diff --git a/src/components/dashboard/modpacks/modal/modpack-modal.tsx b/src/components/dashboard/modpacks/modal/modpack-modal.tsx index 41e7872..925d854 100644 --- a/src/components/dashboard/modpacks/modal/modpack-modal.tsx +++ b/src/components/dashboard/modpacks/modal/modpack-modal.tsx @@ -8,7 +8,7 @@ import { gradient, gradientDanger, notify } from '~/lib/utils'; import { createModpack, deleteModpack, updateModpack, updateModpackPicture } from '~/server/data/modpacks'; import { ModpackModalGeneral } from './modpack-general'; -import { ModpackVersions } from '../../modpack-versions/modpack-version'; +import { ModpackVersions } from './modpack-versions/modpack-version'; export function ModpackModal({ modpack, onClose }: { modpack?: Modpack | undefined, onClose: (editedModpack: Modpack | string) => void }) { const [isPending, startTransition] = useTransition(); diff --git a/src/components/dashboard/modpack-versions/modpack-version-modal.tsx b/src/components/dashboard/modpacks/modal/modpack-versions/modpack-version-modal.tsx similarity index 100% rename from src/components/dashboard/modpack-versions/modpack-version-modal.tsx rename to src/components/dashboard/modpacks/modal/modpack-versions/modpack-version-modal.tsx diff --git a/src/components/dashboard/modpack-versions/modpack-version.tsx b/src/components/dashboard/modpacks/modal/modpack-versions/modpack-version.tsx similarity index 91% rename from src/components/dashboard/modpack-versions/modpack-version.tsx rename to src/components/dashboard/modpacks/modal/modpack-versions/modpack-version.tsx index fab2691..30feeef 100644 --- a/src/components/dashboard/modpack-versions/modpack-version.tsx +++ b/src/components/dashboard/modpacks/modal/modpack-versions/modpack-version.tsx @@ -7,13 +7,12 @@ import { useDisclosure } from '@mantine/hooks'; import { useState } from 'react'; import { useEffectOnce } from '~/hooks/use-effect-once'; -import { gradient } from '~/lib/utils'; +import { gradient, notify } from '~/lib/utils'; import { getModpackVersions } from '~/server/data/modpacks-version'; import type { ModpackVersionWithMods } from '~/types'; import { ModpackVersionModal } from './modpack-version-modal'; - export function ModpackVersions({ modpack }: { modpack: Modpack }) { const [modalOpened, { open: openModal, close: closeModal }] = useDisclosure(false); const [modalModpackVersion, setModalModpackVersion] = useState(); @@ -24,6 +23,7 @@ export function ModpackVersions({ modpack }: { modpack: Modpack }) { .then(setModpackVersions) .catch((error) => { console.error(error); + notify('Error', error.message, 'red'); }); }) @@ -47,8 +47,8 @@ export function ModpackVersions({ modpack }: { modpack: Modpack }) { - {!modpackVersions && (Loading...)} - {modpackVersions.length === 0 && (This Modpack has no versions yet)} + {!modpackVersions && Loading...} + {modpackVersions.length === 0 && This Modpack has no versions yet} {modpackVersions.length > 0 && <> diff --git a/src/components/dashboard/mods/modal/mod-versions/mod-version.tsx b/src/components/dashboard/mods/modal/mod-versions/mod-version.tsx new file mode 100644 index 0000000..e56242a --- /dev/null +++ b/src/components/dashboard/mods/modal/mod-versions/mod-version.tsx @@ -0,0 +1,54 @@ +import type { Mod } from '@prisma/client'; + +import { Group, Table, Text } from '@mantine/core'; +import { useState } from 'react'; + +import { useEffectOnce } from '~/hooks/use-effect-once'; +import { notify } from '~/lib/utils'; +import { getModVersionsWithModpacks } from '~/server/data/mods-version'; +import { ModVersionWithModpacks } from '~/types'; + +export function ModVersions({ mod }: { mod: Mod }) { + const [modVersions, setModVersions] = useState([]); + + useEffectOnce(() => { + getModVersionsWithModpacks(mod.id) + .then(setModVersions) + .catch((err) => { + console.error(err); + notify('Error', err.message, 'red'); + }) + }) + + return ( + + {!modVersions && Loading...} + {modVersions.length === 0 && This Mod has no versions yet} + + {modVersions.length > 0 && <> +
+ + + Version + MC Version + Modpacks + Created + Updated + + + + {modVersions.map((version) => ( + {}}> + {version.version} + {version.mcVersion} + {version.modpacks.map((m) => m.name)} + {version.createdAt.toLocaleString()} + {version.updatedAt.toLocaleString()} + + ))} + +
+ } +
+ ) +} \ No newline at end of file diff --git a/src/components/dashboard/mods/modal/mods-modal.tsx b/src/components/dashboard/mods/modal/mods-modal.tsx index d06c350..46ca01f 100644 --- a/src/components/dashboard/mods/modal/mods-modal.tsx +++ b/src/components/dashboard/mods/modal/mods-modal.tsx @@ -7,6 +7,7 @@ import { useState, useTransition } from 'react'; import { gradient, gradientDanger, notify } from '~/lib/utils'; import { createMod, deleteMod, updateMod, updateModPicture } from '~/server/data/mods'; +import { ModVersions } from './mod-versions/mod-version'; import { ModModalGeneral } from './mods-general'; export interface ModModalFormValues { @@ -91,7 +92,7 @@ export function ModModal({ mod, onClose }: {mod?: Mod | undefined, onClose: (edi - Todo 2 + : 'Hello World' diff --git a/src/server/data/mods-version.ts b/src/server/data/mods-version.ts index 90b22dd..d5c48a2 100644 --- a/src/server/data/mods-version.ts +++ b/src/server/data/mods-version.ts @@ -1,9 +1,31 @@ +'use server'; + import { ModVersion } from '@prisma/client'; import { db } from '~/lib/db'; +import type { ModVersionWithModpacks } from '~/types'; import { deleteResource } from './resource'; +export async function getModVersionsWithModpacks(modId: string): Promise { + const res: ModVersionWithModpacks[] = []; + const modVersions = await db.modVersion.findMany({ where: { modId } }); + + for (const modVer of modVersions) { + console.log(modVer.id); + const modpacks = await db.modpackVersion.findMany({ where: { mods: { some: { id: modVer.id }}}, include: { modpack: true }}) + .then((modpackVersions) => + modpackVersions.map((modpackVersion) => modpackVersion.modpack) + ); + + console.log(modpacks); + + res.push({ ...modVer, modpacks }); + } + + return res; +} + export async function createModVersion({ mod, version, mcVersion }: { mod: { id: string }, version: string, mcVersion: string }): Promise { return db.modVersion.create({ data: { modId: mod.id, version, mcVersion } }); } diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 8356b9d..2b867fa 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -1,4 +1,4 @@ -import type { ModpackVersion } from '@prisma/client'; +import type { Modpack, ModpackVersion, ModVersion } from '@prisma/client'; export type Prettify = { [K in keyof T]: T[K]; @@ -13,6 +13,8 @@ export type CreateObject = export type ModpackVersionWithMods = ModpackVersion & { mods: ModVersion[] }; +export type ModVersionWithModpacks = ModVersion & { modpacks: Modpack[] }; + export type MCModInfoData = MCModInfo[] | { modListVersion: number; modList: MCModInfo[];