feat: add share target to PWA
This commit is contained in:
7 files changed
+91
-8
No files matched your search
@@ -325,7 +325,7 @@
|
||||
"description": "That content does not originate from {{homeInstance}}.",
|
||||
"actions": {
|
||||
"back": "Go back",
|
||||
"fetch": "Locate post on {{homeInstance}}",
|
||||
"fetch": "Continue on {{homeInstance}}",
|
||||
"switch": "Switch to an account on {{destInstance}}"
|
||||
},
|
||||
"automatic": {
|
||||
@@ -563,6 +563,7 @@
|
||||
"share.from": "Share from",
|
||||
"share.global": "Origin server",
|
||||
"share.local": "Your server",
|
||||
"share.photon": "Photon link",
|
||||
"crosspost": "Crosspost",
|
||||
"delete": "Delete",
|
||||
"restore": "Restore"
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import type { PostView } from '$lib/api/types'
|
||||
import { profile } from '$lib/app/auth.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/app/instance.svelte'
|
||||
import { settings, type View } from '$lib/app/settings.svelte'
|
||||
import { instanceToURL } from '$lib/app/util.svelte'
|
||||
import { save } from '$lib/feature/legacy/contentview'
|
||||
import { Photon } from '$lib/ui/icon/photon'
|
||||
import { publishedToDate } from '$lib/ui/util/date'
|
||||
import FormattedNumber from '$lib/ui/util/FormattedNumber.svelte'
|
||||
import {
|
||||
@@ -56,10 +59,12 @@
|
||||
let buttonHeight = $derived(view == 'compact' ? 'h-7.5' : 'h-8')
|
||||
let buttonSquare = $derived(view == 'compact' ? 'w-7.5 h-7.5' : 'w-8 h-8')
|
||||
|
||||
function share(global: boolean = true) {
|
||||
const link = global
|
||||
? post.post.ap_id
|
||||
: `${instanceToURL(profile.current.instance)}/post/${post.post.id}`
|
||||
function share(global: boolean = true, url?: string) {
|
||||
const link =
|
||||
url ??
|
||||
(global
|
||||
? post.post.ap_id
|
||||
: `${instanceToURL(profile.current.instance)}/post/${post.post.id}`)
|
||||
|
||||
if (navigator.share)
|
||||
navigator.share?.({
|
||||
@@ -213,6 +218,21 @@
|
||||
<MenuButton onclick={() => share(false)} icon={MapPin}>
|
||||
{$t('post.actions.more.share.local')}
|
||||
</MenuButton>
|
||||
{#if !LINKED_INSTANCE_URL}
|
||||
<MenuDivider>
|
||||
<svelte:fragment></svelte:fragment>
|
||||
</MenuDivider>
|
||||
<MenuButton
|
||||
onclick={() =>
|
||||
share(
|
||||
false,
|
||||
new URL(`/go/${post.post.ap_id}`, page.url.origin).toString(),
|
||||
)}
|
||||
icon={Photon}
|
||||
>
|
||||
{$t('post.actions.more.share.photon')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
</Menu>
|
||||
|
||||
{#if profile.current.jwt}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { IconVariants } from '@xylightdev/svelte-hero-icons'
|
||||
|
||||
const photon = {
|
||||
a: {
|
||||
viewBox: '0 0 100 100',
|
||||
fill: 'currentColor',
|
||||
},
|
||||
path: [
|
||||
{
|
||||
'fill-rule': 'evenodd',
|
||||
d: 'M45.5 10.8868C48.594 9.10042 52.406 9.10042 55.5 10.8868L82.3061 26.3632C85.4001 28.1496 87.3061 31.4508 87.3061 35.0235V65.9765C87.3061 69.5492 85.4001 72.8504 82.3061 74.6368L55.5 90.1132C52.406 91.8996 48.594 91.8996 45.5 90.1132L18.6939 74.6368C15.5999 72.8504 13.6939 69.5492 13.6939 65.9765V35.0235C13.6939 31.4508 15.5999 28.1496 18.6939 26.3632L45.5 10.8868Z',
|
||||
'clip-rule': 'evenodd',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const outline = {
|
||||
a: {
|
||||
viewBox: '0 0 100 100',
|
||||
fill: 'currentColor',
|
||||
'stroke-width': '1.5',
|
||||
stroke: 'currentColor',
|
||||
},
|
||||
path: [
|
||||
{
|
||||
d: 'M45.5 10.8868C48.594 9.10042 52.406 9.10042 55.5 10.8868L82.3061 26.3632C85.4001 28.1496 87.3061 31.4508 87.3061 35.0235V65.9765C87.3061 69.5492 85.4001 72.8504 82.3061 74.6368L55.5 90.1132C52.406 91.8996 48.594 91.8996 45.5 90.1132L18.6939 74.6368C15.5999 72.8504 13.6939 69.5492 13.6939 65.9765V35.0235C13.6939 31.4508 15.5999 28.1496 18.6939 26.3632L45.5 10.8868Z',
|
||||
'stroke-linecap': 'round',
|
||||
'stroke-linejoin': 'round',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export const Photon: IconVariants = {
|
||||
micro: photon,
|
||||
mini: photon,
|
||||
solid: photon,
|
||||
outline: outline,
|
||||
} as unknown as IconVariants
|
||||
@@ -0,0 +1,11 @@
|
||||
import { photonify } from '$lib/app/markdown/renderers/plugins'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ url }) {
|
||||
const link = url.searchParams.get('localize')
|
||||
|
||||
if (link) {
|
||||
const localized = photonify(link)
|
||||
if (localized) redirect(302, localized)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ params }) {
|
||||
redirect(302, `/go?localize=${params.link}`)
|
||||
}
|
||||
@@ -58,8 +58,7 @@
|
||||
<Button
|
||||
{loading}
|
||||
disabled={loading}
|
||||
size="md"
|
||||
rounding="pill"
|
||||
size="lg"
|
||||
color="primary"
|
||||
onclick={fetchOnHome}
|
||||
>
|
||||
@@ -68,7 +67,7 @@
|
||||
})}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button size="md" rounding="pill" onclick={() => history.back()}>
|
||||
<Button size="lg" onclick={() => history.back()}>
|
||||
{$t('routes.postRedirect.actions.back')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -50,5 +50,14 @@
|
||||
"url": "/profile/user"
|
||||
}
|
||||
],
|
||||
"share_target": {
|
||||
"action": "/go",
|
||||
"method": "GET",
|
||||
"params": {
|
||||
"post_title": "name",
|
||||
"post_body": "description",
|
||||
"localize": "link"
|
||||
}
|
||||
},
|
||||
"categories": ["entertainment", "news", "social"]
|
||||
}
|
||||
Reference in new issue
Block a user