-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new version announcement (#53)
* fix: handle no data when importing visited country data (wrong branch) * feat: new version announcement
- Loading branch information
Showing
11 changed files
with
218 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/lib/components/modals/new-version-announcement/NewTabLink.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script lang="ts"> | ||
import type { Snippet } from 'svelte'; | ||
let { | ||
href, | ||
title, | ||
children, | ||
}: { href: string; title: string | undefined; children: Snippet } = $props(); | ||
let prNum = $derived(href.match(/pull\/(\d+)/)?.[1]); | ||
</script> | ||
|
||
<a target="_blank" {href} {title}> | ||
{#if prNum} | ||
#{prNum} | ||
{:else} | ||
{@render children()} | ||
{/if} | ||
</a> |
71 changes: 71 additions & 0 deletions
71
src/lib/components/modals/new-version-announcement/NewVersionAnnouncement.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<script lang="ts"> | ||
import * as Dialog from '$lib/components/ui/alert-dialog'; | ||
import SvelteMarkdown from 'svelte-markdown'; | ||
import NewTabLink from './NewTabLink.svelte'; | ||
import { Badge } from '$lib/components/ui/badge'; | ||
import { version } from '$app/environment'; | ||
import semver, { SemVer } from 'semver'; | ||
import { Button } from '$lib/components/ui/button'; | ||
let open = $state(false); | ||
let changelog: { name: string; body: string } | null = $state(null); | ||
$effect(() => { | ||
fetch( | ||
'https://api.github.com/repos/johanohly/AirTrail/releases/latest', | ||
).then(async (response) => { | ||
if (!response.ok) return; | ||
const data = await response.json(); | ||
const latestVersion = new SemVer(data.tag_name); | ||
const dismissedVersion = localStorage.getItem('dismissedVersion'); | ||
// If the latest version is the same as the current version or the new version has been dismissed, return | ||
if ( | ||
semver.lte(latestVersion, version) || | ||
(dismissedVersion && semver.lte(latestVersion, dismissedVersion)) | ||
) { | ||
return; | ||
} | ||
changelog = { | ||
name: data.tag_name, | ||
body: data.body, | ||
}; | ||
open = true; | ||
}); | ||
}); | ||
const dismissVersion = () => { | ||
if (!changelog) return; | ||
localStorage.setItem('dismissedVersion', changelog?.name); | ||
}; | ||
</script> | ||
|
||
{#if changelog} | ||
<Dialog.Root bind:open> | ||
<Dialog.Content> | ||
<Dialog.Header> | ||
<Dialog.Title class="flex items-center gap-4"> | ||
New version available! | ||
<Badge>{changelog.name}</Badge> | ||
</Dialog.Title> | ||
</Dialog.Header> | ||
<div class="prose max-h-[80dvh] overflow-y-auto"> | ||
<SvelteMarkdown | ||
source={changelog.body} | ||
renderers={{ link: NewTabLink }} | ||
/> | ||
</div> | ||
<Dialog.Footer> | ||
<Button | ||
variant="outline" | ||
href="https://johanohly.github.io/AirTrail/docs/install/updating" | ||
target="_blank" | ||
> | ||
How to update | ||
</Button> | ||
<Dialog.Action onclick={dismissVersion}>Got it</Dialog.Action> | ||
</Dialog.Footer> | ||
</Dialog.Content> | ||
</Dialog.Root> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script lang="ts"> | ||
import { type Variant, badgeVariants } from './index.js'; | ||
import { cn } from '$lib/utils'; | ||
let className: string | undefined | null = undefined; | ||
export let href: string | undefined = undefined; | ||
export let variant: Variant = 'default'; | ||
export { className as class }; | ||
</script> | ||
|
||
<svelte:element | ||
this={href ? 'a' : 'span'} | ||
{href} | ||
class={cn(badgeVariants({ variant, className }))} | ||
{...$$restProps} | ||
> | ||
<slot /> | ||
</svelte:element> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters