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

refactor: use Fresh's partial for /dashboard #633

Merged
merged 4 commits into from
Oct 16, 2023
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
61 changes: 32 additions & 29 deletions routes/dashboard/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Head from "@/components/Head.tsx";
import TabsBar from "@/components/TabsBar.tsx";
import { HEADING_WITH_MARGIN_STYLES } from "@/utils/constants.ts";
import { defineRoute } from "$fresh/server.ts";
import { Partial } from "$fresh/runtime.ts";

function randomNumbers(length: number) {
return Array.from({ length }, () => Math.floor(Math.random() * 1000));
Expand Down Expand Up @@ -45,7 +46,7 @@ export default defineRoute((_req, ctx) => {
return (
<>
<Head title="Dashboard" href={ctx.url.href} />
<main class="flex-1 p-4 flex flex-col">
<main class="flex-1 p-4 flex flex-col f-client-nav">
<h1 class={HEADING_WITH_MARGIN_STYLES}>Dashboard</h1>
<TabsBar
links={[{
Expand All @@ -57,36 +58,38 @@ export default defineRoute((_req, ctx) => {
}]}
currentPath={ctx.url.pathname}
/>
<div class="flex-1 relative">
<Chart
type="line"
options={{
maintainAspectRatio: false,
interaction: {
intersect: false,
mode: "index",
},
scales: {
x: {
grid: { display: false },
<Partial name="stats">
<div class="flex-1 relative">
<Chart
type="line"
options={{
maintainAspectRatio: false,
interaction: {
intersect: false,
mode: "index",
},
y: {
beginAtZero: true,
grid: { display: false },
ticks: { precision: 0 },
scales: {
x: {
grid: { display: false },
},
y: {
beginAtZero: true,
grid: { display: false },
ticks: { precision: 0 },
},
},
},
}}
data={{
labels,
datasets: datasets.map((dataset) => ({
...dataset,
pointRadius: 0,
cubicInterpolationMode: "monotone",
})),
}}
/>
</div>
}}
data={{
labels,
datasets: datasets.map((dataset) => ({
...dataset,
pointRadius: 0,
cubicInterpolationMode: "monotone",
})),
}}
/>
</div>
</Partial>
</main>
</>
);
Expand Down
7 changes: 5 additions & 2 deletions routes/dashboard/users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import TabsBar from "@/components/TabsBar.tsx";
import { HEADING_WITH_MARGIN_STYLES } from "@/utils/constants.ts";
import UsersTable from "@/islands/UsersTable.tsx";
import { defineRoute } from "$fresh/server.ts";
import { Partial } from "$fresh/runtime.ts";

export default defineRoute((_req, ctx) => {
const endpoint = "/api/users";
Expand All @@ -18,7 +19,7 @@ export default defineRoute((_req, ctx) => {
rel="preload"
/>
</Head>
<main class="flex-1 p-4">
<main class="flex-1 p-4 f-client-nav">
<h1 class={HEADING_WITH_MARGIN_STYLES}>Dashboard</h1>
<TabsBar
links={[{
Expand All @@ -30,7 +31,9 @@ export default defineRoute((_req, ctx) => {
}]}
currentPath={ctx.url.pathname}
/>
<UsersTable endpoint={endpoint} />
<Partial name="users">
<UsersTable endpoint={endpoint} />
</Partial>
</main>
</>
);
Expand Down
Loading