feat: add donation dialog, close #524 (#597)

* feat: add donation dialog, close #524

* fix: command palette broken
This commit is contained in:
Xylight authored and GitHub committed 2025-06-25 23:50:08 +00:00
1 parent 58d5be7027
commit f1f3955a7b
12 files changed
+133 -59

No files matched your search

BIN
View File
Binary file not shown.
+1 -1
View File
@@ -18,7 +18,7 @@
"eslint": "^9.28.0", "eslint": "^9.28.0",
"eslint-plugin-svelte": "^3.9.1", "eslint-plugin-svelte": "^3.9.1",
"jsdom": "^22.1.0", "jsdom": "^22.1.0",
"lemmy-js-client": "^0.19.6-beta.1", "lemmy-js-client": "0.19.11-donation-dialog.1",
"linkify-it": "^5.0.0", "linkify-it": "^5.0.0",
"marked": "7.0.5", "marked": "7.0.5",
"marked-linkify-it": "^3.1.10", "marked-linkify-it": "^3.1.10",
+36
View File
@@ -18,6 +18,7 @@ import { writable } from 'svelte/store'
import { t } from './i18n/translations' import { t } from './i18n/translations'
import { site } from './lemmy.svelte' import { site } from './lemmy.svelte'
import { errorMessage } from './lemmy/error' import { errorMessage } from './lemmy/error'
import { publishedToDate } from './components/util/date'
const getDefaultProfile = (): Profile => ({ const getDefaultProfile = (): Profile => ({
id: -1, id: -1,
@@ -173,6 +174,7 @@ $effect.root(() => {
}) })
}) })
// cookie migration code
if ( if (
env.PUBLIC_MIGRATE_COOKIE && env.PUBLIC_MIGRATE_COOKIE &&
profileData.profiles.length == 0 && profileData.profiles.length == 0 &&
@@ -365,4 +367,38 @@ async function checkInbox() {
}) })
} }
async function init() {
setInterval(checkInbox, 4 * 60 * 1000) setInterval(checkInbox, 4 * 60 * 1000)
// hacky way to check donation status
setTimeout(() => {
if (
profile.data.user?.local_user_view.local_user.last_donation_notification
) {
const donationDate = publishedToDate(
profile.data.user?.local_user_view.local_user
.last_donation_notification,
)
if (Date.now() - donationDate.getTime() > 365 * 24 * 60 * 60 * 1000) {
toast({
content: t.get('toast.lemmyDonate'),
duration: 3600 * 1000,
long: true,
})
// lemmy js client donation dialog is broken
fetch(
`${instanceToURL(profile.data.instance)}/api/v3/user/donation_dialog_shown`,
{
method: 'POST',
headers: {
authorization: `Bearer ${profile.data.jwt}`,
},
},
)
}
}
}, 3 * 1000)
}
init()
@@ -112,7 +112,7 @@
class={[ class={[
'py-3 relative', 'py-3 relative',
node.comment_view.comment.distinguished && node.comment_view.comment.distinguished &&
' text-primary-900 dark:text-primary-100', ' text-primary-900 dark:text-primary-100 bg-green-400/5 -mx-4 sm:-mx-6 px-4 sm:px-6',
clazz, clazz,
]} ]}
id={node.comment_view.comment.id.toString()} id={node.comment_view.comment.id.toString()}
+1 -1
View File
@@ -182,7 +182,7 @@
Debug Debug
</MenuButton> </MenuButton>
{/if} {/if}
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" /> <MenuDivider />
<li class="flex flex-col px-2 py-1 mx-auto my-1 text-xs w-full"> <li class="flex flex-col px-2 py-1 mx-auto my-1 text-xs w-full">
<div class="flex flex-row gap-2 w-full items-center"> <div class="flex flex-row gap-2 w-full items-center">
<div class="flex-1"> <div class="flex-1">
@@ -268,7 +268,7 @@
> >
<Icon src={Home} size="16" mini /> <Icon src={Home} size="16" mini />
</button> </button>
{#each breadcrumbs as crumb (crumb.href)} {#each breadcrumbs as crumb}
<span class="text-base text-slate-400 dark:text-zinc-600">/</span> <span class="text-base text-slate-400 dark:text-zinc-600">/</span>
<span class="text-[13px] font-medium"> <span class="text-[13px] font-medium">
{crumb.name} {crumb.name}
@@ -277,11 +277,11 @@
</div> </div>
{/if} {/if}
<div class="space-y-1" bind:this={container}> <div class="space-y-1" bind:this={container}>
{#each filteredGroups as group, groupIndex (group.name)} {#each filteredGroups as group, groupIndex}
<div class="space-y-1"> <div class="space-y-1">
<span class="text-sm font-medium">{group.name}</span> <span class="text-sm font-medium">{group.name}</span>
<ul class="flex flex-col gap-1"> <ul class="flex flex-col gap-1">
{#each group.actions as action, actionIndex (action.href)} {#each group.actions as action, actionIndex}
{@const globalIndex = {@const globalIndex =
filteredGroups filteredGroups
.slice(0, groupIndex) .slice(0, groupIndex)
+4 -2
View File
@@ -498,7 +498,8 @@
"comments": "Comments", "comments": "Comments",
"communities": "Communities", "communities": "Communities",
"instances": "Instances", "instances": "Instances",
"message": "Message" "message": "Message",
"url": "URL"
}, },
"post": { "post": {
"actions": { "actions": {
@@ -692,7 +693,8 @@
"purgeUser": "Purged that user.", "purgeUser": "Purged that user.",
"settingsImport": "Successfully imported settings", "settingsImport": "Successfully imported settings",
"settingsImportWarning": "The imported settings don't seem valid. Are you sure you want to import this?", "settingsImportWarning": "The imported settings don't seem valid. Are you sure you want to import this?",
"userLoading": "Still loading your user data..." "userLoading": "Still loading your user data...",
"lemmyDonate": "Your account's instance runs Lemmy, and the developers are requesting donations. They are able to develop Lemmy as an open source platform, free of tracking and ads, thanks to the generosity of its users.\n\nAnnually, they ask you to consider donating to support their work, and allow them to continue maintaining and improving Lemmy.\n\n[Donate](https://join-lemmy.org/donate)\n\n*Note: this is a donation to Lemmy, not Photon.*"
}, },
"settings": { "settings": {
"title": "Settings", "title": "Settings",
+18 -10
View File
@@ -12,6 +12,7 @@
Check, Check,
} from 'svelte-hero-icons' } from 'svelte-hero-icons'
import { fly } from 'svelte/transition' import { fly } from 'svelte/transition'
import Markdown from '$lib/components/markdown/Markdown.svelte'
interface Props { interface Props {
toast: Toast toast: Toast
@@ -21,9 +22,11 @@
</script> </script>
<div <div
class="{toastColors[ class={[
toast.type toastColors[toast.type],
]} relative w-80 rounded-xl overflow-hidden flex flex-row items-center" 'relative rounded-xl overflow-hidden flex flex-row items-start',
toast.long ? 'w-full max-w-lg' : 'w-80',
]}
transition:fly={{ transition:fly={{
duration: 600, duration: 600,
y: 8, y: 8,
@@ -39,7 +42,7 @@
<Icon <Icon
size="20" size="20"
mini mini
class="relative m-2 ml-4 shrink-0" class="relative mt-4 mr-2 ml-4 shrink-0 opacity-80"
src={toast.type == 'info' src={toast.type == 'info'
? InformationCircle ? InformationCircle
: toast.type == 'success' : toast.type == 'success'
@@ -51,11 +54,16 @@
: ExclamationCircle} : ExclamationCircle}
/> />
{/if} {/if}
<div class="flex flex-col p-4 pl-0 break-words max-w-full"> <div
class="flex flex-col p-4 pl-0 break-words max-w-full text-slate-900 dark:text-zinc-50"
>
{#if toast.title} {#if toast.title}
<h1 class="text-base font-bold">{toast.title}</h1> <h1 class="text-base font-bold">{toast.title}</h1>
{/if} {/if}
<p class="text-sm">{toast.content}</p> <Markdown
source={toast.content}
class="{toast.long ? 'text-[15px]' : 'text-sm'} font-medium"
/>
</div> </div>
<div class="ml-auto flex items-center gap-1 m-2"> <div class="ml-auto flex items-center gap-1 m-2">
{#if toast.action} {#if toast.action}
@@ -64,18 +72,18 @@
toast.action?.() toast.action?.()
toasts.update(toasts => toasts.filter(t => t.id != toast.id)) toasts.update(toasts => toasts.filter(t => t.id != toast.id))
}} }}
class="rounded-lg w-max transition-colors hover:bg-black/20 dark:hover:bg-white/20 p-2" class="rounded-lg w-max transition-colors hover:bg-slate-100 dark:hover:bg-zinc-800 p-1 cursor-pointer"
> >
<Icon src={Check} size="16" mini /> <Icon src={Check} size="20" micro />
</button> </button>
{/if} {/if}
<button <button
onclick={() => { onclick={() => {
toasts.update(toasts => toasts.filter(t => t.id != toast.id)) toasts.update(toasts => toasts.filter(t => t.id != toast.id))
}} }}
class="rounded-lg w-max transition-colors hover:bg-black/20 dark:hover:bg-white/20 p-2" class="rounded-lg w-max transition-colors hover:bg-slate-100 dark:hover:bg-zinc-800 p-1 cursor-pointer"
> >
<Icon src={XMark} size="16" mini /> <Icon src={XMark} size="20" micro />
</button> </button>
</div> </div>
</div> </div>
+8 -5
View File
@@ -3,13 +3,12 @@ import { writable } from 'svelte/store'
type ToastType = keyof typeof toastColors type ToastType = keyof typeof toastColors
export const toastColors = { export const toastColors = {
error: error: 'bg-white dark:bg-zinc-925 text-red-500 shadow-red-400/30 shadow-sm',
'bg-white dark:bg-zinc-950 text-red-600 dark:text-red-400 border border-red-700',
warning: warning:
'bg-white dark:bg-zinc-950 text-yellow-600 dark:text-yellow-400 border border-yellow-600', 'bg-white dark:bg-zinc-925 text-yellow-500 shadow-yellow-400/30 shadow-sm',
success: success:
'bg-white dark:bg-zinc-950 text-green-700 dark:text-green-400 border border-green-500', 'bg-white dark:bg-zinc-925 text-green-700 shadow-green-400/30 shadow-sm',
info: 'dark:bg-zinc-950 bg-white border border-slate-200 dark:border-zinc-800 shadow-lg', info: 'dark:bg-zinc-925 bg-white border border-slate-200 dark:border-zinc-800',
} }
export interface Toast { export interface Toast {
@@ -18,6 +17,7 @@ export interface Toast {
content: string content: string
type: ToastType type: ToastType
loading?: boolean loading?: boolean
long?: boolean
action?: () => void action?: () => void
} }
@@ -29,6 +29,7 @@ export function toast({
type = 'info', type = 'info',
duration = 5000, duration = 5000,
loading = false, loading = false,
long = false,
action, action,
}: { }: {
title?: string title?: string
@@ -36,6 +37,7 @@ export function toast({
type?: ToastType type?: ToastType
duration?: number duration?: number
loading?: boolean loading?: boolean
long?: boolean
action?: () => void action?: () => void
}) { }) {
let id = 0 let id = 0
@@ -51,6 +53,7 @@ export function toast({
title: title, title: title,
type: type, type: type,
loading: loading, loading: loading,
long: long,
action: action, action: action,
}, },
] ]
+4 -1
View File
@@ -58,7 +58,10 @@ export async function load({ url, fetch }) {
publishedToDate(a.published).getTime(), publishedToDate(a.published).getTime(),
) )
const totalNotifs = type == 'all' ? data.filter(i => !i.read).length : 0 const totalNotifs =
type == 'all'
? data.filter(i => i.type != 'private_message' && !i.read).length
: 0
notifications.update(i => ({ notifications.update(i => ({
applications: i.applications, applications: i.applications,
+14 -35
View File
@@ -11,7 +11,6 @@
import Placeholder from '$lib/components/ui/Placeholder.svelte' import Placeholder from '$lib/components/ui/Placeholder.svelte'
import Skeleton from '$lib/components/ui/generic/Skeleton.svelte' import Skeleton from '$lib/components/ui/generic/Skeleton.svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte' import Header from '$lib/components/ui/layout/pages/Header.svelte'
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
import { t } from '$lib/i18n/translations.js' import { t } from '$lib/i18n/translations.js'
import { import {
isCommentView, isCommentView,
@@ -20,16 +19,17 @@
isUser, isUser,
} from '$lib/lemmy/item.js' } from '$lib/lemmy/item.js'
import { searchParam } from '$lib/util.svelte.js' import { searchParam } from '$lib/util.svelte.js'
import { Button, Select, Spinner, TextInput } from 'mono-svelte' import { Button, Select, Spinner } from 'mono-svelte'
import Option from 'mono-svelte/forms/select/Option.svelte' import Option from 'mono-svelte/forms/select/Option.svelte'
import { import {
AdjustmentsHorizontal, AdjustmentsHorizontal,
ChevronDown, ChevronDoubleDown,
Icon, Icon,
MagnifyingGlass, MagnifyingGlass,
} from 'svelte-hero-icons' } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing' import { expoOut } from 'svelte/easing'
import { fly, slide } from 'svelte/transition' import { fly, slide } from 'svelte/transition'
import SearchBar from './SearchBar.svelte'
let { data } = $props() let { data } = $props()
@@ -55,33 +55,7 @@
{$t('routes.search.title')} {$t('routes.search.title')}
</Header> </Header>
<form method="get" action="/search" class="contents" bind:this={form}> <form method="get" action="/search" class="contents" bind:this={form}>
<div class="mt-4 mb-0 sticky z-30 top-6 lg:top-22"> <SearchBar bind:query={data.filters.value.query} />
<Tabs routes={[]} class="p-2 dark:bg-zinc-925/70">
<div class="flex gap-2 flex-row items-center w-full text-base h-10">
<TextInput
bind:value={data.filters.value.query}
bind:element={searchElement}
name="q"
aria-label={$t('routes.search.query')}
size="lg"
class="flex-1 rounded-full! h-full text-base!"
/>
<Button
submit
color="primary"
size="custom"
class="shrink-0 h-full aspect-square"
title="Search"
rounding="pill"
loading={navigating.to?.route.id == '/search'}
>
{#snippet prefix()}
<Icon src={MagnifyingGlass} size="16" micro />
{/snippet}
</Button>
</div>
</Tabs>
</div>
<div class="flex flex-row flex-wrap items-center gap-4 mt-4"> <div class="flex flex-row flex-wrap items-center gap-4 mt-4">
<Select <Select
name="type" name="type"
@@ -99,6 +73,7 @@
<Option value="Comments">{$t('content.comments')}</Option> <Option value="Comments">{$t('content.comments')}</Option>
<Option value="Communities">{$t('content.communities')}</Option> <Option value="Communities">{$t('content.communities')}</Option>
<Option value="Users">{$t('content.users')}</Option> <Option value="Users">{$t('content.users')}</Option>
<Option value="Url">{$t('content.url')}</Option>
</Select> </Select>
<Sort <Sort
name="sort" name="sort"
@@ -106,17 +81,21 @@
onchange={() => form?.requestSubmit()} onchange={() => form?.requestSubmit()}
/> />
<Button <Button
size="square-lg" size="custom"
color="tertiary" rounding="xl"
class="self-end justify-self-center" class="self-end justify-self-center h-8.5 w-8.5"
onclick={() => (moreOptions = !moreOptions)} onclick={() => (moreOptions = !moreOptions)}
aria-label={$t('post.actions.more.label')}
> >
<Icon src={ChevronDown} size="20" mini /> <Icon src={ChevronDoubleDown} size="20" mini />
</Button> </Button>
</div> </div>
</form> </form>
{#if moreOptions} {#if moreOptions}
<div transition:slide={{ axis: 'y', easing: expoOut }} class="max-w-sm"> <div
transition:slide={{ axis: 'y', easing: expoOut, duration: 500 }}
class="flex flex-row gap-2 flex-wrap"
>
<ObjectAutocomplete <ObjectAutocomplete
label={$t('nav.create.community')} label={$t('nav.create.community')}
jwt={profile.data?.jwt} jwt={profile.data?.jwt}
+43
View File
@@ -0,0 +1,43 @@
<script lang="ts">
import { navigating } from '$app/state'
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
import { t } from '$lib/i18n/translations'
import { Button, TextInput } from 'mono-svelte'
import { Icon, MagnifyingGlass } from 'svelte-hero-icons'
interface Props {
query?: string | null
}
let { query = $bindable() }: Props = $props()
let searchElement = $state<HTMLInputElement>()
</script>
<div class="mt-4 mb-0 sticky z-30 top-6 lg:top-22">
<Tabs routes={[]} class="p-2 dark:bg-zinc-925/70">
<div class="flex gap-2 flex-row items-center w-full text-base h-10">
<TextInput
bind:value={query}
bind:element={searchElement}
name="q"
aria-label={$t('routes.search.query')}
size="lg"
class="flex-1 rounded-full! h-full text-base!"
/>
<Button
submit
color="primary"
size="custom"
class="shrink-0 h-full aspect-square"
title="Search"
rounding="pill"
loading={navigating.to?.route.id == '/search'}
>
{#snippet prefix()}
<Icon src={MagnifyingGlass} size="16" micro />
{/snippet}
</Button>
</div>
</Tabs>
</div>