nsarrazin HF staff commited on
Commit
002f606
1 Parent(s): fae93d9

Shared convos can be opened without being logged in (#266, #270) (#271)

Browse files

* Shared convos can be opened without being logged in

* Fix creating conversation from shared conv

Closes #270

src/lib/components/chat/ChatInput.svelte CHANGED
@@ -50,6 +50,7 @@
50
  bind:this={textareaElement}
51
  {disabled}
52
  on:keydown={handleKeydown}
 
53
  {placeholder}
54
  />
55
  </div>
 
50
  bind:this={textareaElement}
51
  {disabled}
52
  on:keydown={handleKeydown}
53
+ on:keypress
54
  {placeholder}
55
  />
56
  </div>
src/lib/components/chat/ChatWindow.svelte CHANGED
@@ -12,6 +12,7 @@
12
  import StopGeneratingBtn from "../StopGeneratingBtn.svelte";
13
  import type { Model } from "$lib/types/Model";
14
  import type { LayoutData } from "../../../routes/$types";
 
15
 
16
  export let messages: Message[] = [];
17
  export let loading = false;
@@ -21,8 +22,10 @@
21
  export let models: Model[];
22
  export let settings: LayoutData["settings"];
23
 
 
24
  $: isReadOnly = !models.some((model) => model.id === currentModel.id);
25
 
 
26
  let message: string;
27
 
28
  const dispatch = createEventDispatcher<{
@@ -40,6 +43,9 @@
40
  </script>
41
 
42
  <div class="relative min-h-0 min-w-0">
 
 
 
43
  <ChatMessages
44
  {loading}
45
  {pending}
@@ -71,6 +77,9 @@
71
  placeholder="Ask anything"
72
  bind:value={message}
73
  on:submit={handleSubmit}
 
 
 
74
  maxRows={4}
75
  disabled={isReadOnly}
76
  />
 
12
  import StopGeneratingBtn from "../StopGeneratingBtn.svelte";
13
  import type { Model } from "$lib/types/Model";
14
  import type { LayoutData } from "../../../routes/$types";
15
+ import LoginModal from "../LoginModal.svelte";
16
 
17
  export let messages: Message[] = [];
18
  export let loading = false;
 
22
  export let models: Model[];
23
  export let settings: LayoutData["settings"];
24
 
25
+ export let loginRequired = false;
26
  $: isReadOnly = !models.some((model) => model.id === currentModel.id);
27
 
28
+ let loginModalOpen = false;
29
  let message: string;
30
 
31
  const dispatch = createEventDispatcher<{
 
43
  </script>
44
 
45
  <div class="relative min-h-0 min-w-0">
46
+ {#if loginModalOpen}
47
+ <LoginModal {settings} on:close={() => (loginModalOpen = false)} />
48
+ {/if}
49
  <ChatMessages
50
  {loading}
51
  {pending}
 
77
  placeholder="Ask anything"
78
  bind:value={message}
79
  on:submit={handleSubmit}
80
+ on:keypress={() => {
81
+ if (loginRequired) loginModalOpen = true;
82
+ }}
83
  maxRows={4}
84
  disabled={isReadOnly}
85
  />
src/routes/+layout.svelte CHANGED
@@ -91,6 +91,11 @@
91
  });
92
 
93
  $: if ($error) onError();
 
 
 
 
 
94
  </script>
95
 
96
  <svelte:head>
@@ -136,7 +141,7 @@
136
  {#if isSettingsOpen}
137
  <SettingsModal on:close={() => (isSettingsOpen = false)} settings={data.settings} />
138
  {/if}
139
- {#if !$page.error && (data.requiresLogin ? !data.user : !data.settings.ethicsModalAcceptedAt)}
140
  <LoginModal settings={data.settings} />
141
  {/if}
142
  <slot />
 
91
  });
92
 
93
  $: if ($error) onError();
94
+
95
+ const requiresLogin =
96
+ !$page.error &&
97
+ (data.requiresLogin ? !data.user : !data.settings.ethicsModalAcceptedAt) &&
98
+ !$page.route.id?.startsWith("/r/");
99
  </script>
100
 
101
  <svelte:head>
 
141
  {#if isSettingsOpen}
142
  <SettingsModal on:close={() => (isSettingsOpen = false)} settings={data.settings} />
143
  {/if}
144
+ {#if requiresLogin}
145
  <LoginModal settings={data.settings} />
146
  {/if}
147
  <slot />
src/routes/r/[id]/+page.svelte CHANGED
@@ -24,6 +24,7 @@
24
  },
25
  body: JSON.stringify({
26
  fromShare: $page.params.id,
 
27
  }),
28
  });
29
 
@@ -77,4 +78,6 @@
77
  models={data.models}
78
  currentModel={findCurrentModel(data.models, data.model)}
79
  settings={data.settings}
 
 
80
  />
 
24
  },
25
  body: JSON.stringify({
26
  fromShare: $page.params.id,
27
+ model: data.model,
28
  }),
29
  });
30
 
 
78
  models={data.models}
79
  currentModel={findCurrentModel(data.models, data.model)}
80
  settings={data.settings}
81
+ loginRequired={!$page.error &&
82
+ (data.requiresLogin ? !data.user : !data.settings.ethicsModalAcceptedAt)}
83
  />