Skip to content

Commit

Permalink
all features: generate rows in a loader
Browse files Browse the repository at this point in the history
  • Loading branch information
nstepien committed Sep 13, 2024
1 parent 7a66c98 commit 01ffb14
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 37 deletions.
18 changes: 9 additions & 9 deletions website/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createFileRoute } from '@tanstack/react-router'
// Import Routes

import { Route as rootRoute } from './routes/__root'
import { Route as AllFeaturesImport } from './routes/AllFeatures'
import { Route as IndexImport } from './routes/index'

// Create Virtual Routes
Expand All @@ -38,7 +39,6 @@ const ColumnSpanningLazyImport = createFileRoute('/ColumnSpanning')()
const ColumnGroupingLazyImport = createFileRoute('/ColumnGrouping')()
const CellNavigationLazyImport = createFileRoute('/CellNavigation')()
const AnimationLazyImport = createFileRoute('/Animation')()
const AllFeaturesLazyImport = createFileRoute('/AllFeatures')()

// Create/Update Routes

Expand Down Expand Up @@ -155,7 +155,7 @@ const AnimationLazyRoute = AnimationLazyImport.update({
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/Animation.lazy').then((d) => d.Route))

const AllFeaturesLazyRoute = AllFeaturesLazyImport.update({
const AllFeaturesRoute = AllFeaturesImport.update({
path: '/AllFeatures',
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/AllFeatures.lazy').then((d) => d.Route))
Expand All @@ -180,7 +180,7 @@ declare module '@tanstack/react-router' {
id: '/AllFeatures'
path: '/AllFeatures'
fullPath: '/AllFeatures'
preLoaderRoute: typeof AllFeaturesLazyImport
preLoaderRoute: typeof AllFeaturesImport
parentRoute: typeof rootRoute
}
'/Animation': {
Expand Down Expand Up @@ -323,7 +323,7 @@ declare module '@tanstack/react-router' {

export interface FileRoutesByFullPath {
'/': typeof IndexRoute
'/AllFeatures': typeof AllFeaturesLazyRoute
'/AllFeatures': typeof AllFeaturesRoute
'/Animation': typeof AnimationLazyRoute
'/CellNavigation': typeof CellNavigationLazyRoute
'/ColumnGrouping': typeof ColumnGroupingLazyRoute
Expand All @@ -347,7 +347,7 @@ export interface FileRoutesByFullPath {

export interface FileRoutesByTo {
'/': typeof IndexRoute
'/AllFeatures': typeof AllFeaturesLazyRoute
'/AllFeatures': typeof AllFeaturesRoute
'/Animation': typeof AnimationLazyRoute
'/CellNavigation': typeof CellNavigationLazyRoute
'/ColumnGrouping': typeof ColumnGroupingLazyRoute
Expand All @@ -372,7 +372,7 @@ export interface FileRoutesByTo {
export interface FileRoutesById {
__root__: typeof rootRoute
'/': typeof IndexRoute
'/AllFeatures': typeof AllFeaturesLazyRoute
'/AllFeatures': typeof AllFeaturesRoute
'/Animation': typeof AnimationLazyRoute
'/CellNavigation': typeof CellNavigationLazyRoute
'/ColumnGrouping': typeof ColumnGroupingLazyRoute
Expand Down Expand Up @@ -469,7 +469,7 @@ export interface FileRouteTypes {

export interface RootRouteChildren {
IndexRoute: typeof IndexRoute
AllFeaturesLazyRoute: typeof AllFeaturesLazyRoute
AllFeaturesRoute: typeof AllFeaturesRoute
AnimationLazyRoute: typeof AnimationLazyRoute
CellNavigationLazyRoute: typeof CellNavigationLazyRoute
ColumnGroupingLazyRoute: typeof ColumnGroupingLazyRoute
Expand All @@ -493,7 +493,7 @@ export interface RootRouteChildren {

const rootRouteChildren: RootRouteChildren = {
IndexRoute: IndexRoute,
AllFeaturesLazyRoute: AllFeaturesLazyRoute,
AllFeaturesRoute: AllFeaturesRoute,
AnimationLazyRoute: AnimationLazyRoute,
CellNavigationLazyRoute: CellNavigationLazyRoute,
ColumnGroupingLazyRoute: ColumnGroupingLazyRoute,
Expand Down Expand Up @@ -554,7 +554,7 @@ export const routeTree = rootRoute
"filePath": "index.tsx"
},
"/AllFeatures": {
"filePath": "AllFeatures.lazy.tsx"
"filePath": "AllFeatures.tsx"
},
"/Animation": {
"filePath": "Animation.lazy.tsx"
Expand Down
31 changes: 3 additions & 28 deletions website/routes/AllFeatures.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useState } from 'react';
import { faker } from '@faker-js/faker';
import { createLazyFileRoute } from '@tanstack/react-router';
import { css } from '@linaria/core';

Expand All @@ -23,7 +22,7 @@ const highlightClassname = css`
}
`;

interface Row {
export interface Row {
id: string;
avatar: string;
email: string;
Expand Down Expand Up @@ -167,34 +166,10 @@ const columns: readonly Column<Row>[] = [
}
];

function createRows(): Row[] {
const rows: Row[] = [];

for (let i = 0; i < 2000; i++) {
rows.push({
id: `id_${i}`,
avatar: faker.image.avatar(),
email: faker.internet.email(),
title: faker.person.prefix(),
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
street: faker.location.street(),
zipCode: faker.location.zipCode(),
date: faker.date.past().toLocaleDateString(),
bs: faker.company.buzzPhrase(),
catchPhrase: faker.company.catchPhrase(),
companyName: faker.company.name(),
words: faker.lorem.words(),
sentence: faker.lorem.sentence()
});
}

return rows;
}

function AllFeatures() {
const direction = useDirection();
const [rows, setRows] = useState(createRows);
const initialRows = Route.useLoaderData();
const [rows, setRows] = useState(initialRows);
const [selectedRows, setSelectedRows] = useState((): ReadonlySet<string> => new Set());

function handleFill({ columnKey, sourceRow, targetRow }: FillEvent<Row>): Row {
Expand Down
38 changes: 38 additions & 0 deletions website/routes/AllFeatures.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { faker } from '@faker-js/faker';
import { createFileRoute } from '@tanstack/react-router';

import type { Row } from './AllFeatures.lazy';

let rows: readonly Row[] | undefined;

function createRows(): Row[] {
const rows: Row[] = [];

for (let i = 0; i < 2000; i++) {
rows.push({
id: `id_${i}`,
avatar: faker.image.avatar(),
email: faker.internet.email(),
title: faker.person.prefix(),
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
street: faker.location.street(),
zipCode: faker.location.zipCode(),
date: faker.date.past().toLocaleDateString(),
bs: faker.company.buzzPhrase(),
catchPhrase: faker.company.catchPhrase(),
companyName: faker.company.name(),
words: faker.lorem.words(),
sentence: faker.lorem.sentence()
});
}

return rows;
}

export const Route = createFileRoute('/AllFeatures')({
loader() {
rows ??= createRows();
return rows;
}
});

0 comments on commit 01ffb14

Please sign in to comment.