Update home page
This commit is contained in:
parent
56c0275db0
commit
904dbdee7c
|
@ -1,17 +1,27 @@
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
interface GridListProps<T> {
|
interface GridListProps<T> {
|
||||||
items: T[];
|
items: T[];
|
||||||
colNum: number;
|
colNum: number;
|
||||||
|
className?: string;
|
||||||
|
addItemLabel?: string;
|
||||||
onAddItem?: () => void;
|
onAddItem?: () => void;
|
||||||
itemComponent: React.ComponentType<{ item: T }>;
|
itemComponent: React.ComponentType<{ item: T }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AddItemButton = ({ onAddItem }: { onAddItem: () => void }) => {
|
const AddItemButton = ({
|
||||||
|
label,
|
||||||
|
onAddItem,
|
||||||
|
}: {
|
||||||
|
label: string;
|
||||||
|
onAddItem: () => void;
|
||||||
|
}) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
onClick={onAddItem}
|
onClick={onAddItem}
|
||||||
className="flex cursor-pointer items-center justify-center rounded-md border-2 border-dashed border-gray-400 hover:border-gray-600"
|
className="flex cursor-pointer items-center justify-center rounded-md border-2 border-dashed border-gray-400 hover:border-gray-600"
|
||||||
>
|
>
|
||||||
<span className="text-gray-500">+ Add Item</span>
|
<span className="text-gray-500">{label}</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -19,17 +29,23 @@ const AddItemButton = ({ onAddItem }: { onAddItem: () => void }) => {
|
||||||
const GridList = <T,>({
|
const GridList = <T,>({
|
||||||
items,
|
items,
|
||||||
colNum,
|
colNum,
|
||||||
|
className,
|
||||||
|
addItemLabel = '+ Add Item',
|
||||||
onAddItem,
|
onAddItem,
|
||||||
itemComponent: ItemComponent,
|
itemComponent: ItemComponent,
|
||||||
}: GridListProps<T>) => {
|
}: GridListProps<T>) => {
|
||||||
|
const containerClassName = classNames('grid gap-4', className);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`grid gap-4`}
|
className={containerClassName}
|
||||||
style={{
|
style={{
|
||||||
gridTemplateColumns: `repeat(${colNum}, minmax(0, 1fr))`,
|
gridTemplateColumns: `repeat(${colNum}, minmax(0, 1fr))`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{onAddItem && <AddItemButton onAddItem={onAddItem} />}
|
{onAddItem && (
|
||||||
|
<AddItemButton label={addItemLabel} onAddItem={onAddItem} />
|
||||||
|
)}
|
||||||
|
|
||||||
{items.map((item, index) => (
|
{items.map((item, index) => (
|
||||||
<ItemComponent key={index} item={item} />
|
<ItemComponent key={index} item={item} />
|
||||||
|
|
|
@ -45,6 +45,7 @@ const Header = () => {
|
||||||
<Link
|
<Link
|
||||||
className="block px-4 py-2 text-sm text-gray-900 hover:bg-gray-100 dark:text-gray-100 dark:hover:bg-nero-700"
|
className="block px-4 py-2 text-sm text-gray-900 hover:bg-gray-100 dark:text-gray-100 dark:hover:bg-nero-700"
|
||||||
to="/profile"
|
to="/profile"
|
||||||
|
onClick={() => setIsDropdownOpen(false)}
|
||||||
>
|
>
|
||||||
Profile
|
Profile
|
||||||
</Link>
|
</Link>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { getRouteApi, Link } from '@tanstack/react-router';
|
import { getRouteApi } from '@tanstack/react-router';
|
||||||
import { useUser } from '../lib/context/user';
|
|
||||||
import { useEstimationsList } from '../lib/context/estimationsList';
|
import { useEstimationsList } from '../lib/context/estimationsList';
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
|
@ -12,48 +11,38 @@ import { useState } from 'react';
|
||||||
const route = getRouteApi('/_authenticated/');
|
const route = getRouteApi('/_authenticated/');
|
||||||
|
|
||||||
function Home() {
|
function Home() {
|
||||||
const user = useUser();
|
|
||||||
const navigate = route.useNavigate();
|
const navigate = route.useNavigate();
|
||||||
const estimationsList = useEstimationsList();
|
const estimationsList = useEstimationsList();
|
||||||
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="p-6">
|
||||||
<h1 className="text-3xl font-bold underline">Scrummie-Poker</h1>
|
<h1 className="text-3xl font-bold">Estimation sessions</h1>
|
||||||
|
|
||||||
<ul>
|
<GridList
|
||||||
<li>
|
colNum={2}
|
||||||
<Link to="/login">Login</Link>
|
className="my-3"
|
||||||
</li>
|
items={estimationsList?.current ?? []}
|
||||||
</ul>
|
itemComponent={({ item }) => (
|
||||||
<pre>User Id: {user.current?.$id}</pre>
|
<Card
|
||||||
|
key={item.id}
|
||||||
<div>
|
title={item.name}
|
||||||
<p>Estimation sessions</p>
|
onClick={() => {
|
||||||
<GridList
|
navigate({
|
||||||
colNum={2}
|
to: '/estimate/session/$sessionId',
|
||||||
items={estimationsList?.current ?? []}
|
params: { sessionId: item.id },
|
||||||
itemComponent={({ item }) => (
|
});
|
||||||
<Card
|
}}
|
||||||
key={item.id}
|
/>
|
||||||
title={item.name}
|
)}
|
||||||
description={item.id}
|
addItemLabel="+ Create Estimation Session"
|
||||||
onClick={() => {
|
onAddItem={() => setIsDrawerOpen(true)}
|
||||||
navigate({
|
/>
|
||||||
to: '/estimate/session/$sessionId',
|
|
||||||
params: { sessionId: item.id },
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
onAddItem={() => setIsDrawerOpen(true)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Drawer isOpen={isDrawerOpen} onClose={() => setIsDrawerOpen(false)}>
|
<Drawer isOpen={isDrawerOpen} onClose={() => setIsDrawerOpen(false)}>
|
||||||
<CreateEstimationSessionForm onCreated={() => setIsDrawerOpen(false)} />
|
<CreateEstimationSessionForm onCreated={() => setIsDrawerOpen(false)} />
|
||||||
</Drawer>
|
</Drawer>
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue