Skip to content

Commit

Permalink
feat: add delete perm to files
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Aug 12, 2023
1 parent 9eacd5c commit 795c2c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
39 changes: 11 additions & 28 deletions src/routes/dashboard/[workspace_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
downloadUploadedFile,
getUploadedFileURL,
makeFileUpload,
removePermanentlyFile,
} from "@/utils/files";

import {
Expand Down Expand Up @@ -289,30 +290,6 @@ const Page: Component = () => {
<Switch>
<Match when={content.type === "file" && content.data}>
{file => (
// <div class="w-full h-auto p-2 flex flex-row justify-between items-center gap-1 border-b border-text hover:bg-surface0">
// <div class="flex flex-row gap-2">
// {getFileIcon(file())}
// <p class="text-sm mt-0.5">{file().name}</p>
// </div>
// <div class="flex flex-row gap-4">
// <button
// type="button"
// onClick={() => downloadUploadedFile(file())}
// >
// Download
// </button>
// <button
// type="button"
// class="bg-lavender text-crust px-2 py-1 rounded"
// onClick={async () => {
// const url = getUploadedFileURL(file());
// await navigator.clipboard.writeText(url.href);
// }}
// >
// Copy public URL
// </button>
// </div>
// </div>
<div class="w-full h-auto p-2 flex flex-row justify-between items-center gap-1 border-b border-surface2 hover:bg-surface0">
<div class="flex flex-row gap-2">
{getFileIcon(file())}
Expand All @@ -334,7 +311,7 @@ const Page: Component = () => {
<DropdownMenu.Trigger>
<button
type="button"
title="Delete file"
title="Actions"
class="p-1 hover:bg-surface1 rounded-md"
>
<IconDotsHorizontal class="text-lg text-text" />
Expand All @@ -353,13 +330,19 @@ const Page: Component = () => {
class="flex flex-row items-center gap-6 pl-2 pr-4 px-4 py-1 hover:bg-lavender/30 text-text hover:text-[rgb(46,48,66)] rounded-md"
>
<IconStarOutline class="text-lg" />
Favourite
Favorite
</DropdownMenu.Item>
<DropdownMenu.Item
class="flex flex-row items-center gap-6 pl-2 pr-4 py-1 hover:bg-lavender/30 text-text hover:text-[rgb(46,48,66)] rounded-md"
class="cursor-pointer flex flex-row items-center gap-6 pl-2 pr-4 py-1 hover:bg-lavender/30 text-text hover:text-[rgb(46,48,66)] rounded-md"
onSelect={async () => {
await removePermanentlyFile(file().id)
setWorkspaceContent(prev => prev ?
prev.filter(item => item.type === "workspace" || (item.type === "file" && item.data.id !== file().id))
: [])
}}
>
<IconDeleteOutline class="text-lg" />
Delete
Delete permanently
</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu.Portal>
Expand Down
11 changes: 10 additions & 1 deletion src/utils/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,13 @@ export const downloadUploadedFile = (file: UploadedFile) => {
}

xhr.send();
}
};

export const removePermanentlyFile = async (upload_id: string) => {
await fetch("/api/file/" + upload_id, {
method: "DELETE",
headers: {
authorization: auth.profile!.api_token
}
});
};

0 comments on commit 795c2c7

Please sign in to comment.