|
| 1 | +import { useState } from 'react'; |
| 2 | +import { AddNewButton, openNoteModal } from '@notes/components'; |
| 3 | +import { ComboboxItem, Grid, Select, Title } from '@mantine/core'; |
| 4 | +import { MainLayout } from '@notes/layout'; |
| 5 | +import { ViewType, viewTypes } from '@notes/types'; |
| 6 | +import { formOption } from '@notes/utils'; |
| 7 | + |
| 8 | +type Props = { |
| 9 | + isData: boolean; |
| 10 | + title: string; |
| 11 | + Table: React.FC<{ isLoading: boolean }>; |
| 12 | + Stickers?: React.FC; |
| 13 | + Tiles?: React.FC; |
| 14 | +}; |
| 15 | + |
| 16 | +export function DataDisplay({ isData, title, Table, Stickers, Tiles }: Props) { |
| 17 | + const [viewType, setViewType] = useState<ComboboxItem>(formOption<ViewType>(viewTypes.TABLE)); |
| 18 | + |
| 19 | + const options = [ |
| 20 | + formOption<ViewType>(viewTypes.TABLE), |
| 21 | + formOption<ViewType>(viewTypes.GRID), |
| 22 | + formOption<ViewType>(viewTypes.STICKERS) |
| 23 | + ]; |
| 24 | + |
| 25 | + return ( |
| 26 | + <MainLayout> |
| 27 | + <Grid align="center" justify="space-between" p="xl"> |
| 28 | + <Grid.Col span={3} order={{ base: 1, sm: 2, lg: 1 }}> |
| 29 | + <AddNewButton openModal={openNoteModal} /> |
| 30 | + </Grid.Col> |
| 31 | + <Grid.Col span={3} order={{ base: 1, sm: 2, lg: 1 }}> |
| 32 | + <Title order={2}>{title}</Title> |
| 33 | + </Grid.Col> |
| 34 | + <Grid.Col span={3} order={{ base: 1, sm: 2, lg: 1 }}> |
| 35 | + <Select |
| 36 | + c={'var(--primary)'} |
| 37 | + label="Change display view:" |
| 38 | + data={options} |
| 39 | + value={viewType.value} |
| 40 | + allowDeselect={false} |
| 41 | + onChange={(_value, option) => setViewType(option)} |
| 42 | + /> |
| 43 | + </Grid.Col> |
| 44 | + </Grid> |
| 45 | + {viewType.value === viewTypes.TABLE && <Table isLoading={!isData} />} |
| 46 | + {viewType.value === viewTypes.STICKERS && <Stickers isLoading={!isData} />} |
| 47 | + {viewType.value === viewTypes.GRID && <Tiles isLoading={!isData} />} |
| 48 | + |
| 49 | + {!isData && <Title order={3}>Your list is empty! </Title>} |
| 50 | + </MainLayout> |
| 51 | + ); |
| 52 | +} |
0 commit comments