Skip to content

Commit e9c8aaf

Browse files
authored
Add delete config button
* feat(user): Mark config for deletion * feat: simplified and direct deletion of config * chore: move `deleteNeovimConfig` to service.ts * chore: remove redaundant migration
1 parent 9ae803b commit e9c8aaf

6 files changed

Lines changed: 54 additions & 8 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[id,userId]` on the table `NeovimConfig` will be added. If there are existing duplicate values, this will fail.
5+
6+
*/-- CreateIndex
7+
CREATEUNIQUEINDEX "NeovimConfig_id_userId_key"
8+
ON "NeovimConfig"("id", "userId");

prisma/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ model NeovimConfig {
5555
5656
@@unique([owner, repo, root])
5757
@@unique([owner, slug])
58+
@@unique([id, userId])
5859
}
5960

6061
enum NeovimPluginManager {
@@ -97,6 +98,7 @@ model NeovimPluginInstallInstructions {
9798
pluginId Int
9899
pluginManager String
99100
instructions String
101+
100102
@@unique([pluginId, pluginManager])
101103
}
102104

src/lib/server/nvim-sync/config/syncRepoInfo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export async function syncExistingRepoInfo(token: string, config: NeovimConfig)
6262
return upsertNeovimConfig(config.userId, upsertDTO);
6363
}
6464

65+
6566
export function validateConfigPath(root: GithubTree, path: string): undefined {
6667
for (const node of root.tree) {
6768
if (node.path === path) {

src/lib/server/prisma/neovimconfigs/service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export async function getConfigsForPlugin(
111111
return configs.map(attachMetaData);
112112
}
113113

114+
114115
export async function getConfigBySlug(
115116
owner: string,
116117
slug: string
@@ -158,6 +159,17 @@ export async function getConfigBySlug(
158159
return attachMetaData(config);
159160
}
160161

162+
export async function deleteNeovimConfig(id: number, userId: number) {
163+
return await prismaClient.neovimConfig.delete({
164+
where: {
165+
id_userId: {
166+
id,
167+
userId
168+
}
169+
}
170+
});
171+
}
172+
161173
export async function getConfigsByUsername(username: string): Promise<NeovimConfigWithMetaData[]> {
162174
const where = { user: { username } };
163175
return getConfigs(where);

src/lib/trpc/router.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import {
99
import { getGithubToken, getUserByUsername } from '$lib/server/prisma/users/service';
1010
import { fetchGithubRepositoryByName, fetchRepoFileTree } from '$lib/server/github/api';
1111
import {
12+
deleteNeovimConfig,
1213
getConfigBySlug,
1314
getConfigsByUsername,
1415
getConfigsForPlugin,
1516
getNeovimConfigsWithDotfyleShield,
1617
getNewestNeovimConfigs,
17-
searchNeovimConfigs
18+
searchNeovimConfigs,
1819
} from '$lib/server/prisma/neovimconfigs/service';
1920
import {
2021
getAllNeovimPluginNames,
@@ -79,6 +80,17 @@ export const router = t.router({
7980
const syncer = await getPluginSyncer(user, owner, name);
8081
return syncer.sync();
8182
}),
83+
deleteConfig: t.procedure
84+
.use(middlewares.isAuthenticated)
85+
.input((input: unknown) => {
86+
return z.object({
87+
id: z.number()
88+
}).parse(input);
89+
})
90+
.mutation(async ({ input: { id }, ctx }) => {
91+
const user = ctx.getAuthenticatedUser();
92+
return await deleteNeovimConfig(id, user.id)
93+
}),
8294
getPluginsByCategory: t.procedure
8395
.input((input: unknown) => {
8496
return z.string().parse(input);

src/routes/[username]/[slug]/+page.svelte

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import OpenGraph from '$lib/components/OpenGraph.svelte';
88
import { getInstallCommand, getRunCommand } from '$lib/installInstructions';
99
import { faGithub } from '@fortawesome/free-brands-svg-icons';
10-
import { faChevronCircleRight, faStar, faSync } from '@fortawesome/free-solid-svg-icons';
10+
import { faChevronCircleRight, faStar, faSync, faTrash } from '@fortawesome/free-solid-svg-icons';
1111
import Fa from 'svelte-fa';
1212
import { Highlight } from 'svelte-highlight';
1313
import { bash } from 'svelte-highlight/languages';
@@ -19,11 +19,18 @@
1919
import NeovimPluginMetaData from '$lib/components/NeovimPluginMetaData.svelte';
2020
import { humanizeRelative } from '$lib/utils';
2121
import { session } from '$lib/stores/session';
22+
import { trpc } from '$lib/trpc/client';
23+
import { page } from '$app/stores';
24+
import { goto } from '$app/navigation';
2225
2326
export let data: PageData;
2427
$: ({ config, plugins, languageServers } = data);
25-
$: pluginManager = plugins?.find(p => p.category === 'plugin-manager')?.name ?? "unknown"
28+
$: pluginManager = plugins?.find((p) => p.category === 'plugin-manager')?.name ?? 'unknown';
2629
30+
async function deleteConfig() {
31+
await trpc($page).deleteConfig.mutate({ id: config.id });
32+
goto(`/${config.owner}`);
33+
}
2734
</script>
2835

2936
<svelte:head>
@@ -69,14 +76,18 @@
6976
{humanizeRelative(new Date().getTime() - new Date(config.lastSyncedAt).getTime())}</span
7077
>
7178
</div>
72-
73-
<a href="https://github.com/{config.owner}/{config.repo}" target="_blank">
74-
<Button text="GitHub" icon={faGithub} />
75-
</a>
79+
<div class="flex gap-1 items-center justify-between font-semibold">
80+
{#if $session.user?.id === config.userId}
81+
<Button text="Delete" icon={faTrash} on:click={deleteConfig} />
82+
{/if}
83+
<a href="https://github.com/{config.owner}/{config.repo}" target="_blank">
84+
<Button text="GitHub" icon={faGithub} />
85+
</a>
86+
</div>
7687
</div>
7788
<NeovimConfigMetaData
7889
syncing={false}
79-
pluginManager={pluginManager}
90+
{pluginManager}
8091
pluginCount={config.pluginCount?.toString()}
8192
root={config.root}
8293
initFile={config.initFile}

0 commit comments

Comments
 (0)