refactor: switch posts to barrel export
This commit is contained in:
47 files changed
+424
-528
No files matched your search
+1
-11
@@ -7,7 +7,6 @@ import {
|
|||||||
import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js'
|
import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js'
|
||||||
import { client, getClient, site } from '$lib/client/lemmy.svelte'
|
import { client, getClient, site } from '$lib/client/lemmy.svelte'
|
||||||
import { instanceToURL, moveItem } from '$lib/util.svelte'
|
import { instanceToURL, moveItem } from '$lib/util.svelte'
|
||||||
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
|
||||||
import { toast } from 'mono-svelte'
|
import { toast } from 'mono-svelte'
|
||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
import { t } from './i18n/translations'
|
import { t } from './i18n/translations'
|
||||||
@@ -309,9 +308,7 @@ export const notifications = writable<Notifications>({
|
|||||||
async function userFromJwt(
|
async function userFromJwt(
|
||||||
jwt: string,
|
jwt: string,
|
||||||
instance: string,
|
instance: string,
|
||||||
): Promise<
|
): Promise<{ user?: MyUserInfo; site: GetSiteResponse } | undefined> {
|
||||||
{ user: MyUserInfo | undefined; site: GetSiteResponse } | undefined
|
|
||||||
> {
|
|
||||||
const sitePromise = client({ instanceURL: instance, auth: jwt }).getSite()
|
const sitePromise = client({ instanceURL: instance, auth: jwt }).getSite()
|
||||||
|
|
||||||
const timer = setTimeout(
|
const timer = setTimeout(
|
||||||
@@ -335,13 +332,6 @@ async function userFromJwt(
|
|||||||
|
|
||||||
if (!site) return
|
if (!site) return
|
||||||
|
|
||||||
if (!versionIsSupported(site.version, MINIMUM_VERSION)) {
|
|
||||||
toast({
|
|
||||||
content: `This version of Photon only supports Lemmy instances with version ${MINIMUM_VERSION} or higher. This Lemmy instance is running: ${site.version}`,
|
|
||||||
type: 'error',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const myUser = site.my_user
|
const myUser = site.my_user
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
|
||||||
import { publishedToDate } from '$lib/components/util/date.js'
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import type { CommentView } from '$lib/client/types'
|
import type { CommentView } from '$lib/client/types'
|
||||||
import { Button, Material } from 'mono-svelte'
|
import { Button, Material } from 'mono-svelte'
|
||||||
import { ArrowUturnUp, Icon } from 'svelte-hero-icons'
|
import { ArrowUturnUp, Icon } from 'svelte-hero-icons'
|
||||||
import type { ClassValue } from 'svelte/elements'
|
import type { ClassValue } from 'svelte/elements'
|
||||||
|
import { PostMeta } from '../post'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
comment: CommentView
|
comment: CommentView
|
||||||
|
|||||||
@@ -22,9 +22,9 @@
|
|||||||
|
|
||||||
interface Props extends HTMLAttributes<HTMLDivElement> {
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
||||||
site: SiteView
|
site: SiteView
|
||||||
taglines?: Tagline[] | undefined
|
taglines?: Tagline[]
|
||||||
admins?: PersonView[] | undefined
|
admins?: PersonView[]
|
||||||
version?: string | undefined
|
version?: string
|
||||||
class?: ClassValue
|
class?: ClassValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { getClient } from '$lib/client/lemmy.svelte'
|
import { getClient } from '$lib/client/lemmy.svelte'
|
||||||
@@ -18,6 +17,7 @@
|
|||||||
import { Fire, Icon, Trash } from 'svelte-hero-icons'
|
import { Fire, Icon, Trash } from 'svelte-hero-icons'
|
||||||
import { amMod, isAdmin } from './moderation'
|
import { amMod, isAdmin } from './moderation'
|
||||||
import { errorMessage } from '$lib/lemmy/error'
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
|
import { Post } from '../post'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
open: boolean
|
open: boolean
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
import { profile } from '$lib/auth.svelte.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { getClient } from '$lib/client/lemmy.svelte'
|
import { getClient } from '$lib/client/lemmy.svelte'
|
||||||
@@ -15,6 +14,7 @@
|
|||||||
import { Button, Modal, toast } from 'mono-svelte'
|
import { Button, Modal, toast } from 'mono-svelte'
|
||||||
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
||||||
import { errorMessage } from '$lib/lemmy/error'
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
|
import { Post } from '../post'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
open: boolean
|
open: boolean
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { profile } from '$lib/auth.svelte'
|
import { profile } from '$lib/auth.svelte'
|
||||||
import PostActions from '$lib/components/lemmy/post/actions/PostActions.svelte'
|
|
||||||
import { mediaType } from '$lib/components/lemmy/post/helpers.js'
|
|
||||||
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
|
|
||||||
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
|
|
||||||
import PostMeta, {
|
|
||||||
parseTags,
|
|
||||||
type Tag,
|
|
||||||
} from '$lib/components/lemmy/post/PostMeta.svelte'
|
|
||||||
import { publishedToDate } from '$lib/components/util/date.js'
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
import { settings, type View } from '$lib/settings.svelte.js'
|
import { settings, type View } from '$lib/settings.svelte.js'
|
||||||
import type { PostView } from '$lib/client/types'
|
import type { PostView } from '$lib/client/types'
|
||||||
import type { ClassValue } from 'svelte/elements'
|
import type { ClassValue } from 'svelte/elements'
|
||||||
import PostBody from './PostBody.svelte'
|
import {
|
||||||
|
type Tag,
|
||||||
|
PostMeta,
|
||||||
|
PostActions,
|
||||||
|
PostMedia,
|
||||||
|
PostBody,
|
||||||
|
parseTags,
|
||||||
|
mediaType,
|
||||||
|
PostMediaCompact,
|
||||||
|
} from '.'
|
||||||
|
|
||||||
function getTagRule(tags: Tag[]): 'blur-sm' | 'hide' | undefined {
|
function getTagRule(tags: Tag[]): 'blur-sm' | 'hide' | undefined {
|
||||||
const tagContent = tags.map((t) => t.content.toLowerCase())
|
const tagContent = tags.map((t) => t.content.toLowerCase())
|
||||||
|
|||||||
@@ -54,9 +54,11 @@ dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0 max-h-36`
|
|||||||
onclick={() => (expanded = !expanded)}
|
onclick={() => (expanded = !expanded)}
|
||||||
size="square-sm"
|
size="square-sm"
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
class="text-black dark:text-white absolute z-10 isolate pointer-events-auto bottom-0 {expanded
|
class={[
|
||||||
? 'bg-slate-200/50 dark:bg-zinc-900 border shadow-md'
|
'text-black dark:text-white absolute z-10 isolate pointer-events-auto bottom-0',
|
||||||
: ''} left-1/2 -translate-x-1/2 mb-4"
|
'left-1/2 -translate-x-1/2 mb-4',
|
||||||
|
expanded && 'bg-slate-200/50 dark:bg-zinc-900 shadow-md',
|
||||||
|
]}
|
||||||
title="Expand"
|
title="Expand"
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PostView } from '$lib/client/types'
|
import type { PostView } from '$lib/client/types'
|
||||||
import Post from './Post.svelte'
|
import { Post } from '.'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
post: PostView
|
post: PostView
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
<script lang="ts" module>
|
<script lang="ts" module> type BadgeType =
|
||||||
|
| 'nsfw'
|
||||||
|
| 'saved'
|
||||||
|
| 'featured'
|
||||||
|
| 'deleted'
|
||||||
|
| 'removed'
|
||||||
|
| 'locked'
|
||||||
|
| 'moderator'
|
||||||
|
| 'admin'
|
||||||
export interface Tag {
|
export interface Tag {
|
||||||
content: string
|
content: string
|
||||||
color?: string
|
color?: string
|
||||||
@@ -11,6 +19,64 @@
|
|||||||
['CW', { content: 'CW', color: '#ff000040' }],
|
['CW', { content: 'CW', color: '#ff000040' }],
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const badgeToData: Map<
|
||||||
|
BadgeType,
|
||||||
|
{
|
||||||
|
icon: IconSource
|
||||||
|
color: 'red-subtle' | 'yellow-subtle' | 'green-subtle'
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
> = new Map([
|
||||||
|
[
|
||||||
|
'nsfw',
|
||||||
|
{
|
||||||
|
icon: ExclamationTriangle,
|
||||||
|
color: 'red-subtle',
|
||||||
|
label: t.get('post.badges.nsfw'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'saved',
|
||||||
|
{
|
||||||
|
icon: Bookmark,
|
||||||
|
color: 'yellow-subtle',
|
||||||
|
label: t.get('post.badges.saved'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'featured',
|
||||||
|
{
|
||||||
|
icon: Megaphone,
|
||||||
|
color: 'green-subtle',
|
||||||
|
label: t.get('post.badges.featured'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'removed',
|
||||||
|
{
|
||||||
|
icon: Trash,
|
||||||
|
color: 'green-subtle',
|
||||||
|
label: t.get('post.badges.removed'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'deleted',
|
||||||
|
{
|
||||||
|
icon: Trash,
|
||||||
|
color: 'red-subtle',
|
||||||
|
label: t.get('post.badges.deleted'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'locked',
|
||||||
|
{
|
||||||
|
icon: LockClosed,
|
||||||
|
color: 'yellow-subtle',
|
||||||
|
label: t.get('post.badges.locked'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
])
|
||||||
|
|
||||||
export const parseTags = (
|
export const parseTags = (
|
||||||
title?: string,
|
title?: string,
|
||||||
): { tags: Tag[]; title?: string } => {
|
): { tags: Tag[]; title?: string } => {
|
||||||
@@ -43,6 +109,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { profile } from '$lib/auth.svelte'
|
||||||
|
import type { Community, Person, SubscribedType } from '$lib/client/types'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
@@ -51,10 +119,8 @@
|
|||||||
formatRelativeDate,
|
formatRelativeDate,
|
||||||
} from '$lib/components/util/RelativeDate.svelte'
|
} from '$lib/components/util/RelativeDate.svelte'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { instance } from '$lib/instance.svelte'
|
|
||||||
import { settings, type View } from '$lib/settings.svelte'
|
import { settings, type View } from '$lib/settings.svelte'
|
||||||
import type { Community, Person, SubscribedType } from '$lib/client/types'
|
import { Badge, Material, modal, Popover } from 'mono-svelte'
|
||||||
import { Badge, modal, Popover } from 'mono-svelte'
|
|
||||||
import {
|
import {
|
||||||
Bookmark,
|
Bookmark,
|
||||||
ExclamationTriangle,
|
ExclamationTriangle,
|
||||||
@@ -68,7 +134,6 @@
|
|||||||
Trash,
|
Trash,
|
||||||
type IconSource,
|
type IconSource,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import Material from 'mono-svelte/materials/Material.svelte'
|
|
||||||
import { CommunityLink } from '../community'
|
import { CommunityLink } from '../community'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -83,16 +148,7 @@
|
|||||||
edited?: string
|
edited?: string
|
||||||
view?: View
|
view?: View
|
||||||
// Badges
|
// Badges
|
||||||
badges?: {
|
badges?: Record<BadgeType, boolean>
|
||||||
nsfw: boolean
|
|
||||||
saved: boolean
|
|
||||||
featured: boolean
|
|
||||||
deleted: boolean
|
|
||||||
removed: boolean
|
|
||||||
locked: boolean
|
|
||||||
moderator: boolean
|
|
||||||
admin: boolean
|
|
||||||
}
|
|
||||||
tags?: Tag[]
|
tags?: Tag[]
|
||||||
style?: string
|
style?: string
|
||||||
titleClass?: string
|
titleClass?: string
|
||||||
@@ -274,66 +330,17 @@
|
|||||||
</a>
|
</a>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
{#if badges.nsfw}
|
{#each Object.keys(badges)
|
||||||
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
|
// filter by ones that are true
|
||||||
{#snippet icon()}
|
.filter(i => badges[i as BadgeType] == true)
|
||||||
<Icon src={ExclamationTriangle} size="14" micro />
|
// get from predetermined map
|
||||||
{/snippet}
|
.map(i => badgeToData.get(i as BadgeType))
|
||||||
{$t('post.badges.nsfw')}
|
// remove null
|
||||||
|
.filter(i => i != undefined) as badge}
|
||||||
|
<Badge label={badge.label} color={badge.color} allowIconOnly>{#snippet icon()}
|
||||||
|
<Icon src={badge.icon} micro size="14" />{/snippet}{badge.label}
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/each}
|
||||||
{#if badges.saved}
|
|
||||||
<Badge
|
|
||||||
label={$t('post.badges.saved')}
|
|
||||||
color="yellow-subtle"
|
|
||||||
allowIconOnly
|
|
||||||
>
|
|
||||||
{#snippet icon()}
|
|
||||||
<Icon src={Bookmark} micro size="14" />
|
|
||||||
{/snippet}
|
|
||||||
{$t('post.badges.saved')}
|
|
||||||
</Badge>
|
|
||||||
{/if}
|
|
||||||
{#if badges.locked}
|
|
||||||
<Badge
|
|
||||||
label={$t('post.badges.locked')}
|
|
||||||
color="yellow-subtle"
|
|
||||||
allowIconOnly
|
|
||||||
>
|
|
||||||
{#snippet icon()}
|
|
||||||
<Icon src={LockClosed} micro size="14" />
|
|
||||||
{/snippet}
|
|
||||||
<span class="max-md:hidden">{$t('post.badges.locked')}</span>
|
|
||||||
</Badge>
|
|
||||||
{/if}
|
|
||||||
{#if badges.removed}
|
|
||||||
<Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly>
|
|
||||||
{#snippet icon()}
|
|
||||||
<Icon src={Trash} micro size="14" />
|
|
||||||
{/snippet}
|
|
||||||
<span class="max-md:hidden">{$t('post.badges.removed')}</span>
|
|
||||||
</Badge>
|
|
||||||
{/if}
|
|
||||||
{#if badges.deleted}
|
|
||||||
<Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly>
|
|
||||||
{#snippet icon()}
|
|
||||||
<Icon src={Trash} micro size="14" />
|
|
||||||
{/snippet}
|
|
||||||
<span class="max-md:hidden">{$t('post.badges.deleted')}</span>
|
|
||||||
</Badge>
|
|
||||||
{/if}
|
|
||||||
{#if badges.featured}
|
|
||||||
<Badge
|
|
||||||
label={$t('post.badges.featured')}
|
|
||||||
color="green-subtle"
|
|
||||||
allowIconOnly
|
|
||||||
>
|
|
||||||
{#snippet icon()}
|
|
||||||
<Icon src={Megaphone} micro size="14" />
|
|
||||||
{/snippet}
|
|
||||||
<span class="max-md:hidden">{$t('post.badges.featured')}</span>
|
|
||||||
</Badge>
|
|
||||||
{/if}
|
|
||||||
{@render extraBadges?.()}
|
{@render extraBadges?.()}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@@ -341,8 +348,7 @@
|
|||||||
{@const useAttachedUrl = settings.posts.titleOpensUrl && postUrl}
|
{@const useAttachedUrl = settings.posts.titleOpensUrl && postUrl}
|
||||||
<h3
|
<h3
|
||||||
class={[
|
class={[
|
||||||
'max-sm:m-0!',
|
'font-medium max-sm:mt-0!',
|
||||||
'font-medium',
|
|
||||||
titleClass,
|
titleClass,
|
||||||
settings.markReadPosts && read && 'text-slate-600 dark:text-zinc-400',
|
settings.markReadPosts && read && 'text-slate-600 dark:text-zinc-400',
|
||||||
view == 'compact' ? 'text-base' : 'text-lg',
|
view == 'compact' ? 'text-base' : 'text-lg',
|
||||||
@@ -352,7 +358,7 @@
|
|||||||
<a
|
<a
|
||||||
href={useAttachedUrl
|
href={useAttachedUrl
|
||||||
? postUrl
|
? postUrl
|
||||||
: `/post/${encodeURIComponent(instance.data)}/${id}`}
|
: `/post/${encodeURIComponent(profile.current.intsance)}/${id}`}
|
||||||
target={useAttachedUrl
|
target={useAttachedUrl
|
||||||
? '_blank'
|
? '_blank'
|
||||||
: undefined}
|
: undefined}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
ShieldCheck,
|
ShieldCheck,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { postLink } from '../helpers'
|
import { postLink } from '../helpers'
|
||||||
import PostVote from '../PostVote.svelte'
|
import { PostVote } from '..'
|
||||||
|
|
||||||
let saving = $state(false)
|
let saving = $state(false)
|
||||||
let editing = $state(false)
|
let editing = $state(false)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
|
||||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||||
import { settings } from '$lib/settings.svelte.js'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
import type { PostView } from '$lib/client/types'
|
import type { PostView } from '$lib/client/types'
|
||||||
import { Button } from 'mono-svelte'
|
import { Button } from 'mono-svelte'
|
||||||
import type { Snippet } from 'svelte'
|
import type { Snippet } from 'svelte'
|
||||||
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
|
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
|
||||||
|
import { Post } from '..'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
posts: PostView[]
|
posts: PostView[]
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
|
||||||
import VirtualList from '$lib/components/render/VirtualList.svelte'
|
import VirtualList from '$lib/components/render/VirtualList.svelte'
|
||||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||||
@@ -26,6 +25,7 @@
|
|||||||
import { expoOut } from 'svelte/easing'
|
import { expoOut } from 'svelte/easing'
|
||||||
import { SvelteSet } from 'svelte/reactivity'
|
import { SvelteSet } from 'svelte/reactivity'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
|
import { Post } from '..'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
posts: PostView[]
|
posts: PostView[]
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
import { settings } from '$lib/settings.svelte'
|
|
||||||
import type { PostView } from '$lib/client/types'
|
|
||||||
import { SvelteMap, SvelteSet } from 'svelte/reactivity'
|
|
||||||
|
|
||||||
export type PostViewWithCrossposts = PostView & {
|
|
||||||
withCrossposts: true
|
|
||||||
crossposts: PostView[]
|
|
||||||
}
|
|
||||||
export type PostViewWithoutCrossposts = PostView & { withCrossposts?: false }
|
|
||||||
|
|
||||||
export const combineCrossposts = (
|
|
||||||
posts: PostView[],
|
|
||||||
): (PostViewWithCrossposts | PostViewWithoutCrossposts)[] => {
|
|
||||||
const urlMap = new SvelteMap<
|
|
||||||
string,
|
|
||||||
PostViewWithCrossposts | PostViewWithoutCrossposts
|
|
||||||
>()
|
|
||||||
const results: (PostViewWithCrossposts | PostViewWithoutCrossposts)[] = []
|
|
||||||
const seenUrls = new SvelteSet<string>()
|
|
||||||
|
|
||||||
posts?.forEach((post) => {
|
|
||||||
if (
|
|
||||||
!post ||
|
|
||||||
(settings.hidePosts.deleted && post.post.deleted) ||
|
|
||||||
(settings.hidePosts.removed && post.post.removed)
|
|
||||||
)
|
|
||||||
return
|
|
||||||
if (!post?.post?.url) {
|
|
||||||
results.push(post)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const existing = urlMap.get(post.post.url)
|
|
||||||
if (existing) {
|
|
||||||
existing.withCrossposts = true
|
|
||||||
if (existing.withCrossposts) {
|
|
||||||
existing.crossposts = [...(existing.crossposts || []), post]
|
|
||||||
}
|
|
||||||
|
|
||||||
urlMap.set(post.post.url, existing)
|
|
||||||
} else {
|
|
||||||
urlMap.set(post.post.url, post)
|
|
||||||
results.push(post)
|
|
||||||
}
|
|
||||||
seenUrls.add(post.post.url)
|
|
||||||
})
|
|
||||||
|
|
||||||
return results
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
import { instance } from '$lib/instance.svelte'
|
import { profile } from '$lib/auth.svelte'
|
||||||
import { client } from '$lib/client/lemmy.svelte'
|
import { client } from '$lib/client/lemmy.svelte'
|
||||||
import { isImage, isVideo } from '$lib/ui/image'
|
|
||||||
import { canParseUrl, findClosestNumber } from '$lib/util.svelte'
|
|
||||||
import type { CommentView, PersonView, Post } from '$lib/client/types'
|
import type { CommentView, PersonView, Post } from '$lib/client/types'
|
||||||
|
import {
|
||||||
|
canParseUrl,
|
||||||
|
findClosestNumber,
|
||||||
|
isImage,
|
||||||
|
isVideo,
|
||||||
|
} from '$lib/util.svelte'
|
||||||
|
|
||||||
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||||
me.person.id == comment.creator.id
|
me.person.id == comment.creator.id
|
||||||
@@ -57,24 +61,23 @@ export const isYoutubeLink = (url?: string): RegExpMatchArray | null => {
|
|||||||
return url?.match?.(YOUTUBE_REGEX)
|
return url?.match?.(YOUTUBE_REGEX)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const postLink = (post: Post) =>
|
export function postLink(post: Post) {
|
||||||
`/post/${encodeURIComponent(instance.data)}/${post.id}`
|
return `/post/${encodeURIComponent(profile.current.instance)}/${post.id}`
|
||||||
|
}
|
||||||
|
|
||||||
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
||||||
export type IframeType = 'youtube' | 'video' | 'none'
|
export type IframeType = 'youtube' | 'video' | 'none'
|
||||||
|
|
||||||
export const mediaType = (url?: string): MediaType => {
|
export function mediaType(url?: string): MediaType {
|
||||||
if (url) {
|
if (!url) return 'none'
|
||||||
if (isImage(url)) return 'image'
|
if (isImage(url)) return 'image'
|
||||||
if (isVideo(url)) return 'iframe'
|
if (isVideo(url)) return 'iframe'
|
||||||
if (isYoutubeLink(url)) return 'iframe'
|
if (isYoutubeLink(url)) return 'iframe'
|
||||||
if (canParseUrl(url)) return 'embed'
|
if (canParseUrl(url)) return 'embed'
|
||||||
return 'none'
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'none'
|
return 'none'
|
||||||
}
|
}
|
||||||
export const iframeType = (url: string): IframeType => {
|
|
||||||
|
export function iframeType(url: string): IframeType {
|
||||||
if (isVideo(url)) return 'video'
|
if (isVideo(url)) return 'video'
|
||||||
if (isYoutubeLink(url)) return 'youtube'
|
if (isYoutubeLink(url)) return 'youtube'
|
||||||
return 'none'
|
return 'none'
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
export { default as Post } from './Post.svelte'
|
||||||
|
export { default as PostBody } from './PostBody.svelte'
|
||||||
|
export { default as PostItem } from './PostItem.svelte'
|
||||||
|
export { default as PostMeta } from './PostMeta.svelte'
|
||||||
|
export { default as PostVote } from './PostVote.svelte'
|
||||||
|
export { default as PostMedia } from './media/PostMedia.svelte'
|
||||||
|
export { default as PostMediaCompact } from './media/PostMediaCompact.svelte'
|
||||||
|
export { default as PostImage } from './media/PostImage.svelte'
|
||||||
|
export { default as PostIframe } from './media/PostIframe.svelte'
|
||||||
|
export { default as PostLink } from './link/PostLink.svelte'
|
||||||
|
export { default as VirtualFeed } from './feed/VirtualFeed.svelte'
|
||||||
|
export { default as PostFeed } from './feed/PostFeed.svelte'
|
||||||
|
export { default as PostForm } from './form/PostForm.svelte'
|
||||||
|
export { default as PostActions } from './actions/PostActions.svelte'
|
||||||
|
|
||||||
|
export {
|
||||||
|
type Tag,
|
||||||
|
parseTags,
|
||||||
|
textToTag,
|
||||||
|
default as PostsMeta,
|
||||||
|
} from './PostMeta.svelte'
|
||||||
|
|
||||||
|
export * from './helpers'
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
let { post, blur = false }: Props = $props()
|
let { post, blur = false }: Props = $props()
|
||||||
|
|
||||||
let imageLoaded: boolean | null = $state(null)
|
let imageLoaded: boolean | null = $state(null)
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
imageLoaded = false
|
imageLoaded = false
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
|
||||||
iframeType,
|
|
||||||
type MediaType,
|
|
||||||
} from '$lib/components/lemmy/post/helpers.js'
|
|
||||||
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
|
|
||||||
import { settings, type View } from '$lib/settings.svelte.js'
|
import { settings, type View } from '$lib/settings.svelte.js'
|
||||||
import type { Post } from '$lib/client/types'
|
import type { Post } from '$lib/client/types'
|
||||||
import PostIframe from './PostIframe.svelte'
|
import {
|
||||||
import PostImage from './PostImage.svelte'
|
PostImage,
|
||||||
|
PostIframe,
|
||||||
|
PostLink,
|
||||||
|
type MediaType,
|
||||||
|
iframeType,
|
||||||
|
} from '..'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
view?: View
|
view?: View
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import { bestImageURL, postLink, type MediaType } from '..'
|
||||||
bestImageURL,
|
|
||||||
postLink,
|
|
||||||
type MediaType,
|
|
||||||
} from '$lib/components/lemmy/post/helpers.js'
|
|
||||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { settings, type View } from '$lib/settings.svelte.js'
|
import { settings, type View } from '$lib/settings.svelte.js'
|
||||||
import type { Post } from '$lib/client/types'
|
import type { Post } from '$lib/client/types'
|
||||||
import { modal } from 'mono-svelte'
|
import { modal, Button } from 'mono-svelte'
|
||||||
import Button from 'mono-svelte/button/Button.svelte'
|
|
||||||
import {
|
import {
|
||||||
DocumentText,
|
DocumentText,
|
||||||
ExclamationTriangle,
|
ExclamationTriangle,
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
iframeType,
|
iframeType,
|
||||||
mediaType,
|
mediaType,
|
||||||
optimizeImageURL,
|
optimizeImageURL,
|
||||||
} from '$lib/components/lemmy/post/helpers'
|
PostIframe,
|
||||||
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
|
} from '$lib/components/lemmy/post'
|
||||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { getContext } from 'svelte'
|
import { getContext } from 'svelte'
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { site } from '$lib/client/lemmy.svelte'
|
import { site } from '$lib/client/lemmy.svelte'
|
||||||
import { settings } from '$lib/settings.svelte'
|
import { settings } from '$lib/settings.svelte'
|
||||||
import { theme } from '$lib/ui/colors.svelte'
|
import { theme } from '$lib/ui/theme/theme.svelte'
|
||||||
import {
|
import {
|
||||||
Badge,
|
Badge,
|
||||||
Button,
|
Button,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import { profile } from '$lib/auth.svelte'
|
import { profile } from '$lib/auth.svelte'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { resumables } from '$lib/lemmy/item'
|
import { resumables } from '$lib/lemmy/item'
|
||||||
import { theme } from '$lib/ui/colors.svelte'
|
import { theme } from '$lib/ui/theme/theme.svelte'
|
||||||
import { fuzzySearch } from '$lib/util.svelte'
|
import { fuzzySearch } from '$lib/util.svelte'
|
||||||
import { TextInput } from 'mono-svelte'
|
import { TextInput } from 'mono-svelte'
|
||||||
import { createEventDispatcher, onMount } from 'svelte'
|
import { createEventDispatcher, onMount } from 'svelte'
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { type ResumableItem } from '$lib/lemmy/item'
|
import { type ResumableItem } from '$lib/lemmy/item'
|
||||||
import { settings } from '$lib/settings.svelte'
|
import { settings } from '$lib/settings.svelte'
|
||||||
import { theme, type ThemeData } from '$lib/ui/colors.svelte'
|
import { theme, type ThemeData } from '$lib/ui/theme/theme.svelte'
|
||||||
import { fullCommunityName } from '$lib/util.svelte'
|
import { fullCommunityName } from '$lib/util.svelte'
|
||||||
import {
|
import {
|
||||||
ArrowRightOnRectangle,
|
ArrowRightOnRectangle,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { communityLink } from '$lib/lemmy/generic'
|
import { communityLink } from '$lib/lemmy/generic'
|
||||||
import { settings } from '$lib/settings.svelte.js'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
import { theme } from '$lib/ui/colors.svelte'
|
import { theme } from '$lib/ui/theme/theme.svelte'
|
||||||
import { Badge, Option, Select } from 'mono-svelte'
|
import { Badge, Option, Select } from 'mono-svelte'
|
||||||
import {
|
import {
|
||||||
ArrowLeftOnRectangle,
|
ArrowLeftOnRectangle,
|
||||||
|
|||||||
+22
-23
@@ -1,28 +1,27 @@
|
|||||||
import { profile, type ProfileInfo } from '$lib/auth.svelte'
|
import { profile, type ProfileInfo } from '$lib/auth.svelte'
|
||||||
import { getClient } from '$lib/client/lemmy.svelte'
|
import { client } from '$lib/client/lemmy.svelte'
|
||||||
import { trycatch } from '$lib/util.svelte'
|
|
||||||
import type { Community, MyUserInfo } from '$lib/client/types'
|
import type { Community, MyUserInfo } from '$lib/client/types'
|
||||||
|
|
||||||
// TODO obliterate this file
|
// TODO obliterate this file
|
||||||
|
export async function blockUser(block: boolean, id: number) {
|
||||||
export const blockUser = async (block: boolean, id: number) => {
|
|
||||||
const auth = profile.current?.jwt
|
const auth = profile.current?.jwt
|
||||||
|
|
||||||
if (!auth) throw new Error('Unauthorized')
|
if (!auth) throw new Error('Unauthorized')
|
||||||
|
|
||||||
await getClient().blockPerson({
|
await client().blockPerson({
|
||||||
block: block,
|
block: block,
|
||||||
person_id: id,
|
person_id: id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isBlocked = (me: MyUserInfo, user: number) =>
|
export function isBlocked(me: MyUserInfo, user: number) {
|
||||||
me.person_blocks.map((b) => b.target.id).includes(user)
|
return me.person_blocks.map((b) => b.target.id).includes(user)
|
||||||
|
}
|
||||||
|
|
||||||
export const addSubscription = (
|
export function addSubscription(
|
||||||
community: Community,
|
community: Community,
|
||||||
subscribe: boolean = true,
|
subscribe: boolean = true,
|
||||||
) => {
|
) {
|
||||||
const index = profile.current.user?.follows
|
const index = profile.current.user?.follows
|
||||||
.map((f) => f.community.id)
|
.map((f) => f.community.id)
|
||||||
.indexOf(community.id)
|
.indexOf(community.id)
|
||||||
@@ -37,19 +36,19 @@ export const addSubscription = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addAdmin = async (handle: string, added: boolean) =>
|
export async function addAdmin(handle: string, added: boolean) {
|
||||||
trycatch(async () => {
|
const user = await client().resolveObject({
|
||||||
const user = await getClient().resolveObject({
|
q: handle,
|
||||||
q: handle,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!user.person) throw new Error('No user found')
|
|
||||||
|
|
||||||
return await getClient().addAdmin({
|
|
||||||
added: added,
|
|
||||||
person_id: user.person.person.id,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const hasFavorite = (profile: ProfileInfo, id: number): boolean =>
|
if (!user.person) throw new Error('No user found')
|
||||||
profile.favorites?.map((i) => i.id).includes(id) ?? false
|
|
||||||
|
return await client().addAdmin({
|
||||||
|
added: added,
|
||||||
|
person_id: user.person.person.id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasFavorite(profile: ProfileInfo, id: number): boolean {
|
||||||
|
return profile.favorites?.map((i) => i.id).includes(id) ?? false
|
||||||
|
}
|
||||||
+10
-12
@@ -2,18 +2,16 @@ import { browser } from '$app/environment'
|
|||||||
import type { Community } from '$lib/client/types'
|
import type { Community } from '$lib/client/types'
|
||||||
|
|
||||||
interface SessionStorage {
|
interface SessionStorage {
|
||||||
lastSeenCommunity: Community | undefined
|
lastSeenCommunity?: Community
|
||||||
postDraft:
|
postDraft?: {
|
||||||
| {
|
community: Community | null
|
||||||
community: Community | null
|
title: string
|
||||||
title: string
|
body: string
|
||||||
body: string
|
image: FileList | null
|
||||||
image: FileList | null
|
url?: string
|
||||||
url: string | undefined
|
nsfw: boolean
|
||||||
nsfw: boolean
|
loading: boolean
|
||||||
loading: boolean
|
}
|
||||||
}
|
|
||||||
| undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setSessionStorage = (
|
export const setSessionStorage = (
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
export const isImage = (url: string | undefined) => {
|
|
||||||
try {
|
|
||||||
if (!url) return false
|
|
||||||
|
|
||||||
return /\.(jpeg|jpg|gif|png|svg|bmp|webp|avif)/i.test(url)
|
|
||||||
} catch {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const isVideo = (url: string | undefined) => {
|
|
||||||
try {
|
|
||||||
if (!url) return false
|
|
||||||
|
|
||||||
return /\.(mp4|mov|webm|mkv|avi)/i.test(url)
|
|
||||||
} catch {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { env } from '$env/dynamic/public'
|
import { env } from '$env/dynamic/public'
|
||||||
import type { Theme, ThemeColors } from './colors.svelte'
|
import type { Theme, ThemeColors } from './theme.svelte'
|
||||||
|
|
||||||
const PHOTON_DEFAULT = {
|
const PHOTON_DEFAULT = {
|
||||||
slate: {
|
slate: {
|
||||||
File renamed without changes.
+20
-12
@@ -92,18 +92,6 @@ export function moveItem<T>(
|
|||||||
return newArray
|
return newArray
|
||||||
}
|
}
|
||||||
|
|
||||||
type Maybe<T> = T | undefined | void | null
|
|
||||||
export const trycatch = <T>(func: () => T): Maybe<T> => {
|
|
||||||
try {
|
|
||||||
return func()
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
content: errorMessage(err as string),
|
|
||||||
type: 'error',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const removeItem = <T>(array: T[], predicate: (item: T) => boolean) => {
|
export const removeItem = <T>(array: T[], predicate: (item: T) => boolean) => {
|
||||||
array.splice(array.findIndex(predicate), 1)
|
array.splice(array.findIndex(predicate), 1)
|
||||||
}
|
}
|
||||||
@@ -206,3 +194,23 @@ export class ReactiveState<T> {
|
|||||||
this.value = initialValue as NonNullable<T>
|
this.value = initialValue as NonNullable<T>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const isImage = (url: string | undefined) => {
|
||||||
|
try {
|
||||||
|
if (!url) return false
|
||||||
|
|
||||||
|
return /\.(jpeg|jpg|gif|png|svg|bmp|webp|avif)/i.test(url)
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isVideo = (url: string | undefined) => {
|
||||||
|
try {
|
||||||
|
if (!url) return false
|
||||||
|
|
||||||
|
return /\.(mp4|mov|webm|mkv|avi)/i.test(url)
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,8 +11,12 @@
|
|||||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||||
import { site } from '$lib/client/lemmy.svelte'
|
import { site } from '$lib/client/lemmy.svelte'
|
||||||
import { settings } from '$lib/settings.svelte.js'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
import { inDarkColorScheme, rgbToHex, theme } from '$lib/ui/colors.svelte.js'
|
import {
|
||||||
import { getDefaultColors } from '$lib/ui/presets'
|
inDarkColorScheme,
|
||||||
|
rgbToHex,
|
||||||
|
theme,
|
||||||
|
} from '$lib/ui/theme/theme.svelte.js'
|
||||||
|
import { getDefaultColors } from '$lib/ui/theme/presets'
|
||||||
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
|
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
|
||||||
import nProgress from 'nprogress'
|
import nProgress from 'nprogress'
|
||||||
import 'nprogress/nprogress.css'
|
import 'nprogress/nprogress.css'
|
||||||
|
|||||||
@@ -4,12 +4,11 @@
|
|||||||
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
||||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||||
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
||||||
import PostFeed from '$lib/components/lemmy/post/feed/PostFeed.svelte'
|
import { PostFeed, VirtualFeed } from '$lib/components/lemmy/post'
|
||||||
import VirtualFeed from '$lib/components/lemmy/post/feed/VirtualFeed.svelte'
|
|
||||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.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 Pageination from '$lib/components/ui/layout/Pageination.svelte'
|
import Pageination from '$lib/components/ui/layout/Pageination.svelte'
|
||||||
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
import { t } from '$lib/i18n/translations.js'
|
import { t } from '$lib/i18n/translations.js'
|
||||||
import { postFeeds } from '$lib/lemmy/postfeed.svelte.js'
|
import { postFeeds } from '$lib/lemmy/postfeed.svelte.js'
|
||||||
import { settings, SSR_ENABLED } from '$lib/settings.svelte.js'
|
import { settings, SSR_ENABLED } from '$lib/settings.svelte.js'
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
import { Spinner } from 'mono-svelte'
|
import { Spinner } from 'mono-svelte'
|
||||||
import type { ResolveObjectResponse } from '$lib/client/types'
|
import type { ResolveObjectResponse } from '$lib/client/types'
|
||||||
import UserItem from '$lib/components/lemmy/user/UserItem.svelte'
|
import UserItem from '$lib/components/lemmy/user/UserItem.svelte'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
|
||||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||||
import { CommunityItem } from '$lib/components/lemmy/community'
|
import { CommunityItem } from '$lib/components/lemmy/community'
|
||||||
|
import { PostItem } from '$lib/components/lemmy/post'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
data: {
|
data: {
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
{:else if object.person}
|
{:else if object.person}
|
||||||
<UserItem user={object.person} />
|
<UserItem user={object.person} />
|
||||||
{:else if object.post}
|
{:else if object.post}
|
||||||
<Post post={object.post} />
|
<PostItem post={object.post} />
|
||||||
{:else if object.comment}
|
{:else if object.comment}
|
||||||
<CommentItem comment={object.comment} />
|
<CommentItem comment={object.comment} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
import { preventDefault } from 'svelte/legacy'
|
import { preventDefault } from 'svelte/legacy'
|
||||||
|
|
||||||
import { profile } from '$lib/auth.svelte.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
|
import { client, getClient } from '$lib/client/lemmy.svelte'
|
||||||
|
import type { Instance } from '$lib/client/types'
|
||||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import { publishedToDate } from '$lib/components/util/date.js'
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
import { t } from '$lib/i18n/translations.js'
|
import { t } from '$lib/i18n/translations.js'
|
||||||
import { getClient } from '$lib/client/lemmy.svelte'
|
import { errorMessage } from '$lib/lemmy/error.js'
|
||||||
import { trycatch } from '$lib/util.svelte.js'
|
|
||||||
import type { Instance } from '$lib/client/types'
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
FileInput,
|
FileInput,
|
||||||
@@ -40,9 +40,9 @@
|
|||||||
}),
|
}),
|
||||||
saving = $state(false)
|
saving = $state(false)
|
||||||
|
|
||||||
const moderateInstance = async (instance: string, blocked: boolean) => {
|
async function moderateInstance(instance: string, blocked: boolean) {
|
||||||
if (instance == '') return
|
if (instance == '') return
|
||||||
await trycatch(async () => {
|
try {
|
||||||
if (
|
if (
|
||||||
!profile.current?.jwt ||
|
!profile.current?.jwt ||
|
||||||
!data.instances.value?.blocked ||
|
!data.instances.value?.blocked ||
|
||||||
@@ -53,9 +53,9 @@
|
|||||||
if (blocked) blockInstance.loading = true
|
if (blocked) blockInstance.loading = true
|
||||||
else allowInstance.loading = true
|
else allowInstance.loading = true
|
||||||
|
|
||||||
const blockedInstances = data.instances.value.blocked.map(i => i.domain)
|
const blockedInstances = data.instances.value.blocked.map((i) => i.domain)
|
||||||
|
|
||||||
const allowedInstances = data.instances.value.allowed.map(i => i.domain)
|
const allowedInstances = data.instances.value.allowed.map((i) => i.domain)
|
||||||
|
|
||||||
if (blocked) blockedInstances.push(instance)
|
if (blocked) blockedInstances.push(instance)
|
||||||
if (!blocked) allowedInstances.push(instance)
|
if (!blocked) allowedInstances.push(instance)
|
||||||
@@ -71,32 +71,41 @@
|
|||||||
data.instances.value = instances.federated_instances
|
data.instances.value = instances.federated_instances
|
||||||
|
|
||||||
blockInstance.instance = ''
|
blockInstance.instance = ''
|
||||||
})
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
content: errorMessage(err as string),
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
blockInstance.loading = false
|
blockInstance.loading = false
|
||||||
allowInstance.loading = false
|
allowInstance.loading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const save = async () => {
|
async function save() {
|
||||||
const res = await trycatch(async () => {
|
try {
|
||||||
if (!profile.current?.jwt || !data.instances.value?.blocked) return
|
if (!profile.current?.jwt || !data.instances.value?.blocked) return
|
||||||
|
|
||||||
saving = true
|
saving = true
|
||||||
|
|
||||||
const blockedInstances = data.instances.value.blocked.map(i => i.domain)
|
const blockedInstances = data.instances.value.blocked.map((i) => i.domain)
|
||||||
const allowedInstances = data.instances.value.allowed?.map(i => i.domain)
|
const allowedInstances = data.instances.value.allowed?.map(
|
||||||
|
(i) => i.domain,
|
||||||
|
)
|
||||||
|
|
||||||
return await getClient().editSite({
|
await client().editSite({
|
||||||
allowed_instances: allowedInstances,
|
allowed_instances: allowedInstances,
|
||||||
blocked_instances: blockedInstances,
|
blocked_instances: blockedInstances,
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
if (res) {
|
|
||||||
toast({
|
toast({
|
||||||
content: $t('toast.updatedSite'),
|
content: $t('toast.updatedSite'),
|
||||||
type: 'success',
|
type: 'success',
|
||||||
})
|
})
|
||||||
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
content: errorMessage(err as string),
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
saving = false
|
saving = false
|
||||||
}
|
}
|
||||||
@@ -108,7 +117,7 @@
|
|||||||
|
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
|
|
||||||
reader.onload = e => {
|
reader.onload = (e) => {
|
||||||
if (!data.instances.value?.blocked) throw new Error('Missing instance')
|
if (!data.instances.value?.blocked) throw new Error('Missing instance')
|
||||||
const content = e.target?.result
|
const content = e.target?.result
|
||||||
if (!content) toast({ content: $t('toast.failCSV'), type: 'warning' })
|
if (!content) toast({ content: $t('toast.failCSV'), type: 'warning' })
|
||||||
@@ -223,7 +232,7 @@
|
|||||||
|
|
||||||
data.instances.value.blocked =
|
data.instances.value.blocked =
|
||||||
data.instances.value?.blocked.filter(
|
data.instances.value?.blocked.filter(
|
||||||
i => i.id != instance.id,
|
(i) => i.id != instance.id,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -307,7 +316,7 @@
|
|||||||
|
|
||||||
data.instances.value.allowed =
|
data.instances.value.allowed =
|
||||||
data.instances.value?.allowed.filter(
|
data.instances.value?.allowed.filter(
|
||||||
i => i.id != instance.id,
|
(i) => i.id != instance.id,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
import CommunityHeader from '$lib/components/lemmy/community/CommunityHeader.svelte'
|
import CommunityHeader from '$lib/components/lemmy/community/CommunityHeader.svelte'
|
||||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||||
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
||||||
import PostFeed from '$lib/components/lemmy/post/feed/PostFeed.svelte'
|
|
||||||
import VirtualFeed from '$lib/components/lemmy/post/feed/VirtualFeed.svelte'
|
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
import Pageination from '$lib/components/ui/layout/Pageination.svelte'
|
import Pageination from '$lib/components/ui/layout/Pageination.svelte'
|
||||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||||
@@ -19,6 +17,7 @@
|
|||||||
import { Badge, Button, Modal, Note } from 'mono-svelte'
|
import { Badge, Button, Modal, Note } from 'mono-svelte'
|
||||||
import { onDestroy, onMount } from 'svelte'
|
import { onDestroy, onMount } from 'svelte'
|
||||||
import { ArrowRight, ChartBar, Icon, Plus, XMark } from 'svelte-hero-icons'
|
import { ArrowRight, ChartBar, Icon, Plus, XMark } from 'svelte-hero-icons'
|
||||||
|
import { PostFeed, VirtualFeed } from '$lib/components/lemmy/post'
|
||||||
|
|
||||||
let { data } = $props()
|
let { data } = $props()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import PostForm from '$lib/components/lemmy/post/form/PostForm.svelte'
|
import { PostForm } from '$lib/components/lemmy/post'
|
||||||
import { t } from '$lib/i18n/translations.js'
|
import { t } from '$lib/i18n/translations.js'
|
||||||
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
|
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
|
||||||
import { onDestroy } from 'svelte'
|
import { onDestroy } from 'svelte'
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { getClient } from '$lib/client/lemmy.svelte'
|
import { getClient } from '$lib/client/lemmy.svelte'
|
||||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||||
import PrivateMessage from '$lib/components/lemmy/inbox/PrivateMessage.svelte'
|
import PrivateMessage from '$lib/components/lemmy/inbox/PrivateMessage.svelte'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import { PostItem } from '$lib/components/lemmy/post'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
@@ -189,7 +189,7 @@
|
|||||||
{#if item.type == 'comment'}
|
{#if item.type == 'comment'}
|
||||||
<CommentItem comment={item.item} class="p-0!" />
|
<CommentItem comment={item.item} class="p-0!" />
|
||||||
{:else if item.type == 'post'}
|
{:else if item.type == 'post'}
|
||||||
<Post hideCommunity post={item.item} class="p-0!" />
|
<PostItem post={item.item} />
|
||||||
{:else if item.type == 'message'}
|
{:else if item.type == 'message'}
|
||||||
<PrivateMessage
|
<PrivateMessage
|
||||||
message={{
|
message={{
|
||||||
|
|||||||
@@ -27,8 +27,8 @@
|
|||||||
import { client } from '$lib/client/lemmy.svelte'
|
import { client } from '$lib/client/lemmy.svelte'
|
||||||
import Spinner from 'mono-svelte/loader/Spinner.svelte'
|
import Spinner from 'mono-svelte/loader/Spinner.svelte'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import { postLink } from '$lib/components/lemmy/post/helpers'
|
|
||||||
import { CommunityLink } from '$lib/components/lemmy/community'
|
import { CommunityLink } from '$lib/components/lemmy/community'
|
||||||
|
import { postLink } from '$lib/components/lemmy/post'
|
||||||
|
|
||||||
let { data = $bindable() } = $props()
|
let { data = $bindable() } = $props()
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/state'
|
import { page } from '$app/state'
|
||||||
import { profile } from '$lib/auth.svelte.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import PostActions from '$lib/components/lemmy/post/actions/PostActions.svelte'
|
|
||||||
import { mediaType, postLink } from '$lib/components/lemmy/post/helpers.js'
|
|
||||||
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
|
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
|
||||||
import PostMeta, {
|
|
||||||
parseTags,
|
|
||||||
} from '$lib/components/lemmy/post/PostMeta.svelte'
|
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||||
@@ -20,7 +13,6 @@
|
|||||||
import { postFeeds } from '$lib/lemmy/postfeed.svelte'
|
import { postFeeds } from '$lib/lemmy/postfeed.svelte'
|
||||||
import { ReactiveState } from '$lib/util.svelte'
|
import { ReactiveState } from '$lib/util.svelte'
|
||||||
import { settings } from '$lib/settings.svelte.js'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
import { isImage } from '$lib/ui/image.js'
|
|
||||||
import { Button, toast } from 'mono-svelte'
|
import { Button, toast } from 'mono-svelte'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import {
|
import {
|
||||||
@@ -32,6 +24,7 @@
|
|||||||
import { expoOut } from 'svelte/easing'
|
import { expoOut } from 'svelte/easing'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
import CommentProvider from './CommentProvider.svelte'
|
import CommentProvider from './CommentProvider.svelte'
|
||||||
|
import { mediaType, parseTags, Post, PostActions, postLink, PostMedia, PostMeta } from '$lib/components/lemmy/post'
|
||||||
|
|
||||||
let { data } = $props()
|
let { data } = $props()
|
||||||
|
|
||||||
@@ -111,7 +104,7 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<meta property="og:url" content={page.url.toString()} />
|
<meta property="og:url" content={page.url.toString()} />
|
||||||
{#if isImage(data.post.value.post_view.post.url)}
|
{#if mediaType(data.post.value.post_view.post.url) == 'image'}
|
||||||
<meta property="og:image" content={data.post.value.post_view.post.url} />
|
<meta property="og:image" content={data.post.value.post_view.post.url} />
|
||||||
<meta
|
<meta
|
||||||
property="twitter:card"
|
property="twitter:card"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
import PostFeed from '$lib/components/lemmy/post/feed/PostFeed.svelte'
|
import { PostFeed, VirtualFeed } from '$lib/components/lemmy/post'
|
||||||
import VirtualFeed from '$lib/components/lemmy/post/feed/VirtualFeed.svelte'
|
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
import { t } from '$lib/i18n/translations.js'
|
import { t } from '$lib/i18n/translations.js'
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/state'
|
import { page } from '$app/state'
|
||||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||||
import PostItem from '$lib/components/lemmy/post/PostItem.svelte'
|
|
||||||
import Fixate from '$lib/components/ui/generic/Fixate.svelte'
|
import Fixate from '$lib/components/ui/generic/Fixate.svelte'
|
||||||
import CommonList from '$lib/components/ui/layout/CommonList.svelte'
|
import CommonList from '$lib/components/ui/layout/CommonList.svelte'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
@@ -20,6 +19,7 @@
|
|||||||
Icon,
|
Icon,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
|
import { PostItem } from '$lib/components/lemmy/post'
|
||||||
|
|
||||||
let { data } = $props()
|
let { data } = $props()
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||||
import { CommunityItem } from '$lib/components/lemmy/community'
|
import { CommunityItem } from '$lib/components/lemmy/community'
|
||||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||||
import PostItem from '$lib/components/lemmy/post/PostItem.svelte'
|
import { PostItem } from '$lib/components/lemmy/post'
|
||||||
import UserItem from '$lib/components/lemmy/user/UserItem.svelte'
|
import UserItem from '$lib/components/lemmy/user/UserItem.svelte'
|
||||||
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'
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { theme as themeData } from '$lib/ui/colors.svelte'
|
import { theme as themeData } from '$lib/ui/theme/theme.svelte'
|
||||||
import { getDefaultColors } from '$lib/ui/presets'
|
import { getDefaultColors } from '$lib/ui/theme/presets'
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Material,
|
Material,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { hexToRgb } from '$lib/ui/colors.svelte'
|
import { hexToRgb } from '$lib/ui/theme/theme.svelte'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
value: string
|
value: string
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { theme as themeData, type Theme } from '$lib/ui/colors.svelte'
|
import { theme as themeData, type Theme } from '$lib/ui/theme/theme.svelte'
|
||||||
import { action, Button, Material, modal, TextInput } from 'mono-svelte'
|
import { action, Button, Material, modal, TextInput } from 'mono-svelte'
|
||||||
import { CheckCircle, Icon, Trash } from 'svelte-hero-icons'
|
import { CheckCircle, Icon, Trash } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
|
||||||
import { page } from '$app/state'
|
import { page } from '$app/state'
|
||||||
import { profile } from '$lib/auth.svelte.js'
|
|
||||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||||
import ItemList from '$lib/components/lemmy/generic/ItemList.svelte'
|
import ItemList from '$lib/components/lemmy/generic/ItemList.svelte'
|
||||||
import { ban, isAdmin } from '$lib/components/lemmy/moderation/moderation.js'
|
import { PostItem } from '$lib/components/lemmy/post'
|
||||||
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
|
||||||
import PostItem from '$lib/components/lemmy/post/PostItem.svelte'
|
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||||
import CommonList from '$lib/components/ui/layout/CommonList.svelte'
|
import { CommonList, Header, Pageination } from '$lib/components/ui/layout'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
|
||||||
import Pageination from '$lib/components/ui/layout/Pageination.svelte'
|
|
||||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||||
import { publishedToDate } from '$lib/components/util/date.js'
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte'
|
import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte'
|
||||||
import { t } from '$lib/i18n/translations.js'
|
import { t } from '$lib/i18n/translations.js'
|
||||||
import { client, getClient } from '$lib/client/lemmy.svelte'
|
|
||||||
import { communityLink } from '$lib/lemmy/generic.js'
|
import { communityLink } from '$lib/lemmy/generic.js'
|
||||||
import { isCommentView } from '$lib/lemmy/item.js'
|
import { isCommentView } from '$lib/lemmy/item.js'
|
||||||
import { isBlocked } from '$lib/lemmy/user.js'
|
import { Option, Select } from 'mono-svelte'
|
||||||
import {
|
import { AdjustmentsHorizontal, Icon, PencilSquare } from 'svelte-hero-icons'
|
||||||
Button,
|
|
||||||
Menu,
|
|
||||||
MenuButton,
|
|
||||||
Modal,
|
|
||||||
Option,
|
|
||||||
removeToast,
|
|
||||||
Select,
|
|
||||||
toast,
|
|
||||||
} from 'mono-svelte'
|
|
||||||
import {
|
|
||||||
AdjustmentsHorizontal,
|
|
||||||
AtSymbol,
|
|
||||||
EllipsisHorizontal,
|
|
||||||
Envelope,
|
|
||||||
Fire,
|
|
||||||
Icon,
|
|
||||||
Newspaper,
|
|
||||||
NoSymbol,
|
|
||||||
PencilSquare,
|
|
||||||
ShieldExclamation,
|
|
||||||
} from 'svelte-hero-icons'
|
|
||||||
import type { PageData } from './$types'
|
import type { PageData } from './$types'
|
||||||
|
import UserActions from './UserActions.svelte'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
data: PageData
|
data: PageData
|
||||||
@@ -54,103 +27,12 @@
|
|||||||
let { data, inline = false }: Props = $props()
|
let { data, inline = false }: Props = $props()
|
||||||
|
|
||||||
let sortForm = $state<HTMLFormElement>()
|
let sortForm = $state<HTMLFormElement>()
|
||||||
|
|
||||||
async function blockUser(block: number) {
|
|
||||||
if (!profile.current?.user || !profile.current?.jwt)
|
|
||||||
throw new Error('Unauthenticated')
|
|
||||||
|
|
||||||
try {
|
|
||||||
const blocked = isBlocked(profile.current.user, block)
|
|
||||||
|
|
||||||
await getClient().blockPerson({
|
|
||||||
block: !blocked,
|
|
||||||
person_id: block,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (blocked) {
|
|
||||||
const index = profile.current.user.person_blocks
|
|
||||||
.map(p => p.target.id)
|
|
||||||
.indexOf(block)
|
|
||||||
profile.current.user.person_blocks.splice(index, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
toast({
|
|
||||||
content: blocked ? $t('toast.unblockUser') : $t('toast.blockUser'),
|
|
||||||
type: 'success',
|
|
||||||
})
|
|
||||||
|
|
||||||
goto(page.url, {
|
|
||||||
invalidateAll: true,
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
content: err as string,
|
|
||||||
type: 'error',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let purgingUser = $state(false)
|
|
||||||
let purgeEnabled = $state(false)
|
|
||||||
$effect(() => {
|
|
||||||
if (purgingUser) {
|
|
||||||
purgeEnabled = false
|
|
||||||
setTimeout(() => {
|
|
||||||
purgeEnabled = true
|
|
||||||
}, 3000)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
async function purgeUser() {
|
|
||||||
purgingUser = false
|
|
||||||
const purgeToast = toast({ content: '', loading: true })
|
|
||||||
|
|
||||||
try {
|
|
||||||
await client().purgePerson({
|
|
||||||
person_id: data.person_view.value.person.id,
|
|
||||||
})
|
|
||||||
removeToast(purgeToast)
|
|
||||||
toast({ content: $t('toast.purgeUser'), type: 'success' })
|
|
||||||
} catch (e) {
|
|
||||||
toast({ content: e as string, type: 'error' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>{data.person_view.value.person.name}</title>
|
<title>{data.person_view.value.person.name}</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
{#if purgingUser}
|
|
||||||
<Modal bind:open={purgingUser}>
|
|
||||||
{#snippet customTitle()}
|
|
||||||
Purging User
|
|
||||||
{/snippet}
|
|
||||||
<p>
|
|
||||||
Purging user <span class="font-bold">
|
|
||||||
{data.person_view.value.person.name}
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Are you sure you want to do this? (The button will enable in 3 seconds.)
|
|
||||||
</p>
|
|
||||||
<div class="flex flex-row gap-2">
|
|
||||||
<Button size="lg" onclick={() => (purgingUser = false)} class="flex-1">
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="lg"
|
|
||||||
color="danger"
|
|
||||||
onclick={purgeUser}
|
|
||||||
disabled={!purgeEnabled}
|
|
||||||
class="flex-1"
|
|
||||||
>
|
|
||||||
Purge
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</Modal>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="flex flex-col gap-4 max-w-full w-full">
|
<div class="flex flex-col gap-4 max-w-full w-full">
|
||||||
{#if !inline}
|
{#if !inline}
|
||||||
<Header pageHeader class="tracking-normal!">
|
<Header pageHeader class="tracking-normal!">
|
||||||
@@ -201,7 +83,7 @@
|
|||||||
/>
|
/>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
<ItemList
|
<ItemList
|
||||||
items={data.moderates.value.map(m => ({
|
items={data.moderates.value.map((m) => ({
|
||||||
id: m.community.id,
|
id: m.community.id,
|
||||||
name: m.community.title,
|
name: m.community.title,
|
||||||
url: communityLink(m.community),
|
url: communityLink(m.community),
|
||||||
@@ -212,97 +94,7 @@
|
|||||||
</Expandable>
|
</Expandable>
|
||||||
{/if}
|
{/if}
|
||||||
{#snippet actions()}
|
{#snippet actions()}
|
||||||
{#if profile.current?.user && profile.current.jwt && data.person_view.value.person.id != profile.current.user.local_user_view.person.id}
|
<UserActions person={data.person_view.value} />
|
||||||
<div class="flex items-center gap-2 w-full flex-wrap">
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
rounding="pill"
|
|
||||||
color="primary"
|
|
||||||
href="/inbox/messages/{data.person_view.value.person.id}"
|
|
||||||
>
|
|
||||||
{#snippet prefix()}
|
|
||||||
<Icon micro size="16" src={Envelope} />
|
|
||||||
{/snippet}
|
|
||||||
{$t('content.message')}
|
|
||||||
</Button>
|
|
||||||
{#if data.person_view.value.person.matrix_user_id}
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
rounding="pill"
|
|
||||||
color="secondary"
|
|
||||||
href="https://matrix.to/#/{data.person_view.value.person
|
|
||||||
.matrix_user_id}"
|
|
||||||
>
|
|
||||||
{#snippet prefix()}
|
|
||||||
<Icon solid size="16" src={AtSymbol} />
|
|
||||||
{/snippet}
|
|
||||||
{$t('form.profile.matrix')}
|
|
||||||
</Button>
|
|
||||||
{/if}
|
|
||||||
{#if isAdmin(profile.current?.user)}
|
|
||||||
<Menu class="ml-auto" placement="bottom-end">
|
|
||||||
{#snippet target(attachment)}
|
|
||||||
<Button {@attach attachment} size="sm" rounding="pill">
|
|
||||||
<ShieldIcon width={16} filled />
|
|
||||||
{$t('moderation.label')}
|
|
||||||
</Button>
|
|
||||||
{/snippet}
|
|
||||||
<MenuButton
|
|
||||||
href="/modlog?user={data.person_view.value.person.id}"
|
|
||||||
color="success-subtle"
|
|
||||||
>
|
|
||||||
<Icon src={Newspaper} size="16" micro />
|
|
||||||
{$t('moderation.modlog.user')}
|
|
||||||
</MenuButton>
|
|
||||||
<MenuButton
|
|
||||||
color="danger-subtle"
|
|
||||||
onclick={() =>
|
|
||||||
ban(
|
|
||||||
data.person_view.value.person.banned,
|
|
||||||
data.person_view.value.person,
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{#snippet prefix()}
|
|
||||||
<Icon mini size="16" src={ShieldExclamation} />
|
|
||||||
{/snippet}
|
|
||||||
{data.person_view.value.person.banned ? 'Unban' : 'Ban'}
|
|
||||||
</MenuButton>
|
|
||||||
<MenuButton
|
|
||||||
color="danger-subtle"
|
|
||||||
onclick={() => (purgingUser = !purgingUser)}
|
|
||||||
>
|
|
||||||
{#snippet prefix()}
|
|
||||||
<Icon mini size="16" src={Fire} />
|
|
||||||
{/snippet}
|
|
||||||
Purge
|
|
||||||
</MenuButton>
|
|
||||||
</Menu>
|
|
||||||
{/if}
|
|
||||||
<Menu placement="bottom-end">
|
|
||||||
{#snippet target(attachment)}
|
|
||||||
<Button {@attach attachment} size="custom" class="h-8 w-8" rounding="pill">
|
|
||||||
{#snippet prefix()}
|
|
||||||
<Icon src={EllipsisHorizontal} size="16" mini />
|
|
||||||
{/snippet}
|
|
||||||
</Button>
|
|
||||||
{/snippet}
|
|
||||||
<MenuButton
|
|
||||||
color="danger-subtle"
|
|
||||||
onclick={() => blockUser(data.person_view.value.person.id)}
|
|
||||||
>
|
|
||||||
{#snippet prefix()}
|
|
||||||
<Icon mini size="16" src={NoSymbol} />
|
|
||||||
{/snippet}
|
|
||||||
{isBlocked(
|
|
||||||
profile.current.user,
|
|
||||||
data.person_view.value.person.id,
|
|
||||||
)
|
|
||||||
? 'Unblock'
|
|
||||||
: 'Block'}
|
|
||||||
</MenuButton>
|
|
||||||
</Menu>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</EntityHeader>
|
</EntityHeader>
|
||||||
</div>
|
</div>
|
||||||
@@ -358,6 +150,6 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<Pageination
|
<Pageination
|
||||||
bind:page={data.filters.value.page}
|
bind:page={data.filters.value.page}
|
||||||
href={page => `?page=${page}`}
|
href={(page) => `?page=${page}`}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { profile } from '$lib/auth.svelte'
|
||||||
|
import { client } from '$lib/client/lemmy.svelte'
|
||||||
|
import type { PersonView } from '$lib/client/types'
|
||||||
|
import { ban, isAdmin } from '$lib/components/lemmy/moderation/moderation'
|
||||||
|
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
||||||
|
import { t } from '$lib/i18n/translations'
|
||||||
|
import { blockUser, isBlocked } from '$lib/lemmy/user'
|
||||||
|
import { Button, Menu, MenuButton, Modal, removeToast, toast } from 'mono-svelte'
|
||||||
|
import { AtSymbol, EllipsisHorizontal, Envelope, Fire, Icon, Newspaper, NoSymbol, ShieldExclamation } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
let { person }: { person: PersonView } = $props()
|
||||||
|
|
||||||
|
let purgingUser = $state(false)
|
||||||
|
|
||||||
|
async function purgeUser() {
|
||||||
|
purgingUser = false
|
||||||
|
const purgeToast = toast({ content: '', loading: true })
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client().purgePerson({
|
||||||
|
person_id: person.person.id,
|
||||||
|
})
|
||||||
|
removeToast(purgeToast)
|
||||||
|
toast({ content: $t('toast.purgeUser'), type: 'success' })
|
||||||
|
} catch (e) {
|
||||||
|
toast({ content: e as string, type: 'error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{#if purgingUser}
|
||||||
|
<Modal bind:open={purgingUser}>
|
||||||
|
{#snippet customTitle()}
|
||||||
|
Purging User
|
||||||
|
{/snippet}
|
||||||
|
<p>
|
||||||
|
Purging user <span class="font-bold">
|
||||||
|
{person.person.name}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Are you sure you want to do this?
|
||||||
|
</p>
|
||||||
|
<div class="flex flex-row gap-2">
|
||||||
|
<Button size="lg" onclick={() => (purgingUser = false)} class="flex-1">
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
color="danger"
|
||||||
|
onclick={purgeUser}
|
||||||
|
class="flex-1"
|
||||||
|
>
|
||||||
|
Purge
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if profile.current?.user && profile.current.jwt && person.person.id != profile.current.user.local_user_view.person.id}
|
||||||
|
<div class="flex items-center gap-2 w-full flex-wrap">
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
rounding="pill"
|
||||||
|
color="primary"
|
||||||
|
href="/inbox/messages/{person.person.id}"
|
||||||
|
>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon micro size="16" src={Envelope} />
|
||||||
|
{/snippet}
|
||||||
|
{$t('content.message')}
|
||||||
|
</Button>
|
||||||
|
{#if person.person.matrix_user_id}
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
rounding="pill"
|
||||||
|
color="secondary"
|
||||||
|
href="https://matrix.to/#/{person.person.matrix_user_id}"
|
||||||
|
>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon solid size="16" src={AtSymbol} />
|
||||||
|
{/snippet}
|
||||||
|
{$t('form.profile.matrix')}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
{#if isAdmin(profile.current?.user)}
|
||||||
|
<Menu class="ml-auto" placement="bottom-end">
|
||||||
|
{#snippet target(attachment)}
|
||||||
|
<Button {@attach attachment} size="sm" rounding="pill">
|
||||||
|
<ShieldIcon width={16} filled />
|
||||||
|
{$t('moderation.label')}
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
<MenuButton
|
||||||
|
href="/modlog?user={person.person.id}"
|
||||||
|
color="success-subtle"
|
||||||
|
>
|
||||||
|
<Icon src={Newspaper} size="16" micro />
|
||||||
|
{$t('moderation.modlog.user')}
|
||||||
|
</MenuButton>
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
onclick={() => ban(person.person.banned, person.person)}
|
||||||
|
>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon mini size="16" src={ShieldExclamation} />
|
||||||
|
{/snippet}
|
||||||
|
{person.person.banned ? 'Unban' : 'Ban'}
|
||||||
|
</MenuButton>
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
onclick={() => (purgingUser = !purgingUser)}
|
||||||
|
>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon mini size="16" src={Fire} />
|
||||||
|
{/snippet}
|
||||||
|
Purge
|
||||||
|
</MenuButton>
|
||||||
|
</Menu>
|
||||||
|
{/if}
|
||||||
|
<Menu placement="bottom-end">
|
||||||
|
{#snippet target(attachment)}
|
||||||
|
<Button {@attach attachment} size="custom" class="h-8 w-8" rounding="pill">
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
onclick={() => blockUser(isBlocked(profile.current.user!, person.person.id), person.person.id)}
|
||||||
|
>
|
||||||
|
{#snippet prefix()}
|
||||||
|
<Icon mini size="16" src={NoSymbol} />
|
||||||
|
{/snippet}
|
||||||
|
{isBlocked(profile.current.user, person.person.id)
|
||||||
|
? 'Unblock'
|
||||||
|
: 'Block'}
|
||||||
|
</MenuButton>
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { isImage, isVideo } from '$lib/ui/image.js'
|
import { isImage, isVideo } from '$lib/util.svelte'
|
||||||
import { TextInput } from 'mono-svelte'
|
import { TextInput } from 'mono-svelte'
|
||||||
|
|
||||||
let imageInput = $state('')
|
let imageInput = $state('')
|
||||||
|
|||||||
Reference in new issue
Block a user