From ad568a28223c86d7d0529ddedfd6a5f9183b7d22 Mon Sep 17 00:00:00 2001 From: Tim Haasdyk Date: Thu, 20 Jun 2024 18:15:13 +0200 Subject: [PATCH] Redesign home page --- frontend/viewer/src/HomeView.svelte | 277 +++++++++++++++------------- 1 file changed, 151 insertions(+), 126 deletions(-) diff --git a/frontend/viewer/src/HomeView.svelte b/frontend/viewer/src/HomeView.svelte index dcf49bf7e..34ef4e02e 100644 --- a/frontend/viewer/src/HomeView.svelte +++ b/frontend/viewer/src/HomeView.svelte @@ -6,13 +6,14 @@ mdiBookEditOutline, mdiBookPlusOutline, mdiBookSyncOutline, - mdiTestTube + mdiTestTube, } from '@mdi/js'; - import {navigate} from 'svelte-routing'; - import {Button, Card, type ColumnDef, ListItem, Table, TextField, tableCell, Icon} from 'svelte-ux'; + import { navigate } from 'svelte-routing'; + import { Button, Card, type ColumnDef, ListItem, Table, TextField, tableCell, Icon } from 'svelte-ux'; import flexLogo from './lib/assets/flex-logo.png'; + import DevContent, { isDev } from './lib/layout/DevContent.svelte'; - type Project = { name: string, crdt: boolean, fwdata: boolean, lexbox: boolean }; + type Project = { name: string; crdt: boolean; fwdata: boolean; lexbox: boolean }; let newProjectName = ''; let projectsPromise = fetchProjects(); @@ -22,11 +23,11 @@ createError = ''; if (!newProjectName) { - createError = 'Project name is required.' + createError = 'Project name is required.'; return; } const response = await fetch(`/api/project?name=${newProjectName}`, { - method: 'POST' + method: 'POST', }); if (!response.ok) { @@ -44,7 +45,7 @@ async function importFwDataProject(name: string) { loading = name; await fetch(`/api/import/fwdata/${name}`, { - method: 'POST' + method: 'POST', }); projectsPromise = fetchProjects(); await projectsPromise; @@ -55,7 +56,7 @@ async function downloadCrdtProject(name: string) { downloading = name; - await fetch(`/api/download/crdt/${name}`, {method: 'POST'}); + await fetch(`/api/download/crdt/${name}`, { method: 'POST' }); projectsPromise = fetchProjects(); await projectsPromise; downloading = ''; @@ -64,7 +65,7 @@ let uploading = ''; async function uploadCrdtProject(name: string) { uploading = name; - await fetch(`/api/upload/crdt/${name}`, {method: 'POST'}); + await fetch(`/api/upload/crdt/${name}`, { method: 'POST' }); projectsPromise = fetchProjects(); await projectsPromise; uploading = ''; @@ -72,7 +73,7 @@ async function fetchProjects() { let r = await fetch('/api/projects'); - return await r.json() as Promise; + return (await r.json()) as Promise; } let username = ''; @@ -85,134 +86,158 @@ fetchMe(); - $: columns = [ { - name: 'name' + name: 'name', + header: 'Name', }, { name: 'fwdata', - header: 'FieldWorks' - }, - { - name: 'crdt', - header: 'CRDT' + header: 'FieldWorks', }, - ...(loggedIn ? [{ - name: 'lexbox', - header: 'Lexbox CRDT', - }] : []), + ...($isDev + ? [ + { + name: 'crdt', + header: 'CRDT', + }, + ] + : []), + ...(loggedIn + ? [ + { + name: 'lexbox', + header: 'Lexbox CRDT', + }, + ] + : []), ] satisfies ColumnDef[]; + + +
+ +
+ + + + + + {#if loggedIn} +

{username}

+ + {:else} + + {/if} +
+
+
+
+
+
+
My projects
+ +
+ {#await projectsPromise} +

loading...

+ {:then projects} + $isDev || p.fwdata).sort((p1, p2) => p1.name.localeCompare(p2.name))} classes={{ th: 'p-4' }}> + + {#each data ?? [] as rowData, rowIndex} + + {#each columns as column (column.name)} + + {/each} + + {/each} + + + + + + + + +
+ {#if column.name === 'fwdata'} + {#if rowData.fwdata} + + {/if} + {:else if column.name === 'lexbox'} + {#if rowData.lexbox && !rowData.crdt} + + {:else if !rowData.lexbox && rowData.crdt && loggedIn} + + {:else if rowData.lexbox && rowData.crdt} + + {/if} + {:else if column.name === 'crdt'} + {#if rowData.crdt} + + {:else if rowData.fwdata} + + {/if} + {:else} + {getCellContent(column, rowData, rowIndex)} + {/if} +
+ Test project + + +
+ {/await} +
+
+
+
+
+
+ -
-
- - - - - - {#if loggedIn} -

{username}

- - {:else} - - {/if} -
- -
- -
- {#await projectsPromise} -

loading...

- {:then projects} - - - - {#each data ?? [] as rowData, rowIndex} - - {#each columns as column (column.name)} - {@const value = getCellValue(column, rowData, rowIndex)} - - - {/each} - - {/each} - -
- {#if column.name === "fwdata"} - {#if rowData.fwdata} - - {/if} - {:else if column.name === "lexbox"} - {#if rowData.lexbox && !rowData.crdt} - - {:else if !rowData.lexbox && rowData.crdt && loggedIn} - - {:else if rowData.lexbox && rowData.crdt} - - {/if} - {:else if column.name === "crdt"} - {#if rowData.crdt} - - {:else if rowData.fwdata} - - {/if} - {:else} - {getCellContent(column, rowData, rowIndex)} - {/if} -
- {/await} - - navigate('/testing/project-view')}/> -
-
- -