Mishig commited on
Commit
69684cd
1 Parent(s): 0a4f58c

[Assistants] update page & visiblity logic (#802)

Browse files

* Always show community tab

* Change assistants visiblity logic

* ui hint

* comment out

* unused icon for now

* re-use variable

src/routes/assistants/+page.server.ts CHANGED
@@ -7,7 +7,7 @@ import type { Filter } from "mongodb";
7
 
8
  const NUM_PER_PAGE = 24;
9
 
10
- export const load = async ({ url }) => {
11
  if (!ENABLE_ASSISTANTS) {
12
  throw redirect(302, `${base}/`);
13
  }
@@ -15,6 +15,7 @@ export const load = async ({ url }) => {
15
  const modelId = url.searchParams.get("modelId");
16
  const pageIndex = parseInt(url.searchParams.get("p") ?? "0");
17
  const createdByName = url.searchParams.get("user");
 
18
 
19
  if (createdByName) {
20
  const existingUser = await collections.users.findOne({ username: createdByName });
@@ -25,10 +26,9 @@ export const load = async ({ url }) => {
25
 
26
  // fetch the top assistants sorted by user count from biggest to smallest, filter out all assistants with only 1 users. filter by model too if modelId is provided
27
  const filter: Filter<Assistant> = {
28
- userCount: { $gt: 1 },
29
  modelId: modelId ?? { $exists: true },
30
- featured: true,
31
- ...(createdByName && { createdByName }),
32
  };
33
  const assistants = await collections.assistants
34
  .find(filter)
 
7
 
8
  const NUM_PER_PAGE = 24;
9
 
10
+ export const load = async ({ url, locals }) => {
11
  if (!ENABLE_ASSISTANTS) {
12
  throw redirect(302, `${base}/`);
13
  }
 
15
  const modelId = url.searchParams.get("modelId");
16
  const pageIndex = parseInt(url.searchParams.get("p") ?? "0");
17
  const createdByName = url.searchParams.get("user");
18
+ const createdByCurrentUser = locals.user?.username && locals.user.username === createdByName;
19
 
20
  if (createdByName) {
21
  const existingUser = await collections.users.findOne({ username: createdByName });
 
26
 
27
  // fetch the top assistants sorted by user count from biggest to smallest, filter out all assistants with only 1 users. filter by model too if modelId is provided
28
  const filter: Filter<Assistant> = {
 
29
  modelId: modelId ?? { $exists: true },
30
+ ...(!createdByCurrentUser && { userCount: { $gt: 1 } }),
31
+ ...(createdByName ? { createdByName } : { featured: true }),
32
  };
33
  const assistants = await collections.assistants
34
  .find(filter)
src/routes/assistants/+page.svelte CHANGED
@@ -13,6 +13,7 @@
13
  import CarbonClose from "~icons/carbon/close";
14
  import CarbonArrowUpRight from "~icons/carbon/arrow-up-right";
15
  import CarbonEarthAmerica from "~icons/carbon/earth-americas-filled";
 
16
  import Pagination from "$lib/components/Pagination.svelte";
17
  import { getHref } from "$lib/utils/getHref";
18
 
@@ -111,7 +112,7 @@
111
  on HF</a
112
  >
113
  {/if}
114
- {:else if data.user?.username}
115
  <a
116
  href={getHref($page.url, {
117
  existingKeys: { behaviour: "delete", keys: ["user", "modelId", "p"] },
@@ -123,17 +124,19 @@
123
  <CarbonEarthAmerica class="text-xs" />
124
  Community
125
  </a>
126
- <a
127
- href={getHref($page.url, {
128
- newKeys: { user: data.user.username },
129
- existingKeys: { behaviour: "delete", keys: ["modelId", "p"] },
130
- })}
131
- class="flex items-center gap-1.5 rounded-full border px-3 py-1 {assistantsCreator &&
132
- createdByMe
133
- ? 'border-gray-300 bg-gray-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white'
134
- : 'border-transparent text-gray-400 hover:text-gray-800 dark:hover:text-gray-300'}"
135
- >{data.user.username}
136
- </a>
 
 
137
  {/if}
138
  </div>
139
 
@@ -141,8 +144,13 @@
141
  {#each data.assistants as assistant (assistant._id)}
142
  <a
143
  href="{base}/assistant/{assistant._id}"
144
- class="flex flex-col items-center justify-center overflow-hidden text-balance rounded-xl border bg-gray-50/50 px-4 py-6 text-center shadow hover:bg-gray-50 hover:shadow-inner max-sm:px-4 sm:h-64 sm:pb-4 dark:border-gray-800/70 dark:bg-gray-950/20 dark:hover:bg-gray-950/40"
145
  >
 
 
 
 
 
146
  {#if assistant.avatar}
147
  <img
148
  src="{base}/settings/assistants/{assistant._id}/avatar.jpg"
 
13
  import CarbonClose from "~icons/carbon/close";
14
  import CarbonArrowUpRight from "~icons/carbon/arrow-up-right";
15
  import CarbonEarthAmerica from "~icons/carbon/earth-americas-filled";
16
+ // import CarbonViewOff from "~icons/carbon/view-off-filled";
17
  import Pagination from "$lib/components/Pagination.svelte";
18
  import { getHref } from "$lib/utils/getHref";
19
 
 
112
  on HF</a
113
  >
114
  {/if}
115
+ {:else}
116
  <a
117
  href={getHref($page.url, {
118
  existingKeys: { behaviour: "delete", keys: ["user", "modelId", "p"] },
 
124
  <CarbonEarthAmerica class="text-xs" />
125
  Community
126
  </a>
127
+ {#if data.user?.username}
128
+ <a
129
+ href={getHref($page.url, {
130
+ newKeys: { user: data.user.username },
131
+ existingKeys: { behaviour: "delete", keys: ["modelId", "p"] },
132
+ })}
133
+ class="flex items-center gap-1.5 rounded-full border px-3 py-1 {assistantsCreator &&
134
+ createdByMe
135
+ ? 'border-gray-300 bg-gray-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white'
136
+ : 'border-transparent text-gray-400 hover:text-gray-800 dark:hover:text-gray-300'}"
137
+ >{data.user.username}
138
+ </a>
139
+ {/if}
140
  {/if}
141
  </div>
142
 
 
144
  {#each data.assistants as assistant (assistant._id)}
145
  <a
146
  href="{base}/assistant/{assistant._id}"
147
+ class="relative flex flex-col items-center justify-center overflow-hidden text-balance rounded-xl border bg-gray-50/50 px-4 py-6 text-center shadow hover:bg-gray-50 hover:shadow-inner max-sm:px-4 sm:h-64 sm:pb-4 dark:border-gray-800/70 dark:bg-gray-950/20 dark:hover:bg-gray-950/40"
148
  >
149
+ <!-- {#if assistant.userCount && assistant.userCount > 1}
150
+ <div class="absolute right-2 top-2" title="share with others to make it public">
151
+ <CarbonViewOff class="opacity-70" />
152
+ </div>
153
+ {/if} -->
154
  {#if assistant.avatar}
155
  <img
156
  src="{base}/settings/assistants/{assistant._id}/avatar.jpg"