Update home page

This commit is contained in:
Pijus Kamandulis 2024-10-19 14:03:37 +03:00
parent 56c0275db0
commit 904dbdee7c
3 changed files with 44 additions and 38 deletions

View File

@ -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} />

View File

@ -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>

View File

@ -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,32 +11,22 @@ 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>
<li>
<Link to="/login">Login</Link>
</li>
</ul>
<pre>User Id: {user.current?.$id}</pre>
<div>
<p>Estimation sessions</p>
<GridList <GridList
colNum={2} colNum={2}
className="my-3"
items={estimationsList?.current ?? []} items={estimationsList?.current ?? []}
itemComponent={({ item }) => ( itemComponent={({ item }) => (
<Card <Card
key={item.id} key={item.id}
title={item.name} title={item.name}
description={item.id}
onClick={() => { onClick={() => {
navigate({ navigate({
to: '/estimate/session/$sessionId', to: '/estimate/session/$sessionId',
@ -46,14 +35,14 @@ function Home() {
}} }}
/> />
)} )}
addItemLabel="+ Create Estimation Session"
onAddItem={() => setIsDrawerOpen(true)} 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>
); );
} }