Spaces:
Running
Running
feat(assistant): add option to feature assistants for admins
Browse files
src/routes/settings/(nav)/assistants/[assistantId]/+page.server.ts
CHANGED
@@ -197,4 +197,29 @@ export const actions: Actions = {
|
|
197 |
|
198 |
return { from: "unfeature", ok: true, message: "Assistant unfeatured" };
|
199 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
};
|
|
|
197 |
|
198 |
return { from: "unfeature", ok: true, message: "Assistant unfeatured" };
|
199 |
},
|
200 |
+
|
201 |
+
feature: async ({ params, locals }) => {
|
202 |
+
if (!locals.user?.isAdmin) {
|
203 |
+
return fail(403, { error: true, message: "Permission denied" });
|
204 |
+
}
|
205 |
+
|
206 |
+
const assistant = await collections.assistants.findOne({
|
207 |
+
_id: new ObjectId(params.assistantId),
|
208 |
+
});
|
209 |
+
|
210 |
+
if (!assistant) {
|
211 |
+
return fail(404, { error: true, message: "Assistant not found" });
|
212 |
+
}
|
213 |
+
|
214 |
+
const result = await collections.assistants.updateOne(
|
215 |
+
{ _id: assistant._id },
|
216 |
+
{ $set: { featured: true } }
|
217 |
+
);
|
218 |
+
|
219 |
+
if (result.modifiedCount === 0) {
|
220 |
+
return fail(500, { error: true, message: "Failed to feature assistant" });
|
221 |
+
}
|
222 |
+
|
223 |
+
return { from: "feature", ok: true, message: "Assistant featured" };
|
224 |
+
},
|
225 |
};
|
src/routes/settings/(nav)/assistants/[assistantId]/+page.svelte
CHANGED
@@ -11,6 +11,7 @@
|
|
11 |
import CarbonCopy from "~icons/carbon/copy-file";
|
12 |
import CarbonFlag from "~icons/carbon/flag";
|
13 |
import CarbonLink from "~icons/carbon/link";
|
|
|
14 |
import CopyToClipBoardBtn from "$lib/components/CopyToClipBoardBtn.svelte";
|
15 |
import ReportModal from "./ReportModal.svelte";
|
16 |
import IconInternet from "$lib/components/icons/IconInternet.svelte";
|
@@ -154,6 +155,12 @@
|
|
154 |
<CarbonTrash class="mr-1.5 inline text-xs" />Un-feature</button
|
155 |
>
|
156 |
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
{/if}
|
158 |
{/if}
|
159 |
</div>
|
|
|
11 |
import CarbonCopy from "~icons/carbon/copy-file";
|
12 |
import CarbonFlag from "~icons/carbon/flag";
|
13 |
import CarbonLink from "~icons/carbon/link";
|
14 |
+
import CarbonStar from "~icons/carbon/star";
|
15 |
import CopyToClipBoardBtn from "$lib/components/CopyToClipBoardBtn.svelte";
|
16 |
import ReportModal from "./ReportModal.svelte";
|
17 |
import IconInternet from "$lib/components/icons/IconInternet.svelte";
|
|
|
155 |
<CarbonTrash class="mr-1.5 inline text-xs" />Un-feature</button
|
156 |
>
|
157 |
</form>
|
158 |
+
{:else}
|
159 |
+
<form method="POST" action="?/feature" use:enhance>
|
160 |
+
<button type="submit" class="flex items-center text-green-600 underline">
|
161 |
+
<CarbonStar class="mr-1.5 inline text-xs" />Feature</button
|
162 |
+
>
|
163 |
+
</form>
|
164 |
{/if}
|
165 |
{/if}
|
166 |
</div>
|