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 { client, getClient, site } from '$lib/client/lemmy.svelte'
|
||||
import { instanceToURL, moveItem } from '$lib/util.svelte'
|
||||
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { writable } from 'svelte/store'
|
||||
import { t } from './i18n/translations'
|
||||
@@ -309,9 +308,7 @@ export const notifications = writable<Notifications>({
|
||||
async function userFromJwt(
|
||||
jwt: string,
|
||||
instance: string,
|
||||
): Promise<
|
||||
{ user: MyUserInfo | undefined; site: GetSiteResponse } | undefined
|
||||
> {
|
||||
): Promise<{ user?: MyUserInfo; site: GetSiteResponse } | undefined> {
|
||||
const sitePromise = client({ instanceURL: instance, auth: jwt }).getSite()
|
||||
|
||||
const timer = setTimeout(
|
||||
@@ -335,13 +332,6 @@ async function userFromJwt(
|
||||
|
||||
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
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<script lang="ts">
|
||||
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 { t } from '$lib/i18n/translations'
|
||||
import type { CommentView } from '$lib/client/types'
|
||||
import { Button, Material } from 'mono-svelte'
|
||||
import { ArrowUturnUp, Icon } from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import { PostMeta } from '../post'
|
||||
|
||||
interface Props {
|
||||
comment: CommentView
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
|
||||
interface Props extends HTMLAttributes<HTMLDivElement> {
|
||||
site: SiteView
|
||||
taglines?: Tagline[] | undefined
|
||||
admins?: PersonView[] | undefined
|
||||
version?: string | undefined
|
||||
taglines?: Tagline[]
|
||||
admins?: PersonView[]
|
||||
version?: string
|
||||
class?: ClassValue
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
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 { t } from '$lib/i18n/translations'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
@@ -18,6 +17,7 @@
|
||||
import { Fire, Icon, Trash } from 'svelte-hero-icons'
|
||||
import { amMod, isAdmin } from './moderation'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Post } from '../post'
|
||||
|
||||
interface Props {
|
||||
open: boolean
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
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 { t } from '$lib/i18n/translations'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
@@ -15,6 +14,7 @@
|
||||
import { Button, Modal, toast } from 'mono-svelte'
|
||||
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Post } from '../post'
|
||||
|
||||
interface Props {
|
||||
open: boolean
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
<script lang="ts">
|
||||
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 { settings, type View } from '$lib/settings.svelte.js'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
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 {
|
||||
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)}
|
||||
size="square-sm"
|
||||
color="tertiary"
|
||||
class="text-black dark:text-white absolute z-10 isolate pointer-events-auto bottom-0 {expanded
|
||||
? 'bg-slate-200/50 dark:bg-zinc-900 border shadow-md'
|
||||
: ''} left-1/2 -translate-x-1/2 mb-4"
|
||||
class={[
|
||||
'text-black dark:text-white absolute z-10 isolate pointer-events-auto bottom-0',
|
||||
'left-1/2 -translate-x-1/2 mb-4',
|
||||
expanded && 'bg-slate-200/50 dark:bg-zinc-900 shadow-md',
|
||||
]}
|
||||
title="Expand"
|
||||
>
|
||||
<Icon
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import Post from './Post.svelte'
|
||||
import { Post } from '.'
|
||||
|
||||
interface Props {
|
||||
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 {
|
||||
content: string
|
||||
color?: string
|
||||
@@ -11,6 +19,64 @@
|
||||
['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 = (
|
||||
title?: string,
|
||||
): { tags: Tag[]; title?: string } => {
|
||||
@@ -43,6 +109,8 @@
|
||||
</script>
|
||||
|
||||
<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 Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
@@ -51,10 +119,8 @@
|
||||
formatRelativeDate,
|
||||
} from '$lib/components/util/RelativeDate.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { instance } from '$lib/instance.svelte'
|
||||
import { settings, type View } from '$lib/settings.svelte'
|
||||
import type { Community, Person, SubscribedType } from '$lib/client/types'
|
||||
import { Badge, modal, Popover } from 'mono-svelte'
|
||||
import { Badge, Material, modal, Popover } from 'mono-svelte'
|
||||
import {
|
||||
Bookmark,
|
||||
ExclamationTriangle,
|
||||
@@ -68,7 +134,6 @@
|
||||
Trash,
|
||||
type IconSource,
|
||||
} from 'svelte-hero-icons'
|
||||
import Material from 'mono-svelte/materials/Material.svelte'
|
||||
import { CommunityLink } from '../community'
|
||||
|
||||
interface Props {
|
||||
@@ -83,16 +148,7 @@
|
||||
edited?: string
|
||||
view?: View
|
||||
// Badges
|
||||
badges?: {
|
||||
nsfw: boolean
|
||||
saved: boolean
|
||||
featured: boolean
|
||||
deleted: boolean
|
||||
removed: boolean
|
||||
locked: boolean
|
||||
moderator: boolean
|
||||
admin: boolean
|
||||
}
|
||||
badges?: Record<BadgeType, boolean>
|
||||
tags?: Tag[]
|
||||
style?: string
|
||||
titleClass?: string
|
||||
@@ -274,66 +330,17 @@
|
||||
</a>
|
||||
{/each}
|
||||
{/if}
|
||||
{#if badges.nsfw}
|
||||
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
|
||||
{#snippet icon()}
|
||||
<Icon src={ExclamationTriangle} size="14" micro />
|
||||
{/snippet}
|
||||
{$t('post.badges.nsfw')}
|
||||
{#each Object.keys(badges)
|
||||
// filter by ones that are true
|
||||
.filter(i => badges[i as BadgeType] == true)
|
||||
// get from predetermined map
|
||||
.map(i => badgeToData.get(i as BadgeType))
|
||||
// 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>
|
||||
{/if}
|
||||
{#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}
|
||||
{/each}
|
||||
{@render extraBadges?.()}
|
||||
</div>
|
||||
</header>
|
||||
@@ -341,8 +348,7 @@
|
||||
{@const useAttachedUrl = settings.posts.titleOpensUrl && postUrl}
|
||||
<h3
|
||||
class={[
|
||||
'max-sm:m-0!',
|
||||
'font-medium',
|
||||
'font-medium max-sm:mt-0!',
|
||||
titleClass,
|
||||
settings.markReadPosts && read && 'text-slate-600 dark:text-zinc-400',
|
||||
view == 'compact' ? 'text-base' : 'text-lg',
|
||||
@@ -352,7 +358,7 @@
|
||||
<a
|
||||
href={useAttachedUrl
|
||||
? postUrl
|
||||
: `/post/${encodeURIComponent(instance.data)}/${id}`}
|
||||
: `/post/${encodeURIComponent(profile.current.intsance)}/${id}`}
|
||||
target={useAttachedUrl
|
||||
? '_blank'
|
||||
: undefined}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
ShieldCheck,
|
||||
} from 'svelte-hero-icons'
|
||||
import { postLink } from '../helpers'
|
||||
import PostVote from '../PostVote.svelte'
|
||||
import { PostVote } from '..'
|
||||
|
||||
let saving = $state(false)
|
||||
let editing = $state(false)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import { Button } from 'mono-svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
|
||||
import { Post } from '..'
|
||||
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import VirtualList from '$lib/components/render/VirtualList.svelte'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
@@ -26,6 +25,7 @@
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { SvelteSet } from 'svelte/reactivity'
|
||||
import { fly } from 'svelte/transition'
|
||||
import { Post } from '..'
|
||||
|
||||
interface Props {
|
||||
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 { isImage, isVideo } from '$lib/ui/image'
|
||||
import { canParseUrl, findClosestNumber } from '$lib/util.svelte'
|
||||
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) =>
|
||||
me.person.id == comment.creator.id
|
||||
@@ -57,24 +61,23 @@ export const isYoutubeLink = (url?: string): RegExpMatchArray | null => {
|
||||
return url?.match?.(YOUTUBE_REGEX)
|
||||
}
|
||||
|
||||
export const postLink = (post: Post) =>
|
||||
`/post/${encodeURIComponent(instance.data)}/${post.id}`
|
||||
export function postLink(post: Post) {
|
||||
return `/post/${encodeURIComponent(profile.current.instance)}/${post.id}`
|
||||
}
|
||||
|
||||
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
||||
export type IframeType = 'youtube' | 'video' | 'none'
|
||||
|
||||
export const mediaType = (url?: string): MediaType => {
|
||||
if (url) {
|
||||
if (isImage(url)) return 'image'
|
||||
if (isVideo(url)) return 'iframe'
|
||||
if (isYoutubeLink(url)) return 'iframe'
|
||||
if (canParseUrl(url)) return 'embed'
|
||||
return 'none'
|
||||
}
|
||||
|
||||
export function mediaType(url?: string): MediaType {
|
||||
if (!url) return 'none'
|
||||
if (isImage(url)) return 'image'
|
||||
if (isVideo(url)) return 'iframe'
|
||||
if (isYoutubeLink(url)) return 'iframe'
|
||||
if (canParseUrl(url)) return 'embed'
|
||||
return 'none'
|
||||
}
|
||||
export const iframeType = (url: string): IframeType => {
|
||||
|
||||
export function iframeType(url: string): IframeType {
|
||||
if (isVideo(url)) return 'video'
|
||||
if (isYoutubeLink(url)) return 'youtube'
|
||||
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 imageLoaded: boolean | null = $state(null)
|
||||
|
||||
onMount(() => {
|
||||
imageLoaded = false
|
||||
})
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<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 type { Post } from '$lib/client/types'
|
||||
import PostIframe from './PostIframe.svelte'
|
||||
import PostImage from './PostImage.svelte'
|
||||
import {
|
||||
PostImage,
|
||||
PostIframe,
|
||||
PostLink,
|
||||
type MediaType,
|
||||
iframeType,
|
||||
} from '..'
|
||||
|
||||
interface Props {
|
||||
view?: View
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
bestImageURL,
|
||||
postLink,
|
||||
type MediaType,
|
||||
} from '$lib/components/lemmy/post/helpers.js'
|
||||
import { bestImageURL, postLink, type MediaType } from '..'
|
||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { settings, type View } from '$lib/settings.svelte.js'
|
||||
import type { Post } from '$lib/client/types'
|
||||
import { modal } from 'mono-svelte'
|
||||
import Button from 'mono-svelte/button/Button.svelte'
|
||||
import { modal, Button } from 'mono-svelte'
|
||||
import {
|
||||
DocumentText,
|
||||
ExclamationTriangle,
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
iframeType,
|
||||
mediaType,
|
||||
optimizeImageURL,
|
||||
} from '$lib/components/lemmy/post/helpers'
|
||||
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
|
||||
PostIframe,
|
||||
} from '$lib/components/lemmy/post'
|
||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getContext } from 'svelte'
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { site } from '$lib/client/lemmy.svelte'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { theme } from '$lib/ui/colors.svelte'
|
||||
import { theme } from '$lib/ui/theme/theme.svelte'
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
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 { TextInput } from 'mono-svelte'
|
||||
import { createEventDispatcher, onMount } from 'svelte'
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { type ResumableItem } from '$lib/lemmy/item'
|
||||
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 {
|
||||
ArrowRightOnRectangle,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { communityLink } from '$lib/lemmy/generic'
|
||||
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 {
|
||||
ArrowLeftOnRectangle,
|
||||
|
||||
+22
-23
@@ -1,28 +1,27 @@
|
||||
import { profile, type ProfileInfo } from '$lib/auth.svelte'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
import { trycatch } from '$lib/util.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import type { Community, MyUserInfo } from '$lib/client/types'
|
||||
|
||||
// TODO obliterate this file
|
||||
|
||||
export const blockUser = async (block: boolean, id: number) => {
|
||||
export async function blockUser(block: boolean, id: number) {
|
||||
const auth = profile.current?.jwt
|
||||
|
||||
if (!auth) throw new Error('Unauthorized')
|
||||
|
||||
await getClient().blockPerson({
|
||||
await client().blockPerson({
|
||||
block: block,
|
||||
person_id: id,
|
||||
})
|
||||
}
|
||||
|
||||
export const isBlocked = (me: MyUserInfo, user: number) =>
|
||||
me.person_blocks.map((b) => b.target.id).includes(user)
|
||||
export function isBlocked(me: MyUserInfo, user: number) {
|
||||
return me.person_blocks.map((b) => b.target.id).includes(user)
|
||||
}
|
||||
|
||||
export const addSubscription = (
|
||||
export function addSubscription(
|
||||
community: Community,
|
||||
subscribe: boolean = true,
|
||||
) => {
|
||||
) {
|
||||
const index = profile.current.user?.follows
|
||||
.map((f) => f.community.id)
|
||||
.indexOf(community.id)
|
||||
@@ -37,19 +36,19 @@ export const addSubscription = (
|
||||
}
|
||||
}
|
||||
|
||||
export const addAdmin = async (handle: string, added: boolean) =>
|
||||
trycatch(async () => {
|
||||
const user = await getClient().resolveObject({
|
||||
q: handle,
|
||||
})
|
||||
|
||||
if (!user.person) throw new Error('No user found')
|
||||
|
||||
return await getClient().addAdmin({
|
||||
added: added,
|
||||
person_id: user.person.person.id,
|
||||
})
|
||||
export async function addAdmin(handle: string, added: boolean) {
|
||||
const user = await client().resolveObject({
|
||||
q: handle,
|
||||
})
|
||||
|
||||
export const hasFavorite = (profile: ProfileInfo, id: number): boolean =>
|
||||
profile.favorites?.map((i) => i.id).includes(id) ?? false
|
||||
if (!user.person) throw new Error('No user found')
|
||||
|
||||
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'
|
||||
|
||||
interface SessionStorage {
|
||||
lastSeenCommunity: Community | undefined
|
||||
postDraft:
|
||||
| {
|
||||
community: Community | null
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
url: string | undefined
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
}
|
||||
| undefined
|
||||
lastSeenCommunity?: Community
|
||||
postDraft?: {
|
||||
community: Community | null
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
url?: string
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
}
|
||||
}
|
||||
|
||||
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 type { Theme, ThemeColors } from './colors.svelte'
|
||||
import type { Theme, ThemeColors } from './theme.svelte'
|
||||
|
||||
const PHOTON_DEFAULT = {
|
||||
slate: {
|
||||
File renamed without changes.
+20
-12
@@ -92,18 +92,6 @@ export function moveItem<T>(
|
||||
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) => {
|
||||
array.splice(array.findIndex(predicate), 1)
|
||||
}
|
||||
@@ -206,3 +194,23 @@ export class ReactiveState<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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user