Skip to content

Commit

Permalink
Preview
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Dec 14, 2023
1 parent 9cc1015 commit 72af797
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 30 deletions.
63 changes: 44 additions & 19 deletions apps/dashboard/src/components/tables/vault/data-table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import {
DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from "@midday/ui/dropdown-menu";
import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
} from "@midday/ui/hover-card";
import { Icons } from "@midday/ui/icons";
import { TableCell, TableRow } from "@midday/ui/table";
import { useToast } from "@midday/ui/use-toast";
Expand All @@ -58,7 +63,13 @@ export const translatedFolderName = (t: any, folder: string) => {
}
};

export function DataTableRow({ data, deleteFile, createFolder, deleteFolder }) {
export function DataTableRow({
data,
deleteFile,
createFolder,
deleteFolder,
teamId,
}) {
const t = useI18n();
const { toast } = useToast();
const router = useRouter();
Expand Down Expand Up @@ -94,28 +105,42 @@ export function DataTableRow({ data, deleteFile, createFolder, deleteFolder }) {
}
};

console.log(data);

return (
<AlertDialog>
<ContextMenu>
<ContextMenuTrigger asChild>
<TableRow
className="h-[45px] cursor-default"
onClick={handleNavigate}
>
<TableCell>
<div className="flex items-center space-x-2">
<FileIcon
mimetype={data?.metadata?.mimetype}
name={data.name}
isFolder={data.isFolder}
/>
<span>{translatedFolderName(t, data.name)}</span>
{data?.metadata?.size && (
<span className="text-[#878787]">
{formatSize(data.metadata.size)}
</span>
<TableRow className="h-[45px] cursor-default">
<TableCell onClick={handleNavigate}>
<HoverCard openDelay={300}>
<HoverCardTrigger
disabled={data?.metadata?.mimetype !== "application/pdf"}
>
<div className="flex items-center space-x-2">
<FileIcon
mimetype={data?.metadata?.mimetype}
name={data.name}
isFolder={data.isFolder}
/>
<span>{translatedFolderName(t, data.name)}</span>
{data?.metadata?.size && (
<span className="text-[#878787]">
{formatSize(data.metadata.size)}
</span>
)}
</div>
</HoverCardTrigger>
{data?.metadata?.mimetype === "application/pdf" && (
<HoverCardContent className="w-70 h-[350px]">
<iframe
src={`/api/proxy?filePath=vault/${teamId}/${filepath}#toolbar=0`}
title={data.name}
className="w-80 h-full"
/>
</HoverCardContent>
)}
</div>
</HoverCard>
</TableCell>
<TableCell>
{data?.created_at ? format(new Date(data.created_at), "Pp") : "-"}
Expand Down Expand Up @@ -252,7 +277,7 @@ export function DataTableRow({ data, deleteFile, createFolder, deleteFolder }) {
)}
<ContextMenuItem
onClick={() =>
createFolder.execute({
createFolder({
path: folderPath,
name: "Untitled folder",
})
Expand Down
3 changes: 2 additions & 1 deletion apps/dashboard/src/components/tables/vault/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useAction } from "next-safe-action/hook";
import { useOptimistic } from "react";
import { DataTableRow } from "./data-table-row";

export function DataTable({ data }) {
export function DataTable({ data, teamId }) {
const { toast } = useToast();

const [optimisticData, setOptimisticData] = useOptimistic(
Expand Down Expand Up @@ -90,6 +90,7 @@ export function DataTable({ data }) {
<DataTableRow
key={row.name}
data={row}
teamId={teamId}
deleteFile={(params) => deleteFile.execute(params)}
deleteFolder={(params) => deleteFolder.execute(params)}
createFolder={(params) => createFolder.execute(params)}
Expand Down
6 changes: 4 additions & 2 deletions apps/dashboard/src/components/tables/vault/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getVault } from "@midday/supabase/cached-queries";
import { getUser, getVault } from "@midday/supabase/cached-queries";
import { DataTable } from "./data-table";
import { EmptyTable } from "./empty-table";
import { UploadZone } from "./upload-zone";
Expand All @@ -8,10 +8,12 @@ export async function Table({ path }) {
path: path && decodeURIComponent(path),
});

const { data: userData } = await getUser();

return (
<div className="mt-6 h-[calc(100vh-180px)] border overflow-scroll relative">
<UploadZone>
<DataTable data={data} />
<DataTable data={data} teamId={userData.team_id} />
{data.length === 0 && <EmptyTable type={path} />}
</UploadZone>
</div>
Expand Down
8 changes: 0 additions & 8 deletions packages/supabase/src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,3 @@ export async function getVaultRecursiveQuery(

return items;
}

export async function getAuthSessions(supabase: Client) {
return supabase
.from("auth.sessions")
.eq("user_id", "330e6a53-7a98-407c-a135-26882a2bcaf3")
.order("ordupdated_ater", { ascending: false })
.limit(5);
}

0 comments on commit 72af797

Please sign in to comment.