Skip to content

Commit 0aa8192

Browse files
authored
Project fixups (#1565)
* Tweak loading text layout * Prevent icons and actions from getting squashed/pushed out of view * Improve disabled ListItem handling * Add project context to exception messages
1 parent 88748b9 commit 0aa8192

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

backend/FwLite/LcmCrdt/CurrentProjectService.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class CurrentProjectService(IServiceProvider services, IMemoryCache memor
1313
public CrdtProject? MaybeProject => _project;
1414

1515
//only works because PopulateProjectDataCache is called first in the request pipeline
16-
public ProjectData ProjectData => memoryCache.Get<ProjectData>(CacheKey(Project)) ?? throw new InvalidOperationException("Project data not found, call PopulateProjectDataCache first or use GetProjectData");
16+
public ProjectData ProjectData => memoryCache.Get<ProjectData>(CacheKey(Project)) ?? throw new InvalidOperationException(
17+
$"Project data not found for project {MaybeProject?.Name}, call PopulateProjectDataCache first or use GetProjectData");
1718

1819
public async ValueTask<ProjectData> GetProjectData(bool forceRefresh = false)
1920
{
@@ -23,14 +24,15 @@ public async ValueTask<ProjectData> GetProjectData(bool forceRefresh = false)
2324
result = await DbContext.ProjectData.AsNoTracking().FirstAsync();
2425
memoryCache.Set(CacheKey(Project), result);
2526
}
26-
if (result is null) throw new InvalidOperationException("Project data not found");
27+
if (result is null) throw new InvalidOperationException($"Project data not found for project {MaybeProject?.Name}");
2728

2829
return result;
2930
}
3031

3132
public void ValidateProjectScope()
3233
{
33-
if (Project is null) throw new InvalidOperationException($"Project is null, there's a bug and {nameof(SetupProjectContext)} was not called");
34+
if (Project is null)
35+
throw new InvalidOperationException($"Project is null for project {MaybeProject?.Name}, there's a bug and {nameof(SetupProjectContext)} was not called");
3436
}
3537

3638
private static string CacheKey(CrdtProject project)
@@ -60,7 +62,8 @@ public async ValueTask<ProjectData> SetupProjectContext(CrdtProject project)
6062
{
6163
using var activity = LcmCrdtActivitySource.Value.StartActivity();
6264
activity?.SetTag("app.project_code", project.Name);
63-
if (_project != null && project != _project) throw new InvalidOperationException("Can't setup project context for a different project");
65+
if (_project != null && project != _project)
66+
throw new InvalidOperationException($"Can't setup project context for {project.Name} when already in context of project {_project.Name}");
6467
_project = project;
6568
//the first time this is called ProjectData will be null, after that it will be populated, so we can skip migration
6669
if (LookupProjectData(memoryCache, project) is null) await MigrateDb();

frontend/viewer/src/ProjectLoader.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
{#if loading}
1414
<div class="absolute w-full h-full z-10 bg-surface-100 flex grow items-center justify-center" out:fade={{duration: 800}}>
15-
<div class="inline-flex flex-col items-center text-4xl gap-4 opacity-75">
15+
<div class="inline-flex flex-col items-center text-4xl gap-4 opacity-75 m-auto p-4 text-center">
1616
<span>Loading <span class="text-primary-500">{projectName}</span>...</span><ProgressCircle class="text-surface-content" />
1717
</div>
1818
</div>

frontend/viewer/src/home/HomeView.svelte

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script lang="ts">
1+
<script lang="ts">
22
import {
33
mdiBookArrowLeftOutline,
44
mdiBookEditOutline,
@@ -158,7 +158,7 @@
158158
{loading}
159159
>
160160
<ProjectTitle slot="title" {project}/>
161-
<div slot="actions">
161+
<div slot="actions" class="shrink-0">
162162
{#if $isDev}
163163
<Button
164164
icon={mdiDelete}
@@ -178,7 +178,7 @@
178178
<DevContent>
179179
<ButtonListItem href={`/testing/project-view`}>
180180
<ListItem title={$t`Test Project`} icon={mdiTestTube}>
181-
<div slot="actions" class="pointer-events-none">
181+
<div slot="actions" class="pointer-events-none shrink-0">
182182
<Button icon={mdiChevronRight} class="p-2" />
183183
</div>
184184
</ListItem>
@@ -213,8 +213,8 @@
213213
{#each projects.filter((p) => p.fwdata) as project (project.id ?? project.name)}
214214
<ButtonListItem href={`/fwdata/${project.name}`}>
215215
<ListItem title={project.name}>
216-
<img slot="avatar" src={flexLogo} alt={$t`FieldWorks logo`} class="h-6" />
217-
<div slot="actions">
216+
<img slot="avatar" src={flexLogo} alt={$t`FieldWorks logo`} class="h-6 shrink-0" />
217+
<div slot="actions" class="shrink-0">
218218
<DevContent invisible>
219219
<Button
220220
loading={importing === project.name}

frontend/viewer/src/home/Server.svelte

+6-5
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@
8888
{#each projects as project}
8989
{@const localProject = matchesProject(localProjects, project)}
9090
{#if localProject?.crdt}
91-
<ButtonListItem href={`/project/${project.code}`}>
92-
<ListItem icon={mdiCloud}>
93-
<ProjectTitle slot="title" {project}/>
94-
<div slot="actions" class="pointer-events-none">
91+
<ButtonListItem href={`/project/${project.name}`}>
92+
<ListItem icon={mdiCloud}
93+
title={project.name}
94+
loading={downloading === project.name}>
95+
<div slot="actions" class="pointer-events-none shrink-0">
9596
<Button disabled icon={mdiBookSyncOutline} class="p-2">
9697
{$t`Synced`}
9798
</Button>
@@ -104,7 +105,7 @@
104105
<ListItem icon={mdiCloud}
105106
{loading}>
106107
<ProjectTitle slot="title" {project}/>
107-
<div slot="actions" class="pointer-events-none">
108+
<div slot="actions" class="pointer-events-none shrink-0">
108109
<Button icon={mdiBookArrowDownOutline} class="p-2">
109110
{$t`Download`}
110111
</Button>

frontend/viewer/src/lib/utils/ButtonListItem.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{href}
99
{...$$restProps}
1010
class="button-list-item w-full text-start"
11+
class:pointer-events-none={$$restProps.disabled}
1112
role="button"
1213
tabindex="0">
1314
<div></div> <!-- avoid internal first: styles -->

0 commit comments

Comments
 (0)