-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#76 Add title and description metadata to pages
- Loading branch information
1 parent
21d2b11
commit 25ffec0
Showing
9 changed files
with
362 additions
and
352 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
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 |
---|---|---|
@@ -1,154 +1,31 @@ | ||
"use client"; | ||
import { | ||
Anchor, | ||
Breadcrumbs, | ||
Group, | ||
Loader, | ||
Pagination, | ||
Select, | ||
Stack, | ||
Table, | ||
Text, | ||
Title, | ||
} from "@mantine/core"; | ||
import { useScrollIntoView } from "@mantine/hooks"; | ||
import Link from "next/link"; | ||
import { pathOr } from "ramda"; | ||
import { FC, useEffect, useState } from "react"; | ||
import { Group, Stack, Title } from "@mantine/core"; | ||
import { Metadata } from "next"; | ||
import { TbApps } from "react-icons/tb"; | ||
import { | ||
Application, | ||
ApplicationOrderByInput, | ||
useApplicationsConnectionQuery, | ||
} from "../../graphql"; | ||
import { | ||
limitBounds, | ||
usePaginationParams, | ||
} from "../../hooks/usePaginationParams"; | ||
import ApplicationRow from "../../components/applicationRow"; | ||
import Applications from "../../components/applications"; | ||
import Breadcrumbs from "../../components/breadcrumbs"; | ||
|
||
export type ApplicationsPageProps = {}; | ||
|
||
const ApplicationsPage: FC<ApplicationsPageProps> = (props) => { | ||
const [{ limit, page }, updateParams] = usePaginationParams(); | ||
const after = page === 1 ? undefined : ((page - 1) * limit).toString(); | ||
const [query] = useApplicationsConnectionQuery({ | ||
variables: { orderBy: ApplicationOrderByInput.IdAsc, limit, after }, | ||
}); | ||
const totalInputs = query.data?.applicationsConnection.totalCount ?? 1; | ||
const totalPages = Math.ceil(totalInputs / limit); | ||
const [activePage, setActivePage] = useState( | ||
page > totalPages ? totalPages : page, | ||
); | ||
|
||
const { scrollIntoView, targetRef } = useScrollIntoView<HTMLDivElement>({ | ||
duration: 700, | ||
offset: 150, | ||
cancelable: true, | ||
}); | ||
|
||
useEffect(() => { | ||
if (!query.fetching && page > totalPages) { | ||
updateParams(totalPages, limit); | ||
} | ||
}, [limit, page, query.fetching, totalPages, updateParams]); | ||
|
||
useEffect(() => { | ||
setActivePage((n) => { | ||
return n !== page ? page : n; | ||
}); | ||
}, [page]); | ||
export const metadata: Metadata = { | ||
title: "Applications", | ||
}; | ||
|
||
export default function ApplicationsPage() { | ||
return ( | ||
<Stack> | ||
<Breadcrumbs> | ||
<Anchor href="/" component={Link}> | ||
Home | ||
</Anchor> | ||
</Breadcrumbs> | ||
<Breadcrumbs | ||
breadcrumbs={[ | ||
{ | ||
href: "/", | ||
label: "Home", | ||
}, | ||
]} | ||
/> | ||
|
||
<Group> | ||
<TbApps size={40} /> | ||
<Title order={2}>Applications</Title> | ||
</Group> | ||
|
||
<Stack> | ||
<Pagination | ||
styles={{ root: { alignSelf: "flex-end" } }} | ||
value={activePage} | ||
total={totalPages} | ||
onChange={(pageN) => { | ||
updateParams(pageN, limit); | ||
}} | ||
/> | ||
<Table> | ||
<Table.Thead> | ||
<Table.Tr> | ||
<Table.Th>Id</Table.Th> | ||
<Table.Th>Owner</Table.Th> | ||
<Table.Th>URL</Table.Th> | ||
</Table.Tr> | ||
</Table.Thead> | ||
<Table.Tbody> | ||
{query.fetching && ( | ||
<Table.Tr> | ||
<Table.Td align="center" colSpan={3}> | ||
<Loader /> | ||
</Table.Td> | ||
</Table.Tr> | ||
)} | ||
{query.data?.applicationsConnection.totalCount === | ||
0 && ( | ||
<Table.Tr> | ||
<Table.Td colSpan={3} align="center"> | ||
No applications | ||
</Table.Td> | ||
</Table.Tr> | ||
)} | ||
{query.data?.applicationsConnection.edges.map( | ||
({ node }) => ( | ||
<ApplicationRow | ||
key={node.id} | ||
application={ | ||
node as Omit<Application, "inputs"> | ||
} | ||
/> | ||
), | ||
)} | ||
</Table.Tbody> | ||
</Table> | ||
|
||
<Group justify="space-between" align="center"> | ||
<Group> | ||
<Text>Show:</Text> | ||
<Select | ||
style={{ width: "5rem" }} | ||
value={limit.toString()} | ||
onChange={(val) => { | ||
const entry = val ?? limit; | ||
const l = pathOr(limit, [entry], limitBounds); | ||
updateParams(page, l); | ||
}} | ||
data={[ | ||
limitBounds[10].toString(), | ||
limitBounds[20].toString(), | ||
limitBounds[30].toString(), | ||
]} | ||
/> | ||
<Text>Applications</Text> | ||
</Group> | ||
<Pagination | ||
styles={{ root: { alignSelf: "flex-end" } }} | ||
value={activePage} | ||
total={totalPages} | ||
onChange={(pageN) => { | ||
updateParams(pageN, limit); | ||
scrollIntoView({ alignment: "center" }); | ||
}} | ||
/> | ||
</Group> | ||
</Stack> | ||
<Applications /> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default ApplicationsPage; | ||
} |
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
Oops, something went wrong.
25ffec0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rollups-explorer-workshop – ./apps/workshop
rollups-explorer-workshop-cartesi.vercel.app
rollups-explorer-workshop.vercel.app
rollups-explorer-workshop-git-main-cartesi.vercel.app
25ffec0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rollups-explorer-sepolia – ./apps/web
sepolia-rollups.vercel.app
rollups-explorer-sepolia-git-main-cartesi.vercel.app
sepolia.cartesiscan.io
rollups-explorer-sepolia.vercel.app
rollups-explorer-sepolia-cartesi.vercel.app