Spaces:
Sleeping
Sleeping
fix: assistants feature flow
Browse files- show only approved assistants on community page
- show pending & approved on user specific page
- remove gt>1 user count filter
- remove red outline around unfeatured assistants for non-admins
src/routes/api/assistants/+server.ts
CHANGED
@@ -13,8 +13,7 @@ export async function GET({ url, locals }) {
|
|
13 |
const pageIndex = parseInt(url.searchParams.get("p") ?? "0");
|
14 |
const username = url.searchParams.get("user");
|
15 |
const query = url.searchParams.get("q")?.trim() ?? null;
|
16 |
-
const
|
17 |
-
|
18 |
let user: Pick<User, "_id"> | null = null;
|
19 |
if (username) {
|
20 |
user = await collections.users.findOne<Pick<User, "_id">>(
|
@@ -26,23 +25,24 @@ export async function GET({ url, locals }) {
|
|
26 |
}
|
27 |
}
|
28 |
|
29 |
-
// if
|
30 |
-
|
31 |
-
env.REQUIRE_FEATURED_ASSISTANTS === "true" && !user ? { review: ReviewStatus.APPROVED } : {};
|
32 |
-
|
33 |
-
// if the user queried is not the current user, only show "public" assistants that have been shared before
|
34 |
-
const shouldHaveBeenShared =
|
35 |
-
env.REQUIRE_FEATURED_ASSISTANTS === "true" && !createdByCurrentUser
|
36 |
-
? { userCount: { $gt: 1 } }
|
37 |
-
: {};
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
// 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
|
40 |
const filter: Filter<Assistant> = {
|
41 |
...(modelId && { modelId }),
|
42 |
...(user && { createdById: user._id }),
|
43 |
...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
|
44 |
...shouldBeFeatured,
|
45 |
-
...shouldHaveBeenShared,
|
46 |
};
|
47 |
const assistants = await collections.assistants
|
48 |
.find(filter)
|
|
|
13 |
const pageIndex = parseInt(url.searchParams.get("p") ?? "0");
|
14 |
const username = url.searchParams.get("user");
|
15 |
const query = url.searchParams.get("q")?.trim() ?? null;
|
16 |
+
const showUnfeatured = url.searchParams.get("showUnfeatured") === "true";
|
|
|
17 |
let user: Pick<User, "_id"> | null = null;
|
18 |
if (username) {
|
19 |
user = await collections.users.findOne<Pick<User, "_id">>(
|
|
|
25 |
}
|
26 |
}
|
27 |
|
28 |
+
// if we require featured assistants, that we are not on a user page and we are not an admin who wants to see unfeatured assistants, we show featured assistants
|
29 |
+
let shouldBeFeatured = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
if (env.REQUIRE_FEATURED_ASSISTANTS === "true" && !(locals.user?.isAdmin && showUnfeatured)) {
|
32 |
+
if (!user) {
|
33 |
+
// only show featured assistants on the community page
|
34 |
+
shouldBeFeatured = { review: ReviewStatus.APPROVED };
|
35 |
+
} else {
|
36 |
+
// on a user page show assistants that have been approved or are pending
|
37 |
+
shouldBeFeatured = { review: { $in: [ReviewStatus.APPROVED, ReviewStatus.PENDING] } };
|
38 |
+
}
|
39 |
+
}
|
40 |
// 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
|
41 |
const filter: Filter<Assistant> = {
|
42 |
...(modelId && { modelId }),
|
43 |
...(user && { createdById: user._id }),
|
44 |
...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
|
45 |
...shouldBeFeatured,
|
|
|
46 |
};
|
47 |
const assistants = await collections.assistants
|
48 |
.find(filter)
|
src/routes/assistants/+page.server.ts
CHANGED
@@ -19,7 +19,6 @@ export const load = async ({ url, locals }) => {
|
|
19 |
const username = url.searchParams.get("user");
|
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;
|
@@ -33,17 +32,18 @@ export const load = async ({ url, locals }) => {
|
|
33 |
}
|
34 |
}
|
35 |
|
36 |
-
// if
|
37 |
-
|
38 |
-
env.REQUIRE_FEATURED_ASSISTANTS === "true" && !user && !(locals.user?.isAdmin && showUnfeatured)
|
39 |
-
? { review: ReviewStatus.APPROVED }
|
40 |
-
: {};
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
47 |
|
48 |
// fetch the top assistants sorted by user count from biggest to smallest. filter by model too if modelId is provided or query if query is provided
|
49 |
const filter: Filter<Assistant> = {
|
@@ -51,7 +51,6 @@ export const load = async ({ url, locals }) => {
|
|
51 |
...(user && { createdById: user._id }),
|
52 |
...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
|
53 |
...shouldBeFeatured,
|
54 |
-
...shouldHaveBeenShared,
|
55 |
};
|
56 |
const assistants = await Database.getInstance()
|
57 |
.getCollections()
|
|
|
19 |
const username = url.searchParams.get("user");
|
20 |
const query = url.searchParams.get("q")?.trim() ?? null;
|
21 |
const sort = url.searchParams.get("sort")?.trim() ?? SortKey.TRENDING;
|
|
|
22 |
const showUnfeatured = url.searchParams.get("showUnfeatured") === "true";
|
23 |
|
24 |
let user: Pick<User, "_id"> | null = null;
|
|
|
32 |
}
|
33 |
}
|
34 |
|
35 |
+
// if we require featured assistants, that we are not on a user page and we are not an admin who wants to see unfeatured assistants, we show featured assistants
|
36 |
+
let shouldBeFeatured = {};
|
|
|
|
|
|
|
37 |
|
38 |
+
if (env.REQUIRE_FEATURED_ASSISTANTS === "true" && !(locals.user?.isAdmin && showUnfeatured)) {
|
39 |
+
if (!user) {
|
40 |
+
// only show featured assistants on the community page
|
41 |
+
shouldBeFeatured = { review: ReviewStatus.APPROVED };
|
42 |
+
} else {
|
43 |
+
// on a user page show assistants that have been approved or are pending
|
44 |
+
shouldBeFeatured = { review: { $in: [ReviewStatus.APPROVED, ReviewStatus.PENDING] } };
|
45 |
+
}
|
46 |
+
}
|
47 |
|
48 |
// fetch the top assistants sorted by user count from biggest to smallest. filter by model too if modelId is provided or query if query is provided
|
49 |
const filter: Filter<Assistant> = {
|
|
|
51 |
...(user && { createdById: user._id }),
|
52 |
...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
|
53 |
...shouldBeFeatured,
|
|
|
54 |
};
|
55 |
const assistants = await Database.getInstance()
|
56 |
.getCollections()
|
src/routes/assistants/+page.svelte
CHANGED
@@ -250,7 +250,9 @@
|
|
250 |
|
251 |
<button
|
252 |
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
|
253 |
-
{!(assistant.review === ReviewStatus.APPROVED) && !createdByMe
|
|
|
|
|
254 |
on:click={() => {
|
255 |
if (data.settings.assistants.includes(assistant._id.toString())) {
|
256 |
settings.instantSet({ activeModel: assistant._id.toString() });
|
|
|
250 |
|
251 |
<button
|
252 |
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
|
253 |
+
{!(assistant.review === ReviewStatus.APPROVED) && !createdByMe && data.user?.isAdmin
|
254 |
+
? 'border !border-red-500/30'
|
255 |
+
: ''}"
|
256 |
on:click={() => {
|
257 |
if (data.settings.assistants.includes(assistant._id.toString())) {
|
258 |
settings.instantSet({ activeModel: assistant._id.toString() });
|