Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: path added in params #22

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
236 changes: 0 additions & 236 deletions app/(private)/drive/[path]/page.tsx

This file was deleted.

50 changes: 23 additions & 27 deletions app/(private)/drive/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ import {
IconFolderSymlink,
IconTrash,
} from '@tabler/icons-react';
import { useParams, useRouter } from 'next/navigation';
import { useParams, useRouter, useSearchParams } from 'next/navigation';
import { useEffect, useRef, useState } from 'react';
import Breadcrumbs from '@/components/Breadcrumbs';
import FileTable from '@/components/Drive/FileTable';
import useFetchData from '@/hooks/useFetchData';
import { apiCall, failure, openModal } from '@/lib/client_functions';

const DrivePage = () => {
const searchParams = useSearchParams();
const params = useParams();
const { data, refetch } = useFetchData('/api/drive/files');
const { data, refetch } = useFetchData(
`/api/drive/files${searchParams.get('_id') ? `?parent=${searchParams.get('_id')}` : ''}`
);

const [openMoveDialog, setOpenMoveDialog] = useState(false);
const [__path, __setPath] = useState('');
Expand Down Expand Up @@ -93,7 +96,7 @@ const DrivePage = () => {
};

const openFile = (item: any) =>
item.link ? getFile(item.link) : router.push(`/drive/${item?._id}`);
item.link ? getFile(item.link) : router.push(`/drive?_id=${item?._id}`);

const moveFile = async (item: any) => {
await apiCall('/api/drive/files', item, 'PUT');
Expand All @@ -105,13 +108,8 @@ const DrivePage = () => {
};

const getPath = async () => {
if (__path) {
const res = await apiCall(`/api/drive/files?parent=${__path}`);
_setPath(res?.data);
} else {
const res = await apiCall('/api/drive/files');
_setPath(res?.data);
}
const res = await apiCall(`/api/drive/files${__path ? `?parent=${__path}` : ''}`);
_setPath(res?.data?.files);
};

useEffect(() => {
Expand All @@ -127,7 +125,7 @@ const DrivePage = () => {
return (
<>
<Group mb="md" justify="space-between">
<Breadcrumbs path={[{ name: 'Drive' }]} />
<Breadcrumbs path={data?.path} />
<Group>
<ActionIconGroup>
<ActionIcon variant="outline" color="green" onClick={open}>
Expand Down Expand Up @@ -164,7 +162,7 @@ const DrivePage = () => {
</Group>
</Group>
<FileInput style={{ display: 'none' }} ref={ref} value={value} onChange={setValue} multiple />
<FileTable data={data} checked={checked} setChecked={setChecked} openFile={openFile} />
<FileTable data={data?.files} checked={checked} setChecked={setChecked} openFile={openFile} />
<Modal title="New Folder" opened={opened} onClose={close}>
<TextInput
value={folderName}
Expand All @@ -183,7 +181,7 @@ const DrivePage = () => {
</Group>
</Modal>
<Modal
title="New Folder"
title={_path?.[0]?.parent?.name ? `/${_path?.[0]?.parent?.name}` : '/drive'}
opened={!!openMoveDialog}
onClose={() => {
setOpenMoveDialog(false);
Expand All @@ -192,29 +190,27 @@ const DrivePage = () => {
}}
>
<Table striped highlightOnHover withTableBorder withColumnBorders>
{_path?.[0]?.parent && (
<Table.Tr>
<Table.Td
style={{ cursor: 'pointer' }}
onClick={() => __setPath(_path?.[0]?.parent?.parent || '')}
>
...
</Table.Td>
</Table.Tr>
)}
<Table.Tr>
<Table.Td
style={{ cursor: 'pointer' }}
onClick={() => __setPath(_path?.[0]?.parent?.parent || '')}
>
...
</Table.Td>
</Table.Tr>
{_path
?.filter(({ _id }) => !checked.includes(_id))
?.map((test) => (
<Table.Tr key={test?._id}>
<Table.Td>
<Group
style={{ cursor: !test.link ? 'pointer' : 'default' }}
onClick={() => !test.link && __setPath(test._id || '')}
style={{ cursor: !test?.link ? 'pointer' : 'default' }}
onClick={() => !test?.link && __setPath(test?._id || '')}
>
<ThemeIcon variant="transparent" size="sm">
{test.link ? <IconFile /> : <IconFolder />}
{test?.link ? <IconFile /> : <IconFolder />}
</ThemeIcon>
<Text>{test.name}</Text>
<Text>{test?.name}</Text>
</Group>
</Table.Td>
</Table.Tr>
Expand Down
Loading
Loading