Spaces:
Running
Running
feat(tools): let admins feature & unfeature tools
Browse files
src/routes/tools/[toolId]/+layout.server.ts
CHANGED
@@ -21,6 +21,7 @@ export const load = async ({ params, locals }) => {
|
|
21 |
createdByName: null,
|
22 |
createdByMe: false,
|
23 |
reported: false,
|
|
|
24 |
},
|
25 |
};
|
26 |
}
|
|
|
21 |
createdByName: null,
|
22 |
createdByMe: false,
|
23 |
reported: false,
|
24 |
+
featured: false,
|
25 |
},
|
26 |
};
|
27 |
}
|
src/routes/tools/[toolId]/+page.server.ts
CHANGED
@@ -147,4 +147,20 @@ export const actions: Actions = {
|
|
147 |
|
148 |
return { from: "unfeature", ok: true, message: "Tool unfeatured" };
|
149 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
};
|
|
|
147 |
|
148 |
return { from: "unfeature", ok: true, message: "Tool unfeatured" };
|
149 |
},
|
150 |
+
feature: async ({ params, locals }) => {
|
151 |
+
if (!locals.user?.isAdmin) {
|
152 |
+
return fail(403, { error: true, message: "Permission denied" });
|
153 |
+
}
|
154 |
+
|
155 |
+
const result = await collections.tools.updateOne(
|
156 |
+
{ _id: new ObjectId(params.toolId) },
|
157 |
+
{ $set: { featured: true } }
|
158 |
+
);
|
159 |
+
|
160 |
+
if (result.modifiedCount === 0) {
|
161 |
+
return fail(500, { error: true, message: "Failed to feature tool" });
|
162 |
+
}
|
163 |
+
|
164 |
+
return { from: "feature", ok: true, message: "Tool featured" };
|
165 |
+
},
|
166 |
};
|
src/routes/tools/[toolId]/+page.svelte
CHANGED
@@ -16,6 +16,7 @@
|
|
16 |
import CarbonCopy from "~icons/carbon/copy-file";
|
17 |
import CarbonFlag from "~icons/carbon/flag";
|
18 |
import CarbonLink from "~icons/carbon/link";
|
|
|
19 |
|
20 |
export let data;
|
21 |
|
@@ -160,6 +161,19 @@
|
|
160 |
<CarbonTrash class="mr-1.5 inline text-xs" />Delete</button
|
161 |
>
|
162 |
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
{/if}
|
164 |
</div>
|
165 |
</div>
|
|
|
16 |
import CarbonCopy from "~icons/carbon/copy-file";
|
17 |
import CarbonFlag from "~icons/carbon/flag";
|
18 |
import CarbonLink from "~icons/carbon/link";
|
19 |
+
import CarbonStar from "~icons/carbon/star";
|
20 |
|
21 |
export let data;
|
22 |
|
|
|
161 |
<CarbonTrash class="mr-1.5 inline text-xs" />Delete</button
|
162 |
>
|
163 |
</form>
|
164 |
+
{#if data.tool?.featured}
|
165 |
+
<form method="POST" action="?/unfeature" use:enhance>
|
166 |
+
<button type="submit" class="flex items-center text-red-600 underline">
|
167 |
+
<CarbonTrash class="mr-1.5 inline text-xs" />Un-feature</button
|
168 |
+
>
|
169 |
+
</form>
|
170 |
+
{:else}
|
171 |
+
<form method="POST" action="?/feature" use:enhance>
|
172 |
+
<button type="submit" class="flex items-center text-green-600 underline">
|
173 |
+
<CarbonStar class="mr-1.5 inline text-xs" />Feature</button
|
174 |
+
>
|
175 |
+
</form>
|
176 |
+
{/if}
|
177 |
{/if}
|
178 |
</div>
|
179 |
</div>
|