Skip to content

Commit 7fafb23

Browse files
authored
feat(assistants): add toggle for seeing unfeatured assistants as admin (#1457)
1 parent a7a47e3 commit 7fafb23

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/routes/assistants/+page.server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const load = async ({ url, locals }) => {
2020
const query = url.searchParams.get("q")?.trim() ?? null;
2121
const sort = url.searchParams.get("sort")?.trim() ?? SortKey.TRENDING;
2222
const createdByCurrentUser = locals.user?.username && locals.user.username === username;
23+
const showUnfeatured = url.searchParams.get("showUnfeatured") === "true";
2324

2425
let user: Pick<User, "_id"> | null = null;
2526
if (username) {
@@ -34,7 +35,7 @@ export const load = async ({ url, locals }) => {
3435

3536
// if there is no user, we show community assistants, so only show featured assistants
3637
const shouldBeFeatured =
37-
env.REQUIRE_FEATURED_ASSISTANTS === "true" && !user && !locals.user?.isAdmin
38+
env.REQUIRE_FEATURED_ASSISTANTS === "true" && !user && !(locals.user?.isAdmin && showUnfeatured)
3839
? { featured: true }
3940
: {};
4041

@@ -75,5 +76,6 @@ export const load = async ({ url, locals }) => {
7576
numItemsPerPage: NUM_PER_PAGE,
7677
query,
7778
sort,
79+
showUnfeatured,
7880
};
7981
};

src/routes/assistants/+page.svelte

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@
3636
let filterValue = data.query;
3737
let isFilterInPorgress = false;
3838
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+
};
3949
4050
const onModelChange = (e: Event) => {
4151
const newUrl = getHref($page.url, {
@@ -133,7 +143,12 @@
133143
<option value={model.name}>{model.name}</option>
134144
{/each}
135145
</select>
136-
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}
137152
<a
138153
href={`${base}/settings/assistants/new`}
139154
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 @@
229244
!!assistant?.dynamicPrompt}
230245

231246
<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"
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' : ''}"
233249
on:click={() => {
234250
if (data.settings.assistants.includes(assistant._id.toString())) {
235251
settings.instantSet({ activeModel: assistant._id.toString() });

0 commit comments

Comments
 (0)