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
+134 -60

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-plugin-svelte": "^3.9.1",
"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",
"marked": "7.0.5",
"marked-linkify-it": "^3.1.10",
+37 -1
View File
@@ -18,6 +18,7 @@ import { writable } from 'svelte/store'
import { t } from './i18n/translations'
import { site } from './lemmy.svelte'
import { errorMessage } from './lemmy/error'
import { publishedToDate } from './components/util/date'
const getDefaultProfile = (): Profile => ({
id: -1,
@@ -173,6 +174,7 @@ $effect.root(() => {
})
})
// cookie migration code
if (
env.PUBLIC_MIGRATE_COOKIE &&
profileData.profiles.length == 0 &&
@@ -365,4 +367,38 @@ async function checkInbox() {
})
}
setInterval(checkInbox, 4 * 60 * 1000)
async function init() {
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={[
'py-3 relative',
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,
]}
id={node.comment_view.comment.id.toString()}
+1 -1
View File
@@ -182,7 +182,7 @@
Debug
</MenuButton>
{/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">
<div class="flex flex-row gap-2 w-full items-center">
<div class="flex-1">
@@ -268,7 +268,7 @@
>
<Icon src={Home} size="16" mini />
</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-[13px] font-medium">
{crumb.name}
@@ -277,11 +277,11 @@
</div>
{/if}
<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">
<span class="text-sm font-medium">{group.name}</span>
<ul class="flex flex-col gap-1">
{#each group.actions as action, actionIndex (action.href)}
{#each group.actions as action, actionIndex}
{@const globalIndex =
filteredGroups
.slice(0, groupIndex)
+4 -2
View File
@@ -498,7 +498,8 @@
"comments": "Comments",
"communities": "Communities",
"instances": "Instances",
"message": "Message"
"message": "Message",
"url": "URL"
},
"post": {
"actions": {
@@ -692,7 +693,8 @@
"purgeUser": "Purged that user.",
"settingsImport": "Successfully imported settings",
"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": {
"title": "Settings",
+18 -10
View File
@@ -12,6 +12,7 @@
Check,
} from 'svelte-hero-icons'
import { fly } from 'svelte/transition'
import Markdown from '$lib/components/markdown/Markdown.svelte'
interface Props {
toast: Toast
@@ -21,9 +22,11 @@
</script>
<div
class="{toastColors[
toast.type
]} relative w-80 rounded-xl overflow-hidden flex flex-row items-center"
class={[
toastColors[toast.type],
'relative rounded-xl overflow-hidden flex flex-row items-start',
toast.long ? 'w-full max-w-lg' : 'w-80',
]}
transition:fly={{
duration: 600,
y: 8,
@@ -39,7 +42,7 @@
<Icon
size="20"
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'
? InformationCircle
: toast.type == 'success'
@@ -51,11 +54,16 @@
: ExclamationCircle}
/>
{/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}
<h1 class="text-base font-bold">{toast.title}</h1>
{/if}
<p class="text-sm">{toast.content}</p>
<Markdown
source={toast.content}
class="{toast.long ? 'text-[15px]' : 'text-sm'} font-medium"
/>
</div>
<div class="ml-auto flex items-center gap-1 m-2">
{#if toast.action}
@@ -64,18 +72,18 @@
toast.action?.()
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>
{/if}
<button
onclick={() => {
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>
</div>
</div>
+8 -5
View File
@@ -3,13 +3,12 @@ import { writable } from 'svelte/store'
type ToastType = keyof typeof toastColors
export const toastColors = {
error:
'bg-white dark:bg-zinc-950 text-red-600 dark:text-red-400 border border-red-700',
error: 'bg-white dark:bg-zinc-925 text-red-500 shadow-red-400/30 shadow-sm',
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:
'bg-white dark:bg-zinc-950 text-green-700 dark:text-green-400 border border-green-500',
info: 'dark:bg-zinc-950 bg-white border border-slate-200 dark:border-zinc-800 shadow-lg',
'bg-white dark:bg-zinc-925 text-green-700 shadow-green-400/30 shadow-sm',
info: 'dark:bg-zinc-925 bg-white border border-slate-200 dark:border-zinc-800',
}
export interface Toast {
@@ -18,6 +17,7 @@ export interface Toast {
content: string
type: ToastType
loading?: boolean
long?: boolean
action?: () => void
}
@@ -29,6 +29,7 @@ export function toast({
type = 'info',
duration = 5000,
loading = false,
long = false,
action,
}: {
title?: string
@@ -36,6 +37,7 @@ export function toast({
type?: ToastType
duration?: number
loading?: boolean
long?: boolean
action?: () => void
}) {
let id = 0
@@ -51,6 +53,7 @@ export function toast({
title: title,
type: type,
loading: loading,
long: long,
action: action,
},
]
+4 -1
View File
@@ -58,7 +58,10 @@ export async function load({ url, fetch }) {
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 => ({
applications: i.applications,
+14 -35
View File
@@ -11,7 +11,6 @@
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import Skeleton from '$lib/components/ui/generic/Skeleton.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 {
isCommentView,
@@ -20,16 +19,17 @@
isUser,
} from '$lib/lemmy/item.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 {
AdjustmentsHorizontal,
ChevronDown,
ChevronDoubleDown,
Icon,
MagnifyingGlass,
} from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
import { fly, slide } from 'svelte/transition'
import SearchBar from './SearchBar.svelte'
let { data } = $props()
@@ -55,33 +55,7 @@
{$t('routes.search.title')}
</Header>
<form method="get" action="/search" class="contents" bind:this={form}>
<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={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>
<SearchBar bind:query={data.filters.value.query} />
<div class="flex flex-row flex-wrap items-center gap-4 mt-4">
<Select
name="type"
@@ -99,6 +73,7 @@
<Option value="Comments">{$t('content.comments')}</Option>
<Option value="Communities">{$t('content.communities')}</Option>
<Option value="Users">{$t('content.users')}</Option>
<Option value="Url">{$t('content.url')}</Option>
</Select>
<Sort
name="sort"
@@ -106,17 +81,21 @@
onchange={() => form?.requestSubmit()}
/>
<Button
size="square-lg"
color="tertiary"
class="self-end justify-self-center"
size="custom"
rounding="xl"
class="self-end justify-self-center h-8.5 w-8.5"
onclick={() => (moreOptions = !moreOptions)}
aria-label={$t('post.actions.more.label')}
>
<Icon src={ChevronDown} size="20" mini />
<Icon src={ChevronDoubleDown} size="20" mini />
</Button>
</div>
</form>
{#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
label={$t('nav.create.community')}
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>