nsarrazin HF Staff commited on
Commit
5ca011a
·
unverified ·
1 Parent(s): e8dc937

feat(assistants): add toggle for seeing unfeatured assistants as admin (#1457)

Browse files
src/routes/assistants/+page.server.ts CHANGED
@@ -20,6 +20,7 @@ export const load = async ({ url, locals }) => {
20
  const query = url.searchParams.get("q")?.trim() ?? null;
21
  const sort = url.searchParams.get("sort")?.trim() ?? SortKey.TRENDING;
22
  const createdByCurrentUser = locals.user?.username && locals.user.username === username;
 
23
 
24
  let user: Pick<User, "_id"> | null = null;
25
  if (username) {
@@ -34,7 +35,7 @@ export const load = async ({ url, locals }) => {
34
 
35
  // if there is no user, we show community assistants, so only show featured assistants
36
  const shouldBeFeatured =
37
- env.REQUIRE_FEATURED_ASSISTANTS === "true" && !user && !locals.user?.isAdmin
38
  ? { featured: true }
39
  : {};
40
 
@@ -75,5 +76,6 @@ export const load = async ({ url, locals }) => {
75
  numItemsPerPage: NUM_PER_PAGE,
76
  query,
77
  sort,
 
78
  };
79
  };
 
20
  const query = url.searchParams.get("q")?.trim() ?? null;
21
  const sort = url.searchParams.get("sort")?.trim() ?? SortKey.TRENDING;
22
  const createdByCurrentUser = locals.user?.username && locals.user.username === username;
23
+ const showUnfeatured = url.searchParams.get("showUnfeatured") === "true";
24
 
25
  let user: Pick<User, "_id"> | null = null;
26
  if (username) {
 
35
 
36
  // if there is no user, we show community assistants, so only show featured assistants
37
  const shouldBeFeatured =
38
+ env.REQUIRE_FEATURED_ASSISTANTS === "true" && !user && !(locals.user?.isAdmin && showUnfeatured)
39
  ? { featured: true }
40
  : {};
41
 
 
76
  numItemsPerPage: NUM_PER_PAGE,
77
  query,
78
  sort,
79
+ showUnfeatured,
80
  };
81
  };
src/routes/assistants/+page.svelte CHANGED
@@ -36,6 +36,16 @@
36
  let filterValue = data.query;
37
  let isFilterInPorgress = false;
38
  let sortValue = data.sort as SortKey;
 
 
 
 
 
 
 
 
 
 
39
 
40
  const onModelChange = (e: Event) => {
41
  const newUrl = getHref($page.url, {
@@ -133,7 +143,12 @@
133
  <option value={model.name}>{model.name}</option>
134
  {/each}
135
  </select>
136
-
 
 
 
 
 
137
  <a
138
  href={`${base}/settings/assistants/new`}
139
  class="flex items-center gap-1 whitespace-nowrap rounded-lg border bg-white py-1 pl-1.5 pr-2.5 shadow-sm hover:bg-gray-50 hover:shadow-none dark:border-gray-600 dark:bg-gray-700 dark:hover:bg-gray-700"
@@ -229,7 +244,8 @@
229
  !!assistant?.dynamicPrompt}
230
 
231
  <button
232
- 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 dark:border-gray-800/70 dark:bg-gray-950/20 dark:hover:bg-gray-950/40 max-sm:px-4 sm:h-64 sm:pb-4 xl:pt-8"
 
233
  on:click={() => {
234
  if (data.settings.assistants.includes(assistant._id.toString())) {
235
  settings.instantSet({ activeModel: assistant._id.toString() });
 
36
  let filterValue = data.query;
37
  let isFilterInPorgress = false;
38
  let sortValue = data.sort as SortKey;
39
+ let showUnfeatured = data.showUnfeatured;
40
+
41
+ const toggleShowUnfeatured = () => {
42
+ showUnfeatured = !showUnfeatured;
43
+ const newUrl = getHref($page.url, {
44
+ newKeys: { showUnfeatured: showUnfeatured ? "true" : undefined },
45
+ existingKeys: { behaviour: "delete", keys: [] },
46
+ });
47
+ goto(newUrl);
48
+ };
49
 
50
  const onModelChange = (e: Event) => {
51
  const newUrl = getHref($page.url, {
 
143
  <option value={model.name}>{model.name}</option>
144
  {/each}
145
  </select>
146
+ {#if data.user?.isAdmin}
147
+ <label class="mr-auto flex items-center gap-1 text-red-500" title="Admin only feature">
148
+ <input type="checkbox" checked={showUnfeatured} on:change={toggleShowUnfeatured} />
149
+ Show unfeatured assistants
150
+ </label>
151
+ {/if}
152
  <a
153
  href={`${base}/settings/assistants/new`}
154
  class="flex items-center gap-1 whitespace-nowrap rounded-lg border bg-white py-1 pl-1.5 pr-2.5 shadow-sm hover:bg-gray-50 hover:shadow-none dark:border-gray-600 dark:bg-gray-700 dark:hover:bg-gray-700"
 
244
  !!assistant?.dynamicPrompt}
245
 
246
  <button
247
+ 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 dark:border-gray-800/70 dark:bg-gray-950/20 dark:hover:bg-gray-950/40 max-sm:px-4 sm:h-64 sm:pb-4 xl:pt-8
248
+ {!assistant.featured && !createdByMe ? 'border !border-red-500/30' : ''}"
249
  on:click={() => {
250
  if (data.settings.assistants.includes(assistant._id.toString())) {
251
  settings.instantSet({ activeModel: assistant._id.toString() });