nsarrazin HF Staff commited on
Commit
2adc19f
·
unverified ·
1 Parent(s): 9105b0f

feat(tools): add toggle to see unfeatured tools for admins (#1474)

Browse files
src/routes/tools/+page.server.ts CHANGED
@@ -23,6 +23,7 @@ export const load = async ({ url, locals }) => {
23
  const sort = url.searchParams.get("sort")?.trim() ?? SortKey.TRENDING;
24
  const createdByCurrentUser = locals.user?.username && locals.user.username === username;
25
  const activeOnly = url.searchParams.get("active") === "true";
 
26
 
27
  let user: Pick<User, "_id"> | null = null;
28
  if (username) {
@@ -44,7 +45,9 @@ export const load = async ({ url, locals }) => {
44
  const queryTokens = !!query && generateQueryTokens(query);
45
 
46
  const filter: Filter<CommunityToolDB> = {
47
- ...(!createdByCurrentUser && !activeOnly && !locals.user?.isAdmin && { featured: true }),
 
 
48
  ...(user && { createdById: user._id }),
49
  ...(queryTokens && { searchTokens: { $all: queryTokens } }),
50
  ...(activeOnly && {
@@ -90,5 +93,6 @@ export const load = async ({ url, locals }) => {
90
  numItemsPerPage: NUM_PER_PAGE,
91
  query,
92
  sort,
 
93
  };
94
  };
 
23
  const sort = url.searchParams.get("sort")?.trim() ?? SortKey.TRENDING;
24
  const createdByCurrentUser = locals.user?.username && locals.user.username === username;
25
  const activeOnly = url.searchParams.get("active") === "true";
26
+ const showUnfeatured = url.searchParams.get("showUnfeatured") === "true";
27
 
28
  let user: Pick<User, "_id"> | null = null;
29
  if (username) {
 
45
  const queryTokens = !!query && generateQueryTokens(query);
46
 
47
  const filter: Filter<CommunityToolDB> = {
48
+ ...(!createdByCurrentUser &&
49
+ !activeOnly &&
50
+ !(locals.user?.isAdmin && showUnfeatured) && { featured: true }),
51
  ...(user && { createdById: user._id }),
52
  ...(queryTokens && { searchTokens: { $all: queryTokens } }),
53
  ...(activeOnly && {
 
93
  numItemsPerPage: NUM_PER_PAGE,
94
  query,
95
  sort,
96
+ showUnfeatured,
97
  };
98
  };
src/routes/tools/+page.svelte CHANGED
@@ -36,6 +36,8 @@
36
  let isFilterInPorgress = false;
37
  let sortValue = data.sort as SortKey;
38
 
 
 
39
  const resetFilter = () => {
40
  filterValue = "";
41
  isFilterInPorgress = false;
@@ -73,6 +75,15 @@
73
  goto(newUrl);
74
  };
75
 
 
 
 
 
 
 
 
 
 
76
  const goToActiveUrl = () => {
77
  return getHref($page.url, {
78
  newKeys: { active: "true" },
@@ -112,6 +123,12 @@
112
  >. Consider sharing your feedback with us!
113
  </h4>
114
  <div class="ml-auto mt-6 flex justify-between gap-2 max-sm:flex-col sm:items-center">
 
 
 
 
 
 
115
  <a
116
  href={`${base}/tools/new`}
117
  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"
@@ -211,7 +228,10 @@
211
  {@const isOfficial = !tool.createdByName}
212
  <a
213
  href="{base}/tools/{tool._id.toString()}"
214
- class="relative flex flex-row items-center gap-4 overflow-hidden text-balance rounded-xl border bg-gray-50/50 px-4 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-24"
 
 
 
215
  class:!border-blue-600={isActive}
216
  >
217
  <ToolLogo color={tool.color} icon={tool.icon} />
 
36
  let isFilterInPorgress = false;
37
  let sortValue = data.sort as SortKey;
38
 
39
+ let showUnfeatured = data.showUnfeatured;
40
+
41
  const resetFilter = () => {
42
  filterValue = "";
43
  isFilterInPorgress = false;
 
75
  goto(newUrl);
76
  };
77
 
78
+ const toggleShowUnfeatured = () => {
79
+ showUnfeatured = !showUnfeatured;
80
+ const newUrl = getHref($page.url, {
81
+ newKeys: { showUnfeatured: showUnfeatured ? "true" : undefined },
82
+ existingKeys: { behaviour: "delete", keys: [] },
83
+ });
84
+ goto(newUrl);
85
+ };
86
+
87
  const goToActiveUrl = () => {
88
  return getHref($page.url, {
89
  newKeys: { active: "true" },
 
123
  >. Consider sharing your feedback with us!
124
  </h4>
125
  <div class="ml-auto mt-6 flex justify-between gap-2 max-sm:flex-col sm:items-center">
126
+ {#if data.user?.isAdmin}
127
+ <label class="mr-auto flex items-center gap-1 text-red-500" title="Admin only feature">
128
+ <input type="checkbox" checked={showUnfeatured} on:change={toggleShowUnfeatured} />
129
+ Show unfeatured tools
130
+ </label>
131
+ {/if}
132
  <a
133
  href={`${base}/tools/new`}
134
  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"
 
228
  {@const isOfficial = !tool.createdByName}
229
  <a
230
  href="{base}/tools/{tool._id.toString()}"
231
+ class="relative flex flex-row items-center gap-4 overflow-hidden text-balance rounded-xl border bg-gray-50/50 px-4 text-center shadow hover:bg-gray-50 hover:shadow-inner dark:bg-gray-950/20 dark:hover:bg-gray-950/40 max-sm:px-4 sm:h-24 {!tool.featured &&
232
+ !isOfficial
233
+ ? ' border-red-500/30'
234
+ : 'dark:border-gray-800/70'}"
235
  class:!border-blue-600={isActive}
236
  >
237
  <ToolLogo color={tool.color} icon={tool.icon} />