-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dashboard): add ability to navigate between folders by double cli…
…cking
- Loading branch information
1 parent
a43ad30
commit 393d165
Showing
4 changed files
with
86 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ import { | |
Icon, | ||
} from '@chakra-ui/react' | ||
import { Pagination } from '@opengovsg/design-system-react' | ||
import { useState } from 'react' | ||
import { usePathname, useParams, useRouter } from 'next/navigation' | ||
import { useEffect, useState } from 'react' | ||
import { | ||
BiHome, | ||
BiFileBlank, | ||
|
@@ -25,59 +26,61 @@ import { | |
BiDotsHorizontalRounded, | ||
} from 'react-icons/bi' | ||
import { MdOutlineHorizontalRule } from 'react-icons/md' | ||
import { trpc } from '~/utils/trpc' | ||
|
||
export const DashboardTable = (): JSX.Element => { | ||
const dummyChildData: { | ||
id: string | ||
name: string | ||
permalink: string | ||
type: 'page' | 'folder' | ||
status: 'folder' | 'draft' | 'published' | ||
lastEditUser: string | ||
lastEditDate: Date | 'folder' | ||
}[] = [ | ||
{ | ||
id: '0001', | ||
name: 'Test Page 1', | ||
permalink: '/', | ||
type: 'page', | ||
status: 'draft', | ||
lastEditUser: '[email protected]', | ||
lastEditDate: new Date(), | ||
}, | ||
{ | ||
id: '0003', | ||
name: 'Test Folder 1', | ||
permalink: '/testfolder1', | ||
type: 'folder', | ||
status: 'folder', | ||
lastEditUser: 'folder', | ||
lastEditDate: 'folder', | ||
}, | ||
// TODO: add loading state, probably not req for mvp | ||
|
||
export default function DashboardTable(): JSX.Element { | ||
const router = useRouter() | ||
const [pageNumber, onPageChange] = useState(1) | ||
const [dataToDisplay, setDataToDisplay] = useState< | ||
{ | ||
id: '0002', | ||
name: 'Test Page 2', | ||
permalink: '/testpage2', | ||
type: 'page', | ||
status: 'published', | ||
lastEditUser: '[email protected]', | ||
lastEditDate: new Date(50000000000), | ||
}, | ||
id: string | ||
name: string | ||
permalink: string | ||
type: 'page' | 'folder' | ||
status: 'draft' | 'published' | undefined | ||
lastEditUser: string | undefined | ||
lastEditDate: Date | undefined | ||
}[] | ||
>([]) | ||
|
||
const entriesPerPage = 6 | ||
|
||
let { siteId, resourceId } = useParams<{ | ||
siteId: string | ||
resourceId: string | ||
}>() | ||
|
||
// console.log(siteId) | ||
// console.log(resourceId) | ||
|
||
const { data, error, isLoading } = trpc.folder.readFolder.useQuery( | ||
{ | ||
id: '0004', | ||
name: 'Test Folder 2', | ||
permalink: '/testfolder2', | ||
type: 'folder', | ||
status: 'folder', | ||
lastEditUser: 'folder', | ||
lastEditDate: 'folder', | ||
siteId, | ||
resourceId, | ||
}, | ||
] | ||
{ enabled: !!resourceId }, | ||
) | ||
|
||
const [pageNumber, onPageChange] = useState(1) | ||
const [dataToDisplay, setDataToDisplay] = useState(dummyChildData) | ||
useEffect(() => { | ||
if (data) { | ||
console.log(data) | ||
setDataToDisplay(data.children) | ||
} | ||
// setLoading(isLoading) | ||
}, [data]) | ||
|
||
const entriesPerPage = 6 | ||
// if (!resourceId) { | ||
// // todo: fetch data after setting up root folder trpc endpoint | ||
// } else { | ||
// const { data } = await trpc.folder.readFolder | ||
// .useQuery({ | ||
// siteId, | ||
// resourceId, | ||
// }) | ||
// .setDataToDisplay(data) | ||
// } | ||
return ( | ||
<> | ||
<TableContainer | ||
|
@@ -119,12 +122,18 @@ export const DashboardTable = (): JSX.Element => { | |
) | ||
.map((element) => { | ||
return ( | ||
<Tr> | ||
// TODO: add doubleclick handler that handles navigating between folder. | ||
<Tr key={element.id}> | ||
<Td w="min-content"> | ||
<Checkbox size="sm" w="fit-content" h="fit-content" /> | ||
</Td> | ||
|
||
<Td> | ||
<Td | ||
onDoubleClick={() => | ||
router.push(`/${siteId}/dashboard/${element.id}`) | ||
} | ||
cursor="default" | ||
> | ||
<HStack spacing="0.75rem"> | ||
{element.type === 'page' && | ||
element.permalink === '/' && ( | ||
|
@@ -149,20 +158,21 @@ export const DashboardTable = (): JSX.Element => { | |
</Td> | ||
|
||
<Td> | ||
{element.type === 'page' && element.status == 'draft' && ( | ||
<Badge | ||
variant="subtle" | ||
colorScheme="warning" | ||
borderRadius="50px" | ||
> | ||
<Icon | ||
as={BiSolidCircle} | ||
color="utility.feedback.warning" | ||
mr="0.25rem" | ||
/> | ||
Draft | ||
</Badge> | ||
)} | ||
{element.type === 'page' && | ||
element.status === 'draft' && ( | ||
<Badge | ||
variant="subtle" | ||
colorScheme="warning" | ||
borderRadius="50px" | ||
> | ||
<Icon | ||
as={BiSolidCircle} | ||
color="utility.feedback.warning" | ||
mr="0.25rem" | ||
/> | ||
Draft | ||
</Badge> | ||
)} | ||
{element.type === 'page' && | ||
element.status == 'published' && ( | ||
<Badge | ||
|
@@ -233,3 +243,4 @@ export const DashboardTable = (): JSX.Element => { | |
</> | ||
) | ||
} | ||
// async function updateTableContent(siteId:string, resourceId:string|undefined, setDataToDisplay) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Dashboard from '~/pages/[siteId]/dashboard/[resourceId]/index' | ||
|
||
// TODO: This has a different layout, will have to implmenet the top/root level layout | ||
export default Dashboard |