Skip to content

Commit

Permalink
Update RevisionsDialog to user Loader wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Dec 13, 2023
1 parent 4f81496 commit 9530c63
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 57 deletions.
127 changes: 70 additions & 57 deletions src/common/dialog/RevisionsDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import type { Revision } from "../RevisionIcon.svelte";
import RelativeTime from "../RelativeTime.svelte";
import { Sync16 } from "svelte-octicons";
import Loader from "../Loader.svelte";
export let enabled: boolean;
export let documentId: string;
Expand All @@ -35,70 +36,82 @@
}
</script>

<header>
<h3>{$_("dialogRevisionsDialog.heading")}</h3>
<PremiumBadge />
</header>
{#await getMePromise then user}
{#if isPremiumOrg(user.organization)}
<form>
<label class="revision-control-input">
<input
type="checkbox"
name="revision_control"
checked={enabled}
on:change={handleRevisionControlChange}
/>
{$_("dialogRevisionsDialog.controlLabel")}
</label>
</form>
{#if enabled}
<div class="overflow-scroll">
<table class="revisions">
{#each sortedRevisions as revision}
<tr class="revision">
<td class="revision-version count">{revision.version}</td>
<td class="revision-details">
<p class="revision-comment">{revision.comment}</p>
<span class="revision-time"
><RelativeTime date={new Date(revision.created_at)} /></span
{#await getMePromise}
<Loader active />
{:then user}
<Loader active={false}>
<header>
<h3>{$_("dialogRevisionsDialog.heading")}</h3>
<PremiumBadge />
</header>

{#if isPremiumOrg(user.organization)}
<form>
<label class="revision-control-input">
<input
type="checkbox"
name="revision_control"
checked={enabled}
on:change={handleRevisionControlChange}
/>
{$_("dialogRevisionsDialog.controlLabel")}
</label>
</form>
{#if enabled}
<div class="overflow-scroll">
<table class="revisions">
{#each sortedRevisions as revision}
<tr class="revision">
<td class="revision-version count">{revision.version}</td>
<td class="revision-details">
<p class="revision-comment">{revision.comment}</p>
<span class="revision-time"
><RelativeTime date={new Date(revision.created_at)} /></span
>
</td>
<td class="revision-download"
><Button href={revision.url} download nomargin
>{$_("dialogRevisionsDialog.download")}</Button
></td
>
</td>
<td class="revision-download"
><Button href={revision.url} download nomargin
>{$_("dialogRevisionsDialog.download")}</Button
></td
</tr>
{:else}
<tr class="empty"><td>{$_("dialogRevisionsDialog.empty")}</td></tr
>
</tr>
{:else}
<tr class="empty"><td>{$_("dialogRevisionsDialog.empty")}</td></tr>
{/each}
</table>
</div>
{#if revisions.length > 0}<p class="count">
{$_("dialogRevisionsDialog.total", {
values: { n: revisions.length },
})}
</p>{/if}
{/each}
</table>
</div>
{#if revisions.length > 0}<p class="count">
{$_("dialogRevisionsDialog.total", {
values: { n: revisions.length },
})}
</p>{/if}
{/if}
{:else if isOrgAdmin(user)}
<UpgradePrompt
message={$_("dialogRevisionsDialog.upgrade.message")}
callToAction={$_("dialogRevisionsDialog.upgrade.adminCta")}
on:click={() => triggerPremiumUpgradeFlow(user?.organization)}
/>
{:else}
<UpgradePrompt
message={$_("dialogRevisionsDialog.upgrade.message") +
" " +
$_("dialogRevisionsDialog.upgrade.nonAdminCta")}
/>
{/if}
{:else if isOrgAdmin(user)}
<UpgradePrompt
message={$_("dialogRevisionsDialog.upgrade.message")}
callToAction={$_("dialogRevisionsDialog.upgrade.adminCta")}
on:click={() => triggerPremiumUpgradeFlow(user?.organization)}
/>
{:else}
<UpgradePrompt
message={$_("dialogRevisionsDialog.upgrade.message") +
" " +
$_("dialogRevisionsDialog.upgrade.nonAdminCta")}
/>
{/if}
</Loader>
{:catch}
<ErrorMessage message={$_("dialogRevisionsDialog.error")} />
<Loader active={false}>
<ErrorMessage message={$_("dialogRevisionsDialog.error")}
><Button caution action on:click={retryGetMe}>Retry</Button></ErrorMessage
>
</Loader>
{/await}

<style>
.container {
}
header {
display: flex;
gap: 1em;
Expand Down
7 changes: 7 additions & 0 deletions src/common/dialog/stories/RevisionsDialog.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,10 @@
{args}
parameters={{ msw: { handlers: [revisionControl.success, mockGetMe.error] } }}
/>
<Story
name="With Loading"
{args}
parameters={{
msw: { handlers: [revisionControl.loading, mockGetMe.loading] },
}}
/>

0 comments on commit 9530c63

Please sign in to comment.