const [projects, setProjects] = createLocalProjectStore();
function createProject() {
setProjects((projects) => [
...projects,
{
id: Math.random().toString(36).slice(2, 9),
name: "New Project",
dateCreated: Date.now(),
dateModified: Date.now(),
},
]);
}
function NoProjects() {
return (
<Flex direction="column" class="center w-full">
<h2>Looks like there is no projects yet</h2>
<Button onclick={createProject}>Let's create one!</Button>
</Flex>
);
}
export default function ProjectList() {
const dateFormat = d3.utcFormat("%d/%m/%Y %H:%M");
return (
<>
<Show when={projects.length < 1}>
<NoProjects />
</Show>
<Show when={projects.length > 0}>
<Flex class="w-full" direction="column">
<Button onclick={createProject} type="primary" class="m-xxs mr-auto">
Create new project
</Button>
<Flex direction="column" class="p-xxs w-full" gap="xs">
<For each={projects}>
{(project) => (
<Button
href={`/p/${project.id}`}
type="transparent"
class="w-full"
>
<Flex class="w-full" gap="xl">
<p>{project.name}</p>
<p class="ml-auto">
{dateFormat(new Date(project.dateModified))}
</p>
</Flex>
</Button>
)}
</For>
</Flex>
</Flex>
</Show>
</>
);
}