fix: don't reverse mod list in administration panel

This commit is contained in:
Dorian Niemiec 2024-09-08 09:16:21 +02:00
parent 6d8d779777
commit ae24ae9ef2

View file

@ -261,141 +261,135 @@ const SvrjsModsAdminPage = () => {
</TableRow> </TableRow>
</TableHeader> </TableHeader>
<TableBody> <TableBody>
{mods {mods.map((mod) => (
.slice() <TableRow key={mod._id}>
.reverse() <TableCell className="border-b px-4 py-2">
.map((mod) => ( {mod.fileName}
<TableRow key={mod._id}> </TableCell>
<TableCell className="border-b px-4 py-2"> <TableCell className="border-b px-4 py-2">
{mod.fileName} {mod.version}
</TableCell> </TableCell>
<TableCell className="border-b px-4 py-2"> <TableCell className="border-b px-4 py-2">
{mod.version} <a
</TableCell> href={mod.downloadLink}
<TableCell className="border-b px-4 py-2"> target="_blank"
<a rel="noopener noreferrer"
href={mod.downloadLink} >
target="_blank" {mod.downloadLink}
rel="noopener noreferrer" </a>
> </TableCell>
{mod.downloadLink} <TableCell className="border-b px-4 py-2">
</a> {mod.fileSize}
</TableCell> </TableCell>
<TableCell className="border-b px-4 py-2"> <TableCell className="border-b px-4 py-2 gap-2 flex-center">
{mod.fileSize} <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
</TableCell> <DialogTrigger>
<TableCell className="border-b px-4 py-2 gap-2 flex-center"> <Button variant="outline" onClick={() => setEditMod(mod)}>
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}> Edit
<DialogTrigger> </Button>
<Button </DialogTrigger>
variant="outline" <DialogContent>
onClick={() => setEditMod(mod)} <DialogTitle>Edit Content</DialogTitle>
>
Edit
</Button>
</DialogTrigger>
<DialogContent>
<DialogTitle>Edit Content</DialogTitle>
<Form {...dialogForm}> <Form {...dialogForm}>
<form <form
onSubmit={dialogForm.handleSubmit(onSubmit)} onSubmit={dialogForm.handleSubmit(onSubmit)}
className="space-y-4" className="space-y-4"
> >
<FormField <FormField
control={dialogForm.control} control={dialogForm.control}
name="fileName" name="fileName"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>File Name</FormLabel> <FormLabel>File Name</FormLabel>
<FormControl> <FormControl>
<Input <Input
{...field} {...field}
defaultValue={editMod?.fileName} defaultValue={editMod?.fileName}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={dialogForm.control}
name="version"
render={({ field }) => (
<FormItem>
<FormLabel>Version</FormLabel>
<FormControl>
<Input
{...field}
defaultValue={editMod?.version}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={dialogForm.control}
name="downloadLink"
render={({ field }) => (
<FormItem>
<FormLabel>Download Link</FormLabel>
<UploadButton
endpoint="imageUploader"
onClientUploadComplete={(res) => {
field.onChange(res[0].url);
}}
onUploadError={(error: Error) => {
alert(`ERROR! ${error.message}`);
}}
/> />
<FormControl> </FormControl>
<Input <FormMessage />
{...field} </FormItem>
defaultValue={editMod?.downloadLink} )}
/> />
</FormControl> <FormField
<FormMessage /> control={dialogForm.control}
</FormItem> name="version"
)} render={({ field }) => (
/> <FormItem>
<FormField <FormLabel>Version</FormLabel>
control={dialogForm.control} <FormControl>
name="fileSize" <Input
render={({ field }) => ( {...field}
<FormItem> defaultValue={editMod?.version}
<FormLabel>File Size</FormLabel> />
<FormControl> </FormControl>
<Input <FormMessage />
{...field} </FormItem>
defaultValue={editMod?.fileSize} )}
/> />
</FormControl> <FormField
<FormMessage /> control={dialogForm.control}
</FormItem> name="downloadLink"
)} render={({ field }) => (
/> <FormItem>
<Button <FormLabel>Download Link</FormLabel>
type="submit" <UploadButton
className="w-full text-lg rounded-full" endpoint="imageUploader"
size={"lg"} onClientUploadComplete={(res) => {
disabled={loading} field.onChange(res[0].url);
> }}
Save Changes onUploadError={(error: Error) => {
</Button> alert(`ERROR! ${error.message}`);
</form> }}
</Form> />
</DialogContent> <FormControl>
</Dialog> <Input
<Button {...field}
variant={"destructive"} defaultValue={editMod?.downloadLink}
onClick={() => deleteMod(mod._id)} />
> </FormControl>
Delete <FormMessage />
</Button> </FormItem>
</TableCell> )}
</TableRow> />
))} <FormField
control={dialogForm.control}
name="fileSize"
render={({ field }) => (
<FormItem>
<FormLabel>File Size</FormLabel>
<FormControl>
<Input
{...field}
defaultValue={editMod?.fileSize}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button
type="submit"
className="w-full text-lg rounded-full"
size={"lg"}
disabled={loading}
>
Save Changes
</Button>
</form>
</Form>
</DialogContent>
</Dialog>
<Button
variant={"destructive"}
onClick={() => deleteMod(mod._id)}
>
Delete
</Button>
</TableCell>
</TableRow>
))}
</TableBody> </TableBody>
</Table> </Table>
</section> </section>