fix: Fix lint errors (#559)

* cleanup: postactions styling

* misc: fix first round of errors

* pkg: remove vitest

* fix: fix lint errors stage 2

* fix: fix lint errors stage 3

* fix: fix lint errors, stage 3

* misc: update eslint rules to warn for writable derived
This commit is contained in:
Xylight authored and GitHub committed 2025-06-09 16:34:06 -07:00
1 parent 1824245f13
commit 76c581123a
225 files changed
+1553 -2352

No files matched your search

@@ -1,11 +1,10 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import { getClient } from '$lib/lemmy.svelte.js'
import type { Community, CommunityView, ListingType } from 'lemmy-js-client'
import type { Community, ListingType } from 'lemmy-js-client'
import { MenuButton, Search } from 'mono-svelte'
import type { SearchProps } from 'mono-svelte/search/Search.svelte'
import { createEventDispatcher } from 'svelte'
import { Icon, XCircle, ServerStack } from 'svelte-hero-icons'
import { Icon, ServerStack, XCircle } from 'svelte-hero-icons'
import { fly } from 'svelte/transition'
interface Props {
@@ -14,8 +13,8 @@
instance?: string | undefined
listing_type?: ListingType
showWhenEmpty?: boolean
// eslint-disable-next-line
onselect?: (item: any) => void
[key: string]: any
}
let {
@@ -35,7 +34,7 @@
{#if type == 'community'}
<Search
search={async (q) => {
search={async q => {
const results = await getClient(instance).search({
q: q || ' ',
type_: 'Communities',
@@ -44,9 +43,9 @@
sort: 'TopAll',
})
return results.communities.map((c) => c.community)
return results.communities.map(c => c.community)
}}
extractName={(c) => `${c.title}@${new URL(c.actor_id).hostname}`}
extractName={c => `${c.title}@${new URL(c.actor_id).hostname}`}
bind:query={q}
{...rest}
>
@@ -80,16 +79,16 @@
</Search>
{:else if type == 'instance'}
<Search
search={async (q) => {
search={async q => {
const results = (await instances) || {}
return q
? (results.federated_instances?.linked || []).filter(
(i) => i.software === 'lemmy' && i.domain.includes(q),
i => i.software === 'lemmy' && i.domain.includes(q),
)
: []
}}
extractName={(i) => `${i.domain}`}
extractName={i => `${i.domain}`}
bind:query={q}
{...rest}
>
+8 -17
View File
@@ -2,27 +2,18 @@
import Markdown from '$lib/components/markdown/Markdown.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import StickyCard from '$lib/components/ui/StickyCard.svelte'
import { t } from '$lib/i18n/translations'
import { userLink } from '$lib/lemmy/generic'
import { settings } from '$lib/settings.svelte'
import type { PersonView, SiteView, Tagline } from 'lemmy-js-client'
import { Badge, Button } from 'mono-svelte'
import {
BuildingOffice,
ChartBar,
Icon,
InformationCircle,
Newspaper,
ServerStack,
UserGroup,
} from 'svelte-hero-icons'
import { Badge } from 'mono-svelte'
import { Icon, ServerStack } from 'svelte-hero-icons'
import Link from '../input/Link.svelte'
import Entity from '../ui/Entity.svelte'
import Expandable from '../ui/Expandable.svelte'
import LabelStat from '../ui/LabelStat.svelte'
import ItemList from './generic/ItemList.svelte'
import { userLink } from '$lib/lemmy/generic'
import { t } from '$lib/i18n/translations'
import Entity from '../ui/Entity.svelte'
import { settings } from '$lib/settings.svelte'
import { optimizeImageURL } from './post/helpers'
import Link from '../input/Link.svelte'
import EndPlaceholder from '../ui/EndPlaceholder.svelte'
interface Props {
site: SiteView
@@ -130,7 +121,7 @@
</span>
{/snippet}
<ItemList
items={admins.map((a) => ({
items={admins.map(a => ({
id: a.person.id,
name: a.person.name,
url: userLink(a.person),
+21 -21
View File
@@ -1,4 +1,16 @@
<script lang="ts">
import { page } from '$app/state'
import { profile } from '$lib/auth.svelte.js'
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import { publishedToDate } from '$lib/components/util/date.js'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte.js'
import { Button, Modal, toast } from 'mono-svelte'
import { onMount } from 'svelte'
import {
Bookmark,
Icon,
@@ -8,25 +20,13 @@
Plus,
Trash,
} from 'svelte-hero-icons'
import type { CommentNodeI } from './comments.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import CommentForm from './CommentForm.svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
import { getClient } from '$lib/lemmy.svelte.js'
import { Disclosure, toast } from 'mono-svelte'
import { profile } from '$lib/auth.svelte.js'
import { Button, Modal } from 'mono-svelte'
import { publishedToDate } from '$lib/components/util/date.js'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import { page } from '$app/state'
import { onMount } from 'svelte'
import { t } from '$lib/i18n/translations'
import { fly, slide } from 'svelte/transition'
import { expoInOut, expoOut } from 'svelte/easing'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { expoOut } from 'svelte/easing'
import type { ClassValue } from 'svelte/elements'
import { fly, slide } from 'svelte/transition'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import CommentForm from './CommentForm.svelte'
import type { CommentNodeI } from './comments.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
node: CommentNodeI
@@ -76,7 +76,7 @@
editing = false
} catch (err) {
toast({
content: err as any,
content: errorMessage(err as string),
type: 'error',
})
}
@@ -102,7 +102,7 @@
<span>{$t('form.edit')}</span>
{/snippet}
<form
onsubmit={(e) => {
onsubmit={e => {
e.preventDefault()
save()
}}
@@ -253,7 +253,7 @@
label={$t('comment.reply')}
{postId}
parentId={node.comment_view.comment.id}
oncomment={(e) => {
oncomment={e => {
node.children = [
{
children: [],
@@ -1,32 +1,28 @@
<script lang="ts">
import type { CommentView } from 'lemmy-js-client'
import { profile } from '$lib/auth.svelte.js'
import CommentVote from '$lib/components/lemmy/comment/CommentVote.svelte'
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
import {
amMod,
isAdmin,
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import { t } from '$lib/i18n/translations'
import { deleteItem, save } from '$lib/lemmy/contentview.js'
import { settings } from '$lib/settings.svelte'
import type { CommentView } from 'lemmy-js-client'
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
import {
ArrowUturnLeft,
Bookmark,
BookmarkSlash,
ChatBubbleOvalLeft,
EllipsisHorizontal,
Flag,
Icon,
Language,
PencilSquare,
Square2Stack,
Trash,
} from 'svelte-hero-icons'
import { createEventDispatcher } from 'svelte'
import { isCommentMutable } from '$lib/components/lemmy/post/helpers.js'
import {
amMod,
isAdmin,
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
import { profile } from '$lib/auth.svelte.js'
import { deleteItem, save } from '$lib/lemmy/contentview.js'
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import { settings } from '$lib/settings.svelte'
interface Props {
comment: CommentView
@@ -84,9 +80,11 @@
<MenuDivider>{$t('comment.actions.label')}</MenuDivider>
<MenuButton
onclick={() => {
navigator.share?.({
url: comment.comment.ap_id,
}) ?? navigator.clipboard.writeText(comment.comment.ap_id)
if (navigator.share)
navigator.share?.({
url: comment.comment.ap_id,
})
else navigator.clipboard.writeText(comment.comment.ap_id)
}}
>
<Icon src={Square2Stack} mini size="16" />
@@ -102,11 +100,7 @@
<MenuButton
onclick={async () => {
if (profile.data?.jwt)
comment.saved = await save(
comment,
!comment.saved,
profile.data.jwt,
)
comment.saved = await save(comment, !comment.saved)
}}
>
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
@@ -122,7 +116,6 @@
comment.comment.deleted = await deleteItem(
comment,
!comment.comment.deleted,
profile.data.jwt,
)
}}
>
@@ -1,18 +1,17 @@
<script lang="ts">
import type { CommentResponse } from 'lemmy-js-client'
import { getClient, site } from '$lib/lemmy.svelte.js'
import { createEventDispatcher } from 'svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import { profile } from '$lib/auth.svelte.js'
import { Menu, Select, Spinner, toast, Option, MenuButton } from 'mono-svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { placeholders } from '$lib/util.svelte.js'
import { Button } from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import { getClient, site } from '$lib/lemmy.svelte.js'
import { errorMessage } from '$lib/lemmy/error'
import { placeholders } from '$lib/util.svelte.js'
import type { CommentResponse } from 'lemmy-js-client'
import { Button, Menu, MenuButton, toast } from 'mono-svelte'
import { ArrowUp, Icon, Language, XMark } from 'svelte-hero-icons'
import type { ClassValue, HTMLTextareaAttributes } from 'svelte/elements'
interface Props {
interface Props extends Omit<HTMLTextareaAttributes, 'oncancel'> {
postId: number
parentId?: number | undefined
locked?: boolean
@@ -22,10 +21,13 @@
value?: string
actions?: boolean
preview?: boolean
class?: ClassValue
required?: boolean
id?: string
label?: string
oncomment?: (comment: CommentResponse) => void
onconfirm?: (value: string) => void
oncancel?: (cancel: boolean) => void
[key: string]: any
}
let {
@@ -40,7 +42,6 @@
preview: previewAction = true,
oncancel,
oncomment,
onconfirm,
...rest
}: Props = $props()
@@ -65,7 +66,7 @@
} catch (err) {
console.error(err)
toast({
content: errorMessage(err as any),
content: errorMessage(err as string),
type: 'error',
})
}
@@ -93,12 +94,6 @@
: (placeholder ?? placeholders.get('comment'))}
bind:value
disabled={locked || loading || banned}
onconfirm={() => {
if (actions) {
submit()
onconfirm?.(value)
}
}}
previewButton={previewAction}
>
<Menu>
@@ -2,7 +2,7 @@
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 { settings } from '$lib/settings.svelte.js'
import { settings, type View } from '$lib/settings.svelte.js'
import { t } from '$lib/i18n/translations'
import type { CommentView } from 'lemmy-js-client'
import { Button, Material } from 'mono-svelte'
@@ -10,12 +10,11 @@
interface Props {
comment: CommentView
view?: any
view?: View
community?: boolean
meta?: boolean
class?: string
commentClass?: string
[key: string]: any
}
let {
@@ -1,10 +1,9 @@
<script lang="ts">
import VirtualList from '$lib/components/render/VirtualList.svelte'
import type { Post } from 'lemmy-js-client'
import { onMount } from 'svelte'
import type { CommentNodeI } from './comments.svelte'
import Comments from './Comments.svelte'
import { onMount, tick } from 'svelte'
import VirtualList from '$lib/components/render/VirtualList.svelte'
import { page } from '$app/state'
interface Props {
nodes: CommentNodeI[]
@@ -35,7 +34,7 @@
// IntersectionObserver to watch for shifts
const observer = new IntersectionObserver(
(entries) => {
entries => {
entries.forEach(updateOffset)
},
{ threshold: [0, 1] },
@@ -59,11 +58,11 @@
{initialOffset}
bind:this={list}
>
{#snippet item(item, index)}
{#snippet item(index)}
<div class="-mx-4 sm:-mx-6 px-4 sm:px-6">
<Comments
isParent={true}
bind:nodes={() => [nodes[index]], (v) => (nodes[index] = v[0])}
bind:nodes={() => [nodes[index]], v => (nodes[index] = v[0])}
{post}
/>
</div>
@@ -1,22 +1,13 @@
<script lang="ts">
import {
ArrowDownCircle,
ArrowUp,
ArrowUpCircle,
ChevronDown,
ChevronUp,
Icon,
} from 'svelte-hero-icons'
import { getClient, site } from '$lib/lemmy.svelte'
import { settings } from '$lib/settings.svelte'
import { profile } from '$lib/auth.svelte.js'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { Button, buttonColor, toast } from 'mono-svelte'
import { vote as voteItem } from '$lib/lemmy/contentview'
import { shouldShowVoteColor } from '../post/PostVote.svelte'
import { fly } from 'svelte/transition'
import { backOut } from 'svelte/easing'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte'
import { buttonColor, toast } from 'mono-svelte'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
import { backOut } from 'svelte/easing'
import { fly } from 'svelte/transition'
import { shouldShowVoteColor } from '../post/PostVote.svelte'
interface Props {
vote?: number
@@ -1,20 +1,19 @@
<script lang="ts">
import Comments from './Comments.svelte'
import Comment from './Comment.svelte'
import { buildCommentsTree, type CommentNodeI } from './comments.svelte'
import { page } from '$app/state'
import { onMount, setContext } from 'svelte'
import { Icon, ArrowDownCircle } from 'svelte-hero-icons'
import { getClient } from '$lib/lemmy.svelte.js'
import type { CommentView, Post } from 'lemmy-js-client'
import { fly } from 'svelte/transition'
import { toast } from 'mono-svelte'
import { profile } from '$lib/auth.svelte.js'
import { Button } from 'mono-svelte'
import { afterNavigate, goto } from '$app/navigation'
import { backOut, expoOut } from 'svelte/easing'
import { t } from '$lib/i18n/translations'
import { browser } from '$app/environment'
import { goto } from '$app/navigation'
import { page } from '$app/state'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte.js'
import type { Post } from 'lemmy-js-client'
import { Button, toast } from 'mono-svelte'
import { onMount } from 'svelte'
import { ArrowDownCircle, Icon } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
import { fly } from 'svelte/transition'
import Comment from './Comment.svelte'
import Comments from './Comments.svelte'
import { buildCommentsTree, type CommentNodeI } from './comments.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
nodes: CommentNodeI[]
@@ -36,7 +35,6 @@
}
})
let loadingChildren = false
let childrenPage = 0
async function fetchChildren(parent: CommentNodeI) {
@@ -60,7 +58,6 @@
})
if (newComments.comments.length == 0) {
loadingChildren = false
toast({
content: $t('toast.noComments'),
type: 'error',
@@ -96,10 +93,10 @@
}
}
childrenPage++
} catch (error) {
console.error(error)
} catch (err) {
console.error(err)
toast({
content: error as any,
content: errorMessage(err as string),
type: 'error',
})
}
@@ -162,7 +159,6 @@
/>
{/snippet}
{$t('comment.more', {
// @ts-ignore
comments: node.comment_view.counts.child_count,
})}
</Button>
@@ -26,7 +26,7 @@ function getDepthFromComment(comment?: Comment): number | undefined {
export function buildCommentsTree(
comments: CommentView[],
baseDepth: number = 0,
filter: (c: CommentView) => boolean = (c) => true,
filter: (c: CommentView) => boolean = () => true,
): CommentNodeI[] {
const map = new Map<number, CommentNodeI>()
@@ -21,8 +21,8 @@
})
return block
} catch (error) {
toast({ content: error as any, type: 'error' })
} catch (err) {
toast({ content: errorMessage(err as string), type: 'error' })
return !block
}
}
@@ -36,8 +36,8 @@
})
removeToast(purgeToast)
toast({ content: t.get('toast.purgedCommunity'), type: 'success' })
} catch (e) {
toast({ content: e as any, type: 'error' })
} catch (err) {
toast({ content: errorMessage(err as string), type: 'error' })
}
}
@@ -59,8 +59,8 @@
content: `Successfully blocked that instance.`,
type: 'success',
})
} catch (error) {
toast({ content: error as any, type: 'error' })
} catch (err) {
toast({ content: errorMessage(err as string), type: 'error' })
}
}
</script>
@@ -73,43 +73,39 @@
} from '$lib/components/lemmy/moderation/moderation.js'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import Entity from '$lib/components/ui/Entity.svelte'
import Expandable from '$lib/components/ui/Expandable.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import StickyCard from '$lib/components/ui/StickyCard.svelte'
import {
Menu,
MenuButton,
Modal,
removeToast,
toast,
modal,
action,
} from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import { client, getClient } from '$lib/lemmy.svelte.js'
import { errorMessage } from '$lib/lemmy/error'
import { userLink } from '$lib/lemmy/generic'
import { addSubscription } from '$lib/lemmy/user.js'
import { settings } from '$lib/settings.svelte'
import { fullCommunityName } from '$lib/util.svelte.js'
import type { CommunityModeratorView, CommunityView } from 'lemmy-js-client'
import { Button } from 'mono-svelte'
import {
action,
Button,
Menu,
MenuButton,
modal,
removeToast,
toast,
} from 'mono-svelte'
import {
BuildingOffice2,
Calendar,
ChartBar,
Check,
Cog6Tooth,
EllipsisHorizontal,
Fire,
Icon,
InformationCircle,
Newspaper,
NoSymbol,
Plus,
} from 'svelte-hero-icons'
import Expandable from '$lib/components/ui/Expandable.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import ItemList from '../generic/ItemList.svelte'
import { userLink } from '$lib/lemmy/generic'
import { t } from '$lib/i18n/translations'
import Entity from '$lib/components/ui/Entity.svelte'
import { settings } from '$lib/settings.svelte'
let loading = $state({
blocking: false,
@@ -128,8 +124,8 @@
community_id: community_view.community.id,
follow: !subscribed,
})
} catch (error) {
toast({ content: error as any, type: 'error' })
} catch (err) {
toast({ content: errorMessage(err as string), type: 'error' })
}
community_view.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed'
@@ -219,7 +215,7 @@
</span>
{/snippet}
<ItemList
items={moderators.map((m) => ({
items={moderators.map(m => ({
id: m.moderator.id,
name: m.moderator.name,
url: userLink(m.moderator),
@@ -4,22 +4,27 @@
import { goto } from '$app/navigation'
import { profile } from '$lib/auth.svelte.js'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { Badge, ImageInput, MenuButton, Switch, toast } from 'mono-svelte'
import { client, getClient, site } from '$lib/lemmy.svelte.js'
import { addSubscription } from '$lib/lemmy/user.js'
import { Button, Checkbox, TextInput } from 'mono-svelte'
import { uploadImage } from '$lib/util.svelte.js'
import { t } from '$lib/i18n/translations'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import ImagePreviewInput from '$lib/components/input/ImagePreviewInput.svelte'
import Label from 'mono-svelte/forms/Label.svelte'
import { DocumentPlus, GlobeAlt, Icon, MapPin, Plus } from 'svelte-hero-icons'
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
import Select from 'mono-svelte/forms/select/Select.svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
import { t } from '$lib/i18n/translations'
import { getClient, site } from '$lib/lemmy.svelte.js'
import { addSubscription } from '$lib/lemmy/user.js'
import {
Badge,
Button,
MenuButton,
Switch,
TextInput,
toast,
} from 'mono-svelte'
import Label from 'mono-svelte/forms/Label.svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import Select from 'mono-svelte/forms/select/Select.svelte'
import Material from 'mono-svelte/materials/Material.svelte'
import Menu from 'mono-svelte/popover/Menu.svelte'
import { DocumentPlus, GlobeAlt, Icon, MapPin, Plus } from 'svelte-hero-icons'
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
/**
@@ -96,7 +101,7 @@
if (profile.data.user) {
const c = profile.data.user.moderates
.map((m) => m.community.id)
.map(m => m.community.id)
.indexOf(res.community_view.community.id)
if (c != -1) {
profile.data.user.moderates[c] = {
@@ -127,7 +132,7 @@
)
} catch (err) {
toast({
content: err as any,
content: errorMessage(err as string),
type: 'error',
})
}
@@ -184,7 +189,7 @@
<ImageUploadModal
bind:open={uploading.icon}
multiple={false}
onupload={(uploaded) => {
onupload={uploaded => {
uploading.icon = false
formData.icon = uploaded[0]
}}
@@ -212,7 +217,7 @@
<ImageUploadModal
bind:open={uploading.banner}
multiple={false}
onupload={(uploaded) => {
onupload={uploaded => {
uploading.banner = false
formData.banner = uploaded[0]
}}
@@ -249,7 +254,7 @@
</Badge>
</button>
{/snippet}
{#each site.data.all_languages.filter((l) => !formData.languages?.includes(l.id)) as language, index}
{#each site.data.all_languages.filter(l => !formData.languages?.includes(l.id)) as language (language.id)}
<MenuButton
class="min-h-[16px] py-0"
onclick={() => {
@@ -263,9 +268,9 @@
</MenuButton>
{/each}
</Menu>
{#each formData.languages ?? [] as languageId, index}
{#each formData.languages ?? [] as languageId, index (languageId)}
{@const language = site.data.all_languages.find(
(l) => l.id == languageId,
l => l.id == languageId,
)}
<button
type="button"
@@ -1,7 +1,12 @@
<script lang="ts">
import { profile } from '$lib/auth.svelte'
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
import Expandable from '$lib/components/ui/Expandable.svelte'
import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte'
import { publishedToDate } from '$lib/components/util/date'
import { t } from '$lib/i18n/translations'
import { userLink } from '$lib/lemmy/generic'
import { settings } from '$lib/settings.svelte'
import { fullCommunityName } from '$lib/util.svelte'
import type {
Community,
@@ -9,28 +14,22 @@
CommunityModeratorView,
SubscribedType,
} from 'lemmy-js-client'
import { Button, toast, Menu, MenuButton, modal, action } from 'mono-svelte'
import { action, Button, Menu, MenuButton, modal, toast } from 'mono-svelte'
import {
BuildingOffice2,
Check,
Cog6Tooth,
Icon,
EllipsisHorizontal,
Plus,
Newspaper,
BuildingOffice2,
Fire,
Icon,
Newspaper,
NoSymbol,
Plus,
} from 'svelte-hero-icons'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import Expandable from '$lib/components/ui/Expandable.svelte'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import ItemList from '../generic/ItemList.svelte'
import { userLink } from '$lib/lemmy/generic'
import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte'
import { publishedToDate } from '$lib/components/util/date'
import { isAdmin } from '../moderation/moderation'
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
import { settings } from '$lib/settings.svelte'
interface Props {
community: Community
@@ -102,7 +101,7 @@
<hr class="flex-1 border-slate-200 dark:border-zinc-800 mx-3" />
{/snippet}
<ItemList
items={moderators.map((m) => ({
items={moderators.map(m => ({
id: m.moderator.id,
name: m.moderator.name,
url: userLink(m.moderator),
@@ -119,8 +118,7 @@
community: community,
banned_from_community: false,
blocked: false,
// @ts-ignore
counts: counts ?? {},
counts: counts!,
subscribed: subscribed,
}}
>
@@ -153,7 +151,7 @@
{/if}
{#if profile.data?.user && profile.data.user.moderates
.map((c) => c.community.id)
.map(c => c.community.id)
.includes(community.id)}
<Button
size="square-lg"
@@ -1,29 +1,25 @@
<script lang="ts">
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import { profile } from '$lib/auth.svelte.js'
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { t } from '$lib/i18n/translations'
import { addSubscription } from '$lib/lemmy/user.js'
import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js'
import type { CommunityView } from 'lemmy-js-client'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import { Button, Modal } from 'mono-svelte'
import {
ChatBubbleOvalLeftEllipsis,
Check,
ExclamationTriangle,
Icon,
InformationCircle,
MapPin,
NoSymbol,
PencilSquare,
Plus,
Trash,
UserGroup,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { Button, Modal } from 'mono-svelte'
import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js'
import { profile } from '$lib/auth.svelte.js'
import { addSubscription } from '$lib/lemmy/user.js'
import Avatar from '$lib/components/ui/Avatar.svelte'
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import { t } from '$lib/i18n/translations'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
let showInfo = $state(false)
interface Props {
@@ -13,10 +13,11 @@
avatarSize?: number
showInstance?: boolean
displayName?: boolean
badges?: any
badges?: {
nsfw: boolean
}
class?: string
instanceClass?: string
[key: string]: any
}
let {
@@ -13,19 +13,18 @@
import { amModOfAny } from '../moderation/moderation'
import { t } from '$lib/i18n/translations'
import Option from 'mono-svelte/forms/select/Option.svelte'
import type { SelectProps } from 'mono-svelte/forms/select/Select.svelte'
interface Props {
interface Props extends SelectProps<string> {
selected: string
navigate?: boolean
changeDefault?: boolean
showLabel?: boolean
[key: string]: any
}
let {
selected = $bindable(),
navigate = true,
changeDefault = false,
showLabel = true,
...rest
}: Props = $props()
@@ -3,6 +3,8 @@
import { t } from '$lib/i18n/translations'
import { searchParam } from '$lib/util.svelte.js'
import { Select } from 'mono-svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import type { SelectProps } from 'mono-svelte/forms/select/Select.svelte'
import {
ArrowTrendingDown,
ArrowTrendingUp,
@@ -21,21 +23,18 @@
Trophy,
} from 'svelte-hero-icons'
import { backOut } from 'svelte/easing'
import { fly, slide } from 'svelte/transition'
import Option from 'mono-svelte/forms/select/Option.svelte'
import { fly } from 'svelte/transition'
interface Props {
interface Props extends SelectProps<string> {
selected: string
navigate?: boolean
changeDefault?: boolean
class?: string
[key: string]: any
}
let {
selected = $bindable(),
navigate = true,
changeDefault = false,
class: clazz = '',
...rest
}: Props = $props()
@@ -1,22 +1,12 @@
<script lang="ts">
import { settings } from '$lib/settings.svelte.js'
import { t } from '$lib/i18n/translations'
import { settings } from '$lib/settings.svelte.js'
import { Select } from 'mono-svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import {
Bars3,
Clock,
Icon,
ListBullet,
QueueList,
RectangleGroup,
Square2Stack,
ViewColumns,
} from 'svelte-hero-icons'
import { Bars3, Icon, RectangleGroup, ViewColumns } from 'svelte-hero-icons'
interface Props {
showLabel?: boolean
[key: string]: any
}
let { showLabel = true, ...rest }: Props = $props()
@@ -1,6 +1,5 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import { Button } from 'mono-svelte'
import { flip } from 'svelte/animate'
import { expoOut } from 'svelte/easing'
@@ -4,7 +4,7 @@
import { errorMessage } from '$lib/lemmy/error'
import { t } from '$lib/i18n/translations'
import { uploadImage } from '$lib/util.svelte.js'
import { ImageInput, Spinner, toast } from 'mono-svelte'
import { toast } from 'mono-svelte'
import { Button, Modal } from 'mono-svelte'
import { DocumentPlus, Icon } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
@@ -39,19 +39,19 @@
try {
const uploaded = (
await Promise.all(
Array.from(image).map((i) =>
Array.from(image).map(i =>
uploadImage(i, profile.data.instance, profile.data.jwt!)
.then((uploaded) => {
.then(uploaded => {
progress += 1 / (image?.length ?? 0)
return uploaded
})
.catch((err) => {
.catch(err => {
toast({ content: errorMessage(err), type: 'error' })
return 'Failed to upload'
}),
),
)
).filter((i) => i != undefined)
).filter(i => i != undefined)
if (!uploaded) throw new Error('Image upload returned undefined')
@@ -80,7 +80,7 @@
{/if}
<form
class="flex flex-col gap-4"
onsubmit={(e) => {
onsubmit={e => {
e.preventDefault()
upload()
}}
@@ -96,7 +96,6 @@
{multiple ? 'grid-cols-3 grid-rows-2' : 'grid-cols-1 grid-rows-1'}"
>
{#each previewURLs as file}
<!-- svelte-ignore a11y_missing_attribute -->
<img
src={file}
onload={() => URL.revokeObjectURL(file)}
@@ -9,6 +9,7 @@
import type { Person } from 'lemmy-js-client'
import { Button, Modal, toast } from 'mono-svelte'
import { Icon, PaperAirplane } from 'svelte-hero-icons'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
open?: boolean
@@ -40,7 +41,7 @@
open = false
} catch (err) {
toast({
content: err as any,
content: errorMessage(err as string),
type: 'error',
})
}
@@ -1,17 +1,18 @@
<script lang="ts">
import { run, preventDefault } from 'svelte/legacy'
import { preventDefault } from 'svelte/legacy'
import Avatar from '$lib/components/ui/Avatar.svelte'
import type { Community, Person, PersonView } from 'lemmy-js-client'
import type { Community, Person } from 'lemmy-js-client'
import { getClient } from '$lib/lemmy.svelte.js'
import { toast } from 'mono-svelte'
import { profile } from '$lib/auth.svelte.js'
import { Button, Checkbox, Modal, TextInput } from 'mono-svelte'
import { Button, Checkbox, Modal } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { t } from '$lib/i18n/translations'
import CommunityLink from '../community/CommunityLink.svelte'
import Duration from '$lib/components/form/Duration.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
open?: boolean
@@ -84,7 +85,7 @@
item.banned = !banned
} catch (err) {
toast({
content: err as any,
content: errorMessage(err),
type: 'error',
})
}
@@ -16,7 +16,6 @@
interface Props {
item: PostView | CommentView
[key: string]: any
}
let { item = $bindable(), ...rest }: Props = $props()
@@ -1,9 +1,11 @@
<script lang="ts">
import { profile } from '$lib/auth.svelte.js'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte'
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
import type { CommentView, PostView } from 'lemmy-js-client'
import { amMod, ban, isAdmin, remove } from './moderation'
import { Button, Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
import {
ArrowsUpDown,
Fire,
Icon,
LockClosed,
@@ -12,16 +14,12 @@
ShieldExclamation,
Trash,
} from 'svelte-hero-icons'
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
import { Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
import { profile } from '$lib/auth.svelte.js'
import { Button } from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import { amMod, ban, isAdmin, remove } from './moderation'
import ShieldIcon from './ShieldIcon.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
item: PostView | CommentView
[key: string]: any
}
let { item = $bindable(), ...rest }: Props = $props()
@@ -44,7 +42,7 @@
item.post.locked = lock
} catch (err) {
toast({
content: err as any,
content: errorMessage(err),
type: 'error',
})
}
@@ -67,7 +65,7 @@
item.post.featured_community = pinned
} catch (err) {
toast({
content: err as any,
content: errorMessage(err),
type: 'error',
})
}
@@ -1,23 +1,23 @@
<script lang="ts">
import { run, preventDefault } from 'svelte/legacy'
import { preventDefault, run } from 'svelte/legacy'
import { profile } from '$lib/auth.svelte.js'
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 { Select, Switch, toast } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte.js'
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
import type { CommentView, PostView } from 'lemmy-js-client'
import { profile } from '$lib/auth.svelte.js'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { Fire, Icon, Trash } from 'svelte-hero-icons'
import MultiSelect from '$lib/components/input/Switch.svelte'
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
import { settings } from '$lib/settings.svelte.js'
import { fullCommunityName } from '$lib/util.svelte.js'
import { amMod, isAdmin } from './moderation'
import { Button, Checkbox, Modal } from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import type { CommentView, PostView } from 'lemmy-js-client'
import { Button, Modal, Select, Switch, toast } from 'mono-svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import { Fire, Icon, Trash } from 'svelte-hero-icons'
import { amMod, isAdmin } from './moderation'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
open: boolean
@@ -153,7 +153,7 @@
open = false
} catch (err) {
toast({
content: err as any,
content: errorMessage(err),
type: 'error',
})
}
@@ -1,22 +1,20 @@
<script lang="ts">
import { run, preventDefault } from 'svelte/legacy'
import { preventDefault, run } from 'svelte/legacy'
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 { toast } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte.js'
import type {
CommentView,
PostView,
PrivateMessageView,
} from 'lemmy-js-client'
import { profile } from '$lib/auth.svelte.js'
import { Button, Modal } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { onMount } from 'svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { t } from '$lib/i18n/translations'
import { Button, Modal, toast } from 'mono-svelte'
import PrivateMessage from '../inbox/PrivateMessage.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
open: boolean
@@ -67,7 +65,7 @@
type: 'success',
})
} catch (err) {
toast({ content: err as any, type: 'error' })
toast({ content: errorMessage(err as string), type: 'error' })
}
loading = false
@@ -9,7 +9,7 @@ import type {
PostView,
PrivateMessageView,
} from 'lemmy-js-client'
import { get, writable } from 'svelte/store'
import { writable } from 'svelte/store'
interface Modals {
reporting: {
@@ -29,7 +29,7 @@ interface Modals {
}
}
export let modals = writable<Modals>({
export const modals = writable<Modals>({
reporting: {
open: false,
item: undefined,
@@ -48,7 +48,7 @@ export let modals = writable<Modals>({
})
export function report(item: PostView | CommentView | PrivateMessageView) {
modals.update((m) => ({
modals.update(m => ({
...m,
reporting: {
open: true,
@@ -58,7 +58,7 @@ export function report(item: PostView | CommentView | PrivateMessageView) {
}
export function remove(item: SubmissionView, purge: boolean = false) {
modals.update((m) => ({
modals.update(m => ({
...m,
removing: {
open: true,
@@ -69,7 +69,7 @@ export function remove(item: SubmissionView, purge: boolean = false) {
}
export function ban(banned: boolean, item: Person, community?: Community) {
modals.update((m) => ({
modals.update(m => ({
...m,
banning: {
open: true,
@@ -88,16 +88,13 @@ export async function feature(featured: boolean, item: Comment, jwt: string) {
}
export const amMod = (me: MyUserInfo, community: Community) =>
me.moderates.map((c) => c.community.id).includes(community.id) ||
me.moderates.map(c => c.community.id).includes(community.id) ||
(community.local && isAdmin(me))
export const amModOfAny = (me?: MyUserInfo) =>
me && (me.moderates.length > 0 || isAdmin(me))
export const isAdmin = (me: MyUserInfo) =>
// backwards compatibility hack
// @ts-ignore
me.local_user_view.local_user.admin ?? me.local_user_view.person?.admin
export const isAdmin = (me: MyUserInfo) => me.local_user_view.local_user.admin
export const removalTemplate = (
input: string,
+17 -24
View File
@@ -1,29 +1,27 @@
<script lang="ts">
import type { PostView } from 'lemmy-js-client'
import { goto } from '$app/navigation'
import { profile } from '$lib/auth.svelte'
import { mediaType, postLink } 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 PostActions from '$lib/components/lemmy/post/PostActions.svelte'
import { settings, type View } from '$lib/settings.svelte.js'
import PostMeta, {
parseTags,
type Tag,
} from '$lib/components/lemmy/post/PostMeta.svelte'
import { Badge } from 'mono-svelte'
import { mediaType, postLink } from '$lib/components/lemmy/post/helpers.js'
import { publishedToDate } from '$lib/components/util/date.js'
import { ArrowUp, ChatBubbleOvalLeft, Icon } from 'svelte-hero-icons'
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
import PostBody from './PostBody.svelte'
import { profile } from '$lib/auth.svelte'
import { goto } from '$app/navigation'
import { settings, type View } from '$lib/settings.svelte.js'
import type { PostView } from 'lemmy-js-client'
import type { ClassValue } from 'svelte/elements'
import PostBody from './PostBody.svelte'
function getTagRule(tags: Tag[]): 'blur-sm' | 'hide' | undefined {
const tagContent = tags.map((t) => t.content.toLowerCase())
const tagContent = tags.map(t => t.content.toLowerCase())
let rule: 'blur-sm' | 'hide' | undefined
if (settings.nsfwBlur && (post.post.nsfw || post.community.nsfw))
rule = 'blur-sm'
tagContent.forEach((tag) => {
tagContent.forEach(tag => {
if (settings.tagRules?.[tag]) rule = settings.tagRules?.[tag] ?? rule
if (rule == 'hide') return rule
})
@@ -31,8 +29,8 @@
return rule
}
function onClick(e: any) {
const event = e as MouseEvent
function onClick(e: Event) {
const event = e as Event
const parent = document.getElementById(post.post.id.toString())
if (event.target == parent) {
@@ -68,7 +66,7 @@
})
let tags = $derived(parseTags(post.post.name))
let type = $derived(mediaType(post.post.url, view))
let type = $derived(mediaType(post.post.url))
let rule = $derived(getTagRule(tags.tags))
let hideTitle = $derived(
settings.posts.deduplicateEmbed &&
@@ -100,7 +98,6 @@
It adapts to all kinds of form factors for different contexts, such as feeds, full post view, and crosspost list.
-->
<!-- svelte-ignore a11y_no_static_element_interactions -->
<!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
<div
class={[
@@ -111,11 +108,10 @@
clazz,
]}
id={post.post.id.toString()}
onclick={(e) => {
onclick={e => {
onClick(e)
}}
onkeydown={(e) => {
// @ts-ignore
onkeydown={e => {
if (e.key == 'Enter') onClick(e)
}}
tabindex="0"
@@ -128,7 +124,7 @@
published={publishedToDate(post.post.published)}
{badges}
subscribed={profile.data?.user?.follows
.map((c) => c.community.id)
.map(c => c.community.id)
.includes(post.community.id)
? 'Subscribed'
: 'NotSubscribed'}
@@ -156,9 +152,7 @@
<PostMediaCompact
post={post.post}
{type}
class="{settings.leftAlign
? 'mr-3'
: 'ml-3'} shrink no-list-margin"
class="{settings.leftAlign ? 'mr-3' : 'ml-3'} shrink no-list-margin"
style="grid-area: media;"
blur={rule == 'blur-sm' ? true : undefined}
{view}
@@ -169,7 +163,6 @@
<PostBody
element="section"
body={post.post.body}
{view}
style="grid-area: body"
class="relative"
/>
+51 -126
View File
@@ -1,43 +1,25 @@
<script lang="ts">
import type { PostView } from 'lemmy-js-client'
import PostVote from './PostVote.svelte'
import { site } from '$lib/lemmy.svelte.js'
import {
ArrowsUpDown,
ArrowTopRightOnSquare,
Bookmark,
BookmarkSlash,
BugAnt,
ChatBubbleOvalLeft,
ChatBubbleOvalLeftEllipsis,
Clock,
EllipsisHorizontal,
Eye,
EyeSlash,
Flag,
GlobeAmericas,
Icon,
MapPin,
Newspaper,
Pencil,
PencilSquare,
Share,
Trash,
UserCircle,
XMark,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { goto } from '$app/navigation'
import { profile } from '$lib/auth.svelte.js'
import {
amMod,
isAdmin,
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import { profile } from '$lib/auth.svelte.js'
import TextProps from '$lib/components/ui/text/TextProps.svelte'
import { publishedToDate } from '$lib/components/util/date'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { t } from '$lib/i18n/translations'
import { instance } from '$lib/instance.svelte'
import { site } from '$lib/lemmy.svelte.js'
import { deleteItem, markAsRead, save } from '$lib/lemmy/contentview.js'
import { communityLink, userLink } from '$lib/lemmy/generic'
import { setSessionStorage } from '$lib/session.js'
import { goto } from '$app/navigation'
import { settings, type View } from '$lib/settings.svelte.js'
import { instanceToURL } from '$lib/util.svelte'
import { feature } from '$lib/version'
import type { PostView } from 'lemmy-js-client'
import {
Button,
Menu,
@@ -47,17 +29,29 @@
Spinner,
toast,
} from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import {
ArrowTopRightOnSquare,
Bookmark,
BookmarkSlash,
BugAnt,
ChatBubbleOvalLeft,
ChatBubbleOvalLeftEllipsis,
EllipsisHorizontal,
Eye,
EyeSlash,
Flag,
GlobeAmericas,
Icon,
MapPin,
Newspaper,
PencilSquare,
Share,
Trash,
UserCircle,
XMark,
} from 'svelte-hero-icons'
import { hidePost, postLink } from './helpers'
import { feature } from '$lib/version'
import { instanceId, instanceToURL } from '$lib/util.svelte'
import { publishedToDate } from '$lib/components/util/date'
import TextProps from '$lib/components/ui/text/TextProps.svelte'
import { communityLink, userLink } from '$lib/lemmy/generic'
import RelativeDate, {
formatRelativeDate,
} from '$lib/components/util/RelativeDate.svelte'
import { instance } from '$lib/instance.svelte'
import PostVote from './PostVote.svelte'
let editing = $state(false)
let saving = $state(false)
@@ -98,7 +92,7 @@
<PostForm
edit
editingPost={post.post}
onsubmit={(e) => {
onsubmit={e => {
editing = false
post = e
onedit?.(e)
@@ -106,7 +100,6 @@
>
{#snippet formtitle()}
<!-- Have the title not exist at all -->
{''}
{/snippet}
</PostForm>
{/await}
@@ -136,7 +129,6 @@
rounding="pill"
target={settings.openLinksInNewTab ? '_blank' : ''}
title={$t('post.actions.comments')}
animations={{ scale: true, large: false }}
>
{@const newComment =
publishedToDate(post.counts.newest_comment_time).getTime() >
@@ -148,7 +140,6 @@
<FormattedNumber number={post.counts.comments} />
</Button>
<div class="flex-1"></div>
{#if settings.debugInfo}
{#if debug}
{#await import('$lib/components/util/debug/DebugObject.svelte') then { default: DebugObject }}
@@ -185,7 +176,7 @@
onclick={async () => {
if (!profile.data?.jwt) return
saving = true
post.saved = await save(post, !post.saved, profile.data?.jwt)
post.saved = await save(post, !post.saved)
saving = false
}}
size="custom"
@@ -195,7 +186,6 @@
loading={saving}
disabled={saving}
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
animations={{ scale: true, large: true }}
>
{#snippet prefix()}
<Icon src={post.saved ? BookmarkSlash : Bookmark} size="16" mini />
@@ -203,13 +193,7 @@
</Button>
{/if}
<Menu
placement="bottom-end"
containerClass="overflow-auto max-h-[400px]"
class="h-8"
targetClass="h-full"
title={$t('post.actions.more.label')}
>
<Menu placement="bottom-end" class="h-8">
{#snippet target()}
<Button
title={$t('post.actions.more.label')}
@@ -224,59 +208,6 @@
{/snippet}
</Button>
{/snippet}
<MenuDivider>{$t('cards.site.stats')}</MenuDivider>
<div class="flex flex-row gap-1 items-center">
<MenuButton class="flex-1">
{#snippet prefix()}
<Icon src={Clock} size="16" micro />
{/snippet}
<span>
{publishedToDate(post.post.published).toLocaleDateString(undefined, {
dateStyle: 'short',
})}
</span>
</MenuButton>
{#if post.post.updated}
{@const editedTime = formatRelativeDate(
publishedToDate(post.post.updated),
{
style: 'long',
},
)}
<MenuButton class="flex-1" aria-label={editedTime}>
{#snippet prefix()}
<Icon src={Pencil} size="16" micro />
{/snippet}
<RelativeDate date={publishedToDate(post.post.updated)} />
</MenuButton>
{/if}
</div>
{#if post.counts.score}
{@const ratio =
post.counts.upvotes / (post.counts.upvotes + post.counts.downvotes)}
<MenuButton
aria-label={$t('aria.vote.score', { default: post.counts.score })}
>
{#snippet prefix()}
<Icon src={ArrowsUpDown} size="16" micro />
{/snippet}
{$t('post.actions.vote.score')}
•
<FormattedNumber
number={post.counts.score}
options={{ notation: 'standard' }}
class="font-medium"
/>
•
<FormattedNumber
number={ratio}
options={{ style: 'percent' }}
class="font-medium {ratio > 0.7
? 'text-blue-700 dark:text-blue-300'
: 'text-red-500'}"
/>
</MenuButton>
{/if}
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
<MenuButton link href={userLink(post.creator)}>
{#snippet prefix()}
@@ -309,11 +240,7 @@
<MenuButton
onclick={async () => {
if (profile.data?.jwt)
post.read = await markAsRead(
post.post,
!post.read,
profile.data.jwt,
)
post.read = await markAsRead(post.post, !post.read)
}}
>
{#snippet prefix()}
@@ -326,11 +253,13 @@
{/if}
<MenuButton
onclick={() => {
navigator.share?.({
url: localShare
? `${instanceToURL(instance.data)}/post/${post.post.id}`
: post.post.ap_id,
}) ??
if (navigator.share)
navigator.share?.({
url: localShare
? `${instanceToURL(instance.data)}/post/${post.post.id}`
: post.post.ap_id,
})
else
navigator.clipboard.writeText(
localShare
? `${instanceToURL(instance.data)}/post/${post.post.id}`
@@ -346,11 +275,11 @@
{$t('post.actions.more.share')}
<div class="flex-1"></div>
{#if !post.post.local}
<div class="flex">
<div class="flex gap-1">
<Button
color={!localShare ? 'primary' : 'secondary'}
size="square-md"
roundingSide="left"
size="square-sm"
rounding="pill"
onclick={() => (localShare = false)}
title={$t('filter.location.global')}
>
@@ -358,8 +287,8 @@
</Button>
<Button
color={localShare ? 'primary' : 'secondary'}
size="square-md"
roundingSide="right"
size="square-sm"
rounding="pill"
onclick={() => (localShare = true)}
title={$t('filter.location.local')}
>
@@ -401,11 +330,7 @@
<MenuButton
onclick={async () => {
if (profile.data?.jwt)
post.post.deleted = await deleteItem(
post,
!post.post.deleted,
profile.data.jwt,
)
post.post.deleted = await deleteItem(post, !post.post.deleted)
}}
color="danger-subtle"
>
@@ -1,6 +1,5 @@
<script lang="ts">
import Markdown from '$lib/components/markdown/Markdown.svelte'
import type { View } from '$lib/settings.svelte'
import { Button } from 'mono-svelte'
import { ChevronDown, Icon } from 'svelte-hero-icons'
@@ -16,7 +15,6 @@
interface Props {
body: string
view?: View
clickThrough?: boolean
element?: string
style?: string
@@ -25,7 +23,6 @@
let {
body,
view = 'cozy',
clickThrough = false,
element: htmlElement = 'div',
style = '',
+23 -14
View File
@@ -20,11 +20,11 @@
const newTitle = title
.toString()
.replace(/^(\[.[^\]]+\])|(\[.[^\]]+\])$/g, (match, content) => {
.replace(/^(\[.[^\]]+\])|(\[.[^\]]+\])$/g, match => {
const contents = match.split(',').map((part: string) => part.trim())
contents
.map((i) => i.replaceAll(/(\[|\])/g, ''))
.map(i => i.replaceAll(/(\[|\])/g, ''))
.forEach((content: string) => {
extracted.push(
textToTag.get(content) ?? {
@@ -44,32 +44,32 @@
<script lang="ts">
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import { Badge, Popover } from 'mono-svelte'
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'
import { publishedToDate } from '$lib/components/util/date'
import RelativeDate, {
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 'lemmy-js-client'
import { Badge, Popover } from 'mono-svelte'
import {
Bookmark,
ExclamationTriangle,
Icon,
LockClosed,
Megaphone,
PaperAirplane,
Pencil,
Tag,
Trash,
PaperAirplane,
type IconSource,
} from 'svelte-hero-icons'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import { settings, type View } from '$lib/settings.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import { t } from '$lib/i18n/translations'
import { Pencil, type IconSource } from 'svelte-hero-icons'
import CommunityHeader from '../community/CommunityHeader.svelte'
import { publishedToDate } from '$lib/components/util/date'
import { profile } from '$lib/auth.svelte'
import { instance } from '$lib/instance.svelte'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
interface Props {
community?: Community | undefined
@@ -83,7 +83,16 @@
edited?: string | undefined
view?: View
// Badges
badges?: any
badges?: {
nsfw: boolean
saved: boolean
featured: boolean
deleted: boolean
removed: boolean
locked: boolean
moderator: boolean
admin: boolean
}
tags?: Tag[]
style?: string
titleClass?: string
+11 -15
View File
@@ -1,6 +1,5 @@
<script lang="ts" module>
import { settings } from '$lib/settings.svelte.js'
export const voteColor = (vote: number, border: boolean = false) =>
export const voteColor = (vote: number) =>
vote == 1
? `bg-linear-to-br from-blue-500 to-indigo-500 dark:from-blue-400 dark:to-indigo-500 text-slate-50 dark:text-zinc-900`
: vote == -1
@@ -17,17 +16,17 @@
</script>
<script lang="ts">
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import type { Post } from 'lemmy-js-client'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
import { profile } from '$lib/auth.svelte.js'
import { vote as voteItem } from '$lib/lemmy/contentview.js'
import { Button, Popover, buttonColor, toast } from 'mono-svelte'
import { site } from '$lib/lemmy.svelte.js'
import { fade, fly } from 'svelte/transition'
import { backOut } from 'svelte/easing'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { t } from '$lib/i18n/translations'
import { site } from '$lib/lemmy.svelte.js'
import { vote as voteItem } from '$lib/lemmy/contentview.js'
import { errorMessage } from '$lib/lemmy/error'
import type { Post } from 'lemmy-js-client'
import { buttonColor, toast } from 'mono-svelte'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
import { backOut } from 'svelte/easing'
import { fly } from 'svelte/transition'
interface Props {
post: Post
@@ -36,7 +35,7 @@
upvotes?: number
downvotes?: number
showCounts?: boolean
children?: import('svelte').Snippet<[any]>
children?: import('svelte').Snippet<[{ vote: number; score: number }]>
}
let {
@@ -51,17 +50,14 @@
let loading = $state(false)
let oldScore = score
const castVote = async (newVote: number) => {
if (!profile.data?.jwt) {
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
return
}
loading = true
oldScore = score
vote = newVote
const res = await voteItem(post, newVote, profile.data.jwt).catch((e) => {
const res = await voteItem(post, newVote).catch(e => {
toast({ content: errorMessage(e), type: 'error' })
return { upvotes: 0, downvotes: 0, score: 0 }
})
@@ -3,24 +3,17 @@
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { settings } from '$lib/settings.svelte.js'
import type { PostView } from 'lemmy-js-client'
import { Badge, Button } from 'mono-svelte'
import { ArchiveBox, Icon, Minus, Plus } from 'svelte-hero-icons'
import { Button } from 'mono-svelte'
import type { Snippet } from 'svelte'
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
interface Props {
posts: PostView[]
community?: boolean
feedData: any
children?: import('svelte').Snippet
[key: string]: any
children?: Snippet
}
let {
posts = $bindable(),
community = false,
feedData,
children,
...rest
}: Props = $props()
let { posts = $bindable(), community = false, children }: Props = $props()
</script>
<ul
@@ -1,8 +1,10 @@
<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'
import { t } from '$lib/i18n/translations'
import { client } from '$lib/lemmy.svelte'
import {
postFeeds,
@@ -10,10 +12,9 @@
type PostFeedID,
} from '$lib/lemmy/postfeed.svelte'
import { settings } from '$lib/settings.svelte.js'
import { t } from '$lib/i18n/translations'
import type { PostView } from 'lemmy-js-client'
import { Button } from 'mono-svelte'
import { onMount, tick, untrack } from 'svelte'
import { onMount, untrack } from 'svelte'
import {
ArchiveBox,
ChevronDoubleUp,
@@ -22,7 +23,6 @@
Plus,
} from 'svelte-hero-icons'
import InfiniteScroll from 'svelte-infinite-scroll'
import VirtualList from '$lib/components/render/VirtualList.svelte'
interface Props {
posts: PostView[]
@@ -45,7 +45,7 @@
scrollToIndex: (index: number, window?: boolean) => void
}>()
let error: any = $state(undefined)
let error = $state()
let loading = $state(false)
let hasMore = $state(true)
@@ -69,7 +69,7 @@
sort: feedData.sort,
type_: feedData.type_,
})
.catch((e) => {
.catch(e => {
throw new Error(e)
})
@@ -90,7 +90,7 @@
}
const callback: IntersectionObserverCallback = (entries, observer) => {
entries.forEach((entry) => {
entries.forEach(entry => {
if (!entry.isIntersecting) return
const element = entry.target as HTMLElement
@@ -130,7 +130,7 @@
const feed = document.getElementById('feed')
if (!feed) return
new MutationObserver((mutations) => {
new MutationObserver(mutations => {
mutations.forEach(({ addedNodes, removedNodes }) => {
addedNodes.forEach(observePost)
removedNodes.forEach(unobservePost)
@@ -176,7 +176,7 @@
bind:restore={postFeeds.value[feedId].clientData}
bind:this={listComp}
>
{#snippet item(_, row, __)}
{#snippet item(row)}
<li
data-index={row}
style={row < 7 ? `--anim-delay: ${row * 100}ms` : ''}
@@ -238,7 +238,6 @@
<div style="border-top-width: 0">
<EndPlaceholder>
{$t('routes.frontpage.endFeed', {
// @ts-ignore
community_name: feedData.community_name ?? 'undefined',
})}
{#snippet action()}
@@ -1,20 +1,11 @@
import { settings } from '$lib/settings.svelte'
import type { PostView } from 'lemmy-js-client'
import { get } from 'svelte/store'
export type PostViewWithCrossposts = PostView & {
withCrossposts: true
crossposts: PostView[]
}
export type PostViewWithoutCrossposts = PostView & { withCrossposts?: false }
const addCrosspostProperty = (
post: PostView,
crossposts: PostView[],
): PostViewWithCrossposts => ({
...post,
crossposts: crossposts,
withCrossposts: true,
})
export const combineCrossposts = (
posts: PostView[],
@@ -26,7 +17,7 @@ export const combineCrossposts = (
const results: (PostViewWithCrossposts | PostViewWithoutCrossposts)[] = []
const seenUrls = new Set<string>()
posts?.forEach((post) => {
posts?.forEach(post => {
if (
!post ||
(settings.hidePosts.deleted && post.post.deleted) ||
@@ -38,7 +29,7 @@ export const combineCrossposts = (
return
}
let existing = urlMap.get(post.post.url)
const existing = urlMap.get(post.post.url)
if (existing) {
existing.withCrossposts = true
if (existing.withCrossposts) {
@@ -1,40 +1,44 @@
<script lang="ts">
import { run, preventDefault } from 'svelte/legacy'
import { preventDefault, run } from 'svelte/legacy'
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
import { client, site } from '$lib/lemmy.svelte.js'
import type { Community, Post, PostView } from 'lemmy-js-client'
import { Select, Spinner, Switch, toast } from 'mono-svelte'
import {
Icon,
Photo,
ArrowPath,
Sparkles,
ChatBubbleBottomCenterText,
Plus,
Language,
Link,
XMark,
} from 'svelte-hero-icons'
import { profile } from '$lib/auth.svelte.js'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { placeholders, uploadImage } from '$lib/util.svelte.js'
import { Checkbox, TextInput } from 'mono-svelte'
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
import { Button } from 'mono-svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import { t } from '$lib/i18n/translations'
import { slide } from 'svelte/transition'
import { feature } from '$lib/version'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import ErrorContainer, {
clearErrorScope,
pushError,
} from '$lib/components/error/ErrorContainer.svelte'
import { errorMessage } from '$lib/lemmy/error'
import FreeTextInput from '$lib/components/input/FreeTextInput.svelte'
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { t } from '$lib/i18n/translations'
import { client, site } from '$lib/lemmy.svelte.js'
import { errorMessage } from '$lib/lemmy/error'
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
import { placeholders } from '$lib/util.svelte.js'
import type { Community, Post, PostView } from 'lemmy-js-client'
import {
Button,
Select,
Spinner,
Switch,
TextInput,
toast,
} from 'mono-svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import { onDestroy, onMount } from 'svelte'
import {
ArrowPath,
ChatBubbleBottomCenterText,
Icon,
Language,
Link,
Photo,
Plus,
Sparkles,
XMark,
} from 'svelte-hero-icons'
import { slide } from 'svelte/transition'
interface Props {
edit?: boolean
@@ -82,7 +86,6 @@
let data = $state(passedData)
// weird select menu language handling
// @ts-ignore
$effect(() => {
if (data.language_id === '') data.language_id = undefined
})
@@ -100,7 +103,6 @@
data.nsfw = editingPost.nsfw
data.alt_text = editingPost.alt_text
data.thumbnail = editingPost.thumbnail_url
// @ts-ignore
data.language_id = editingPost.language_id.toString()
}
@@ -115,12 +117,12 @@
limit: 40,
})
communities = list.communities.map((c) => c.community)
communities = list.communities.map(c => c.community)
}
})
onDestroy(() => {
// @ts-ignore
// @ts-expect-error TODO get rid of sessionStorage stuff
if (saveDraft) setSessionStorage('postDraft', data)
})
@@ -137,7 +139,7 @@
if (data.url && data.url != '') {
try {
new URL(data.url)
} catch (err) {
} catch {
pushError({
message: $t('toast.invalidURL'),
scope: 'post-form',
@@ -190,7 +192,7 @@
onsubmit?.(post.post_view)
}
} catch (err) {
pushError({ message: errorMessage(err as any), scope: 'post-form' })
pushError({ message: errorMessage(err as string), scope: 'post-form' })
data.loading = false
}
}
@@ -212,7 +214,7 @@
if (res.metadata.description)
data.body = res.metadata.description
.split('\n')
.map((l) => `> ${l}`)
.map(l => `> ${l}`)
.join('\n')
toast({
@@ -221,7 +223,7 @@
action: () => (data = oldData),
duration: 15 * 1000,
})
} catch (e) {
} catch {
pushError({
message: $t('toast.failGenerateTitle'),
scope: 'post-form',
@@ -234,7 +236,7 @@
if (!url) return false
try {
new URL(url)
} catch (e) {
} catch {
return false
}
return true
@@ -258,7 +260,7 @@
<UploadModal
bind:open={uploadingImage}
multiple={false}
onupload={(e) => {
onupload={e => {
if (e) data.url = e[0]
uploadingImage = false
}}
@@ -282,7 +284,7 @@
listing_type="All"
label={$t('form.post.community')}
required
onselect={(e) => {
onselect={e => {
const c = e
if (!c) {
data.community = null
@@ -399,7 +401,9 @@
const url = new URL(await navigator.clipboard.readText())
data.url = url.toString()
} catch (e) {}
} catch {
/* empty */
}
}}
size="sm"
rounding="pill"
@@ -472,9 +476,9 @@
toast({ content: $t('toast.restoredFromDraft') })
const draft = getSessionStorage('postDraft')
if (draft && !edit) {
// @ts-ignore
// @ts-expect-error TODO get rid of session storage
draft.loading = false
// @ts-ignore
// @ts-expect-error TODO get rid of session storage
data = draft
}
}}
+6 -6
View File
@@ -1,11 +1,8 @@
import { profile } from '$lib/auth.svelte'
import { instance } from '$lib/instance.svelte'
import { client } from '$lib/lemmy.svelte.js'
import type { View } from '$lib/settings.svelte'
import { isImage, isVideo } from '$lib/ui/image'
import { canParseUrl, findClosestNumber } from '$lib/util.svelte'
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
import { get } from 'svelte/store'
import type { CommentView, PersonView, Post } from 'lemmy-js-client'
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
me.person.id == comment.creator.id
@@ -15,6 +12,9 @@ export const bestImageURL = (
compact: boolean = true,
width: number = 1024,
) => {
if (compact) {
/* empty */
}
if (post.url) return optimizeImageURL(post.url, width)
else if (post.thumbnail_url)
return optimizeImageURL(post.thumbnail_url, width)
@@ -67,7 +67,7 @@ export const postLink = (post: Post) =>
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
export type IframeType = 'youtube' | 'video' | 'none'
export const mediaType = (url?: string, view: View = 'cozy'): MediaType => {
export const mediaType = (url?: string): MediaType => {
if (url) {
if (isImage(url)) return 'image'
if (isVideo(url)) return 'iframe'
@@ -89,7 +89,7 @@ export async function hidePost(
hide: boolean,
jwt: string,
): Promise<boolean> {
const res = await client({ auth: jwt }).hidePost({
await client({ auth: jwt }).hidePost({
hide: hide,
post_ids: [id],
})
@@ -1,31 +1,22 @@
<script lang="ts">
import Link, { parseURL } from '$lib/components/input/Link.svelte'
import { Button, Material } from 'mono-svelte'
import {
CheckBadge,
ChevronDown,
Icon,
Link as LinkIcon,
} from 'svelte-hero-icons'
import { optimizeImageURL } from '../helpers'
import { t } from '$lib/i18n/translations'
import { parseURL } from '$lib/components/input/Link.svelte'
import type { View } from '$lib/settings.svelte'
import { Button, Material } from 'mono-svelte'
import { optimizeImageURL } from '../helpers'
interface Props {
url: string
thumbnail_url?: string | undefined
thumbnail_url?: string
nsfw?: boolean
embed_title?: string | undefined
embed_description?: string | undefined
embed_title?: string
view?: View
}
let {
url,
thumbnail_url = undefined,
thumbnail_url,
nsfw = false,
embed_title = undefined,
embed_description = undefined,
embed_title,
view = 'cozy',
}: Props = $props()
@@ -27,15 +27,14 @@
</script>
<script lang="ts">
import { settings } from '$lib/settings.svelte'
import {
Icon,
PuzzlePiece,
VideoCamera,
type IconSource,
} from 'svelte-hero-icons'
import { optimizeImageURL, type IframeType, type MediaType } from '../helpers'
import { settings } from '$lib/settings.svelte'
import { get } from 'svelte/store'
import { optimizeImageURL, type IframeType } from '../helpers'
const urlToEmbed = (inputUrl: string) => {
if (type == 'video') {
@@ -89,7 +88,7 @@
type?: IframeType
thumbnail?: string | undefined
url: string
opened?: any
opened?: boolean
autoplay?: boolean
class?: string
}
@@ -1,12 +1,10 @@
<script lang="ts">
import { stopPropagation } from 'svelte/legacy'
import { settings, type View } from '$lib/settings.svelte'
import type { Post } from 'lemmy-js-client'
import { bestImageURL, postLink } from '../helpers'
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
import { settings } from '$lib/settings.svelte'
import type { Post } from 'lemmy-js-client'
import { Button, modal } from 'mono-svelte'
import { onMount } from 'svelte'
import { bestImageURL, postLink } from '../helpers'
interface Props {
post: Post
@@ -54,7 +52,6 @@
srcset={bestImageURL(post, false, 1536)}
media="(max-width: 1024px)"
/>
<!-- svelte-ignore a11y_missing_attribute -->
<img
src={bestImageURL(post, false, -1)}
loading="lazy"
@@ -74,11 +71,11 @@
class="absolute bottom-0 left-0 right-0 flex justify-between items-center
rounded-full ml-auto w-max m-2 p-0 gap-1
*:bg-white *:border *:border-slate-200 dark:*:border-zinc-800 dark:*:bg-zinc-900"
onclick={(e) => e.stopPropagation()}
onclick={e => e.stopPropagation()}
>
{#if post.alt_text}
<Button
onclick={(e) => {
onclick={e => {
e.stopPropagation()
modal({
title: 'Alt',
@@ -1,21 +1,12 @@
<script lang="ts">
import Empty from '$lib/components/helper/Empty.svelte'
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
import {
bestImageURL,
postLink,
type MediaType,
iframeType,
type MediaType,
} from '$lib/components/lemmy/post/helpers.js'
import ExpandableImage, {
showImage,
} from '$lib/components/ui/ExpandableImage.svelte'
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
import { settings, type View } from '$lib/settings.svelte.js'
import type { Post } from 'lemmy-js-client'
import PostIframe from './PostIframe.svelte'
import { Button, Material, modal } from 'mono-svelte'
import { onMount } from 'svelte'
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
import PostImage from './PostImage.svelte'
interface Props {
@@ -7,17 +7,16 @@
} from '$lib/components/lemmy/post/helpers.js'
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
import { settings, type View } from '$lib/settings.svelte.js'
import { t } from '$lib/i18n/translations'
import { isImage } from '$lib/ui/image'
import type { Post } from 'lemmy-js-client'
import { Material, modal, Popover } from 'mono-svelte'
import { modal } from 'mono-svelte'
import Button from 'mono-svelte/button/Button.svelte'
import {
DocumentText,
ExclamationTriangle,
Icon,
Link,
VideoCamera,
ExclamationTriangle,
} from 'svelte-hero-icons'
const thumbnailSize = (view: View) =>
@@ -68,6 +67,7 @@
}}
role="button"
tabindex="0"
class="cursor-pointer"
>
{#if post.thumbnail_url || isImage(post.url)}
<div class="relative overflow-hidden rounded-xl">
@@ -75,16 +75,20 @@
<img
src={optimizeImageURL(post.thumbnail_url || post.url || '', 256)}
loading="lazy"
class="object-cover relative overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl
transition-colors {size}"
class={[
'object-cover relative overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl transition-colors',
size,
]}
alt={post.alt_text ?? ' '}
class:blur-xl={blur}
/>
{#if type != 'image'}
<div
class="absolute w-8 h-8 m-1 bottom-0 left-0 rounded-xl text-slate-800 dark:text-zinc-200
bg-slate-25 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-700
grid place-items-center"
class={[
'absolute w-8 h-8 m-1 bottom-0 left-0 rounded-xl text-slate-800 dark:text-zinc-200',
'bg-slate-25 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-700',
'grid place-items-center',
]}
>
<Icon
src={type == 'iframe' ? VideoCamera : Link}
@@ -109,10 +113,13 @@
{/if}
{:else}
<div
class="object-cover overflow-hidden bg-slate-50 dark:bg-zinc-900 rounded-xl
border border-slate-200 dark:border-zinc-800 group-hover/media:border-slate-400
dark:group-hover/media:border-zinc-600 transition-colors text-slate-400 dark:text-zinc-600 grid
place-items-center {size}"
class={[
'object-cover overflow-hidden bg-slate-50 dark:bg-zinc-900 rounded-xl',
'border border-slate-200 dark:border-zinc-800 group-hover/media:border-slate-400',
'dark:group-hover/media:border-zinc-600 transition-colors text-slate-400 dark:text-zinc-600 grid',
'place-items-center',
size,
]}
>
<Icon
src={type == 'embed'
@@ -1,7 +1,7 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import { getClient } from '$lib/lemmy.svelte.js'
import type { Community, ListingType, Person } from 'lemmy-js-client'
import type { ListingType, Person } from 'lemmy-js-client'
import { MenuButton, Search } from 'mono-svelte'
import { createEventDispatcher } from 'svelte'
import { Icon, XCircle } from 'svelte-hero-icons'
@@ -12,8 +12,7 @@
instance?: string | undefined
listing_type?: ListingType
showWhenEmpty?: boolean
onselect?: (e: any) => void
[key: string]: any
onselect?: (e: Person) => void
}
let {
@@ -28,7 +27,7 @@
</script>
<Search
search={async (q) => {
search={async q => {
const results = await getClient(instance).search({
q: q || ' ',
type_: 'Users',
@@ -37,9 +36,9 @@
sort: 'TopAll',
})
return results.users.map((c) => c.person)
return results.users.map(c => c.person)
}}
extractName={(c) => `${c.name}@${new URL(c.actor_id).hostname}`}
extractName={c => `${c.name}@${new URL(c.actor_id).hostname}`}
bind:query={q}
{...rest}
>
@@ -1,15 +1,8 @@
<script lang="ts">
import type { PersonView } from 'lemmy-js-client'
import {
ChatBubbleOvalLeftEllipsis,
Icon,
PencilSquare,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import { userLink } from '$lib/lemmy/generic'
import Avatar from '$lib/components/ui/Avatar.svelte'
import type { PersonView } from 'lemmy-js-client'
interface Props {
user: PersonView
@@ -10,7 +10,7 @@
} else {
return {}
}
} catch (e) {
} catch {
return {}
}
}
@@ -61,7 +61,7 @@
badges?: boolean
inComment?: boolean
showInstance?: boolean
displayName?: any
displayName?: boolean
instanceClass?: string
class?: string
children?: import('svelte').Snippet
@@ -1,31 +0,0 @@
<script lang="ts">
import { preventDefault } from 'svelte/legacy'
import { goto } from '$app/navigation'
import { t } from '$lib/i18n/translations'
import { TextInput } from 'mono-svelte'
let query: string = $state('')
let loading = $state(false)
function search() {
loading = true
goto(`/search?q=${query}`).then(() => (loading = false))
}
interface Props {
class?: string
children?: import('svelte').Snippet<[any]>
}
let { class: clazz = '', children }: Props = $props()
</script>
<form onsubmit={preventDefault(search)} class="w-full h-full {clazz}">
<TextInput
bind:value={query}
class="w-full h-full {clazz}"
placeholder={$t('nav.search')}
autofocus
/>
</form>
{@render children?.({ search, loading })}