migrate: change settings from a store to a state

This commit is contained in:
Xylight committed 2024-10-25 21:09:32 -07:00
1 parent ffcd9faa96
commit d597349887
128 files changed
+1010 -1144

No files matched your search

+9 -10
View File
@@ -3,7 +3,7 @@
import { isImage, isVideo } from '$lib/ui/image.js'
import { getInstance } from '$lib/lemmy.js'
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
import { userSettings } from '$lib/settings.js'
import { settings } from '$lib/settings.svelte.js'
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
import PostMeta, {
parseTags,
@@ -28,18 +28,17 @@
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'
import { profile } from '$lib/auth.svelte'
import { goto } from '$app/navigation'
function getTagRule(tags: Tag[]): 'blur' | 'hide' | undefined {
const tagContent = tags.map((t) => t.content.toLowerCase())
let rule: 'blur' | 'hide' | undefined
if ($userSettings.nsfwBlur && (post.post.nsfw || post.community.nsfw))
if (settings.nsfwBlur && (post.post.nsfw || post.community.nsfw))
rule = 'blur'
tagContent.forEach((tag) => {
if ($userSettings.tagRules?.[tag])
rule = $userSettings.tagRules?.[tag] ?? rule
if (settings.tagRules?.[tag]) rule = settings.tagRules?.[tag] ?? rule
if (rule == 'hide') return rule
})
@@ -69,7 +68,7 @@
post,
actions = true,
hideCommunity = false,
view = $userSettings.view,
view = settings.view,
style = '',
class: clazz = '',
badges,
@@ -79,13 +78,13 @@
let type = $derived(mediaType(post.post.url, view))
let rule = $derived(getTagRule(tags.tags))
let hideTitle = $derived(
$userSettings.posts.deduplicateEmbed &&
settings.posts.deduplicateEmbed &&
post.post.embed_title == post.post.name &&
view != 'compact' &&
type != 'iframe',
)
let hideBody = $derived(
$userSettings.posts.deduplicateEmbed &&
settings.posts.deduplicateEmbed &&
post.post.embed_description == post.post.body &&
view != 'compact',
)
@@ -102,7 +101,7 @@
<div
class="post relative max-w-full min-w-0 w-full cursor-pointer outline-none
group
{$userSettings.leftAlign ? 'left-align' : ''}
{settings.leftAlign ? 'left-align' : ''}
{view == 'compact' ? 'py-3 list-type compact' : ''}
{view == 'list' ? 'py-5 list-type' : ''}
{view == 'cozy' ? 'py-5 flex flex-col gap-2' : ''}
@@ -168,7 +167,7 @@
<PostMediaCompact
post={post.post}
{type}
class="{$userSettings.leftAlign
class="{settings.leftAlign
? 'mr-3'
: 'ml-3'} flex-shrink no-list-margin"
style="grid-area: media;"
@@ -39,11 +39,11 @@
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import { profile } from '$lib/auth.js'
import { profile } from '$lib/auth.svelte.js'
import { deleteItem, markAsRead, save } from '$lib/lemmy/contentview.js'
import { setSessionStorage } from '$lib/session.js'
import { goto } from '$app/navigation'
import { userSettings, type View } from '$lib/settings.js'
import { settings, type View } from '$lib/settings.svelte.js'
import {
Button,
Menu,
@@ -59,7 +59,7 @@
import { hidePost, postLink } from './helpers'
import { feature } from '$lib/version'
import Switch from '$lib/components/input/Switch.svelte'
import { instanceId, instanceToURL } from '$lib/util'
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'
@@ -129,15 +129,15 @@
<footer
class="flex flex-row gap-2 items-center flex-shrink-0 {buttonHeight}"
class:flex-row-reverse={$userSettings.posts.reverseActions}
class:flex-row-reverse={settings.posts.reverseActions}
{style}
>
<PostVote
post={post.post}
bind:vote={post.my_vote}
bind:score={post.counts.score}
bind:upvotes={post.counts.upvotes}
bind:downvotes={post.counts.downvotes}
vote={post.my_vote}
score={post.counts.score}
upvotes={post.counts.upvotes}
downvotes={post.counts.downvotes}
showCounts={$profile?.user?.local_user_view?.local_user?.show_scores ??
true}
/>
@@ -148,7 +148,7 @@
class="!text-inherit h-full px-3 relative"
color="ghost"
rounding="pill"
target={$userSettings.openLinksInNewTab ? '_blank' : ''}
target={settings.openLinksInNewTab ? '_blank' : ''}
title={$t('post.actions.comments')}
animations={{ scale: true, large: false }}
>
@@ -163,7 +163,7 @@
</Button>
<div class="flex-1"></div>
{#if $userSettings.debugInfo}
{#if settings.debugInfo}
{#if debug}
{#await import('$lib/components/util/debug/DebugObject.svelte') then { default: DebugObject }}
<DebugObject object={post} bind:open={debug} />
@@ -378,7 +378,7 @@
</div>
{/if}
</MenuButton>
{#if post.post.body && $userSettings.translator}
{#if post.post.body && settings.translator}
<MenuButton
on:click={() => {
// @ts-ignore
@@ -397,7 +397,7 @@
on:click={() => {
setSessionStorage('postDraft', {
body: `${
$userSettings.crosspostOriginalLink
settings.crosspostOriginalLink
? `cross-posted from: ${post.post.ap_id}`
: ``
}\n${
+7 -11
View File
@@ -1,22 +1,17 @@
<script lang="ts">
import Markdown from '$lib/components/markdown/Markdown.svelte'
import type { View } from '$lib/settings'
import type { View } from '$lib/settings.svelte'
import { Button } from 'mono-svelte'
import { ChevronDown, Icon } from 'svelte-hero-icons'
let expanded = $state(false)
let element: Element = $state()
let element: Element | undefined = $state()
function isOverflown(element: Element, body: string = '') {
if (!element) return
let overflows =
if (!element) return false
return (
element.scrollHeight > element.clientHeight ||
element.scrollWidth > element.clientWidth
if (!overflows) expanded = true
else expanded = false
return overflows
)
}
interface Props {
@@ -37,7 +32,8 @@
class: clazz = '',
}: Props = $props()
let overflows = $derived(isOverflown(element, body))
let overflows = $derived(element ? isOverflown(element, body) : false)
let expanded = $state(false)
</script>
<svelte:element
@@ -65,7 +65,7 @@
} from 'svelte-hero-icons'
import { getInstance } from '$lib/lemmy.js'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import { userSettings, type View } from '$lib/settings'
import { settings, type View } from '$lib/settings.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import { t } from '$lib/translations'
import { Pencil, type IconSource } from 'svelte-hero-icons'
@@ -315,11 +315,11 @@
href="/post/{getInstance()}/{id}"
class="inline hover:underline
hover:text-primary-900 hover:dark:text-primary-100 transition-colors max-[480px]:!mt-0
{$userSettings.font == 'satoshi/nunito'
{settings.font == 'satoshi/nunito'
? 'font-display font-semibold'
: 'font-medium'} {titleClass}"
class:text-slate-600={$userSettings.markReadPosts && read}
class:dark:text-zinc-400={$userSettings.markReadPosts && read}
class:text-slate-600={settings.markReadPosts && read}
class:dark:text-zinc-400={settings.markReadPosts && read}
class:text-base={view == 'compact'}
class:text-lg={view != 'compact'}
style="grid-area: title;"
@@ -1,5 +1,5 @@
<script lang="ts" module>
import { userSettings } from '$lib/settings.js'
import { settings } from '$lib/settings.svelte.js'
export const voteColor = (vote: number, border: boolean = false) =>
vote == 1
? `bg-gradient-to-br from-blue-500 to-indigo-500 dark:from-blue-400 dark:to-indigo-500 text-slate-50 dark:text-zinc-900`
@@ -20,7 +20,7 @@
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.js'
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.js'
@@ -1,13 +1,13 @@
<script lang="ts">
import Post from '$lib/components/lemmy/post/Post.svelte'
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { userSettings } from '$lib/settings.js'
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 { expoOut } from 'svelte/easing'
import { fly, slide } from 'svelte/transition'
import { combineCrossposts } from './crosspost'
import { combineCrossposts } from './crosspost.svelte'
interface Props {
posts: PostView[]
@@ -32,7 +32,7 @@
</script>
<ul
class="flex flex-col list-none {$userSettings.view == 'card'
class="flex flex-col list-none {settings.view == 'card'
? 'gap-3 md:gap-4'
: 'divide-y'} divide-slate-200 dark:divide-zinc-800"
>
@@ -53,14 +53,14 @@
</div>
{:else}
{#each combinedPosts as post, index}
{#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
{#if !(settings.hidePosts.deleted && post.post.deleted) && !(settings.hidePosts.removed && post.post.removed)}
<li class="relative post-container">
<Post
hideCommunity={community}
view={(post.post.featured_community || post.post.featured_local) &&
$userSettings.posts.compactFeatured
settings.posts.compactFeatured
? 'compact'
: $userSettings.view}
: settings.view}
{post}
class="transition-all duration-250"
on:hide={() => {
@@ -102,14 +102,14 @@
>
<span
class="text-sm flex flex-row gap-2 items-center"
class:my-4={$userSettings.view == 'card'}
class:my-4={settings.view == 'card'}
>
Crossposts <hr class="w-full dark:border-zinc-800" />
{post.crossposts.length}
</span>
{#each post.crossposts as crosspost, index}
<div class="w-full transition-all mb-4">
<Post post={crosspost} view={$userSettings.view} />
<Post post={crosspost} view={settings.view} />
</div>
{/each}
</div>
@@ -3,7 +3,7 @@
import Post from '$lib/components/lemmy/post/Post.svelte'
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { userSettings } from '$lib/settings.js'
import { settings } from '$lib/settings.svelte.js'
import type {
GetPostsResponse,
ListingType,
@@ -29,7 +29,7 @@
type SvelteVirtualizer,
} from '@tanstack/svelte-virtual'
import { afterNavigate, beforeNavigate } from '$app/navigation'
import { combineCrossposts } from './crosspost'
import { combineCrossposts } from './crosspost.svelte'
import { client } from '$lib/lemmy'
import {
postFeeds,
@@ -199,7 +199,7 @@
<!-- <svelte:window on:keydown={handleKeydown} /> -->
<ul
class="flex flex-col list-none {$userSettings.view == 'card'
class="flex flex-col list-none {settings.view == 'card'
? 'gap-3 md:gap-4'
: 'divide-y'} divide-slate-200 dark:divide-zinc-800"
>
@@ -247,9 +247,9 @@
hideCommunity={community}
view={(posts[row.index]?.post.featured_community ||
posts[row.index]?.post.featured_local) &&
$userSettings.posts.compactFeatured
settings.posts.compactFeatured
? 'compact'
: $userSettings.view}
: settings.view}
{post}
class="transition-all duration-250"
on:hide={() => {
@@ -263,7 +263,7 @@
</div>
{/if}
{#if $userSettings.infiniteScroll && browser}
{#if settings.infiniteScroll && browser}
{#if error}
<div
class="flex flex-col justify-center items-center
@@ -1,4 +1,4 @@
import { userSettings } from '$lib/settings.svelte'
import { settings } from '$lib/settings.svelte'
import type { PostView } from 'lemmy-js-client'
import { get } from 'svelte/store'
@@ -29,8 +29,8 @@ export const combineCrossposts = (
posts?.forEach((post) => {
if (
!post ||
(get(userSettings).hidePosts.deleted && post.post.deleted) ||
(get(userSettings).hidePosts.removed && post.post.removed)
(settings.hidePosts.deleted && post.post.deleted) ||
(settings.hidePosts.removed && post.post.removed)
)
return
if (!post?.post?.url) {
@@ -16,9 +16,9 @@
Link,
XMark,
} from 'svelte-hero-icons'
import { profile } from '$lib/auth.js'
import { profile } from '$lib/auth.svelte.js'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { placeholders, uploadImage } from '$lib/util.js'
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'
+1 -1
View File
@@ -1,7 +1,7 @@
import { client, getInstance } from '$lib/lemmy.js'
import type { View } from '$lib/settings.svelte'
import { isImage, isVideo } from '$lib/ui/image'
import { canParseUrl, findClosestNumber } from '$lib/util'
import { canParseUrl, findClosestNumber } from '$lib/util.svelte'
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
@@ -10,7 +10,7 @@
import { optimizeImageURL } from '../helpers'
import PostLinkSources from './PostLinkSources.svelte'
import { t } from '$lib/translations'
import type { View } from '$lib/settings'
import type { View } from '$lib/settings.svelte'
interface Props {
url: string
@@ -5,10 +5,10 @@
return 'www.youtube-nocookie.com'
}
case 'invidious': {
return get(userSettings).embeds.invidious || 'yewtu.be'
return settings.embeds.invidious || 'yewtu.be'
}
case 'piped': {
return get(userSettings).embeds.piped || 'piped.video'
return settings.embeds.piped || 'piped.video'
}
}
}
@@ -34,7 +34,7 @@
type IconSource,
} from 'svelte-hero-icons'
import { optimizeImageURL, type IframeType, type MediaType } from '../helpers'
import { userSettings } from '$lib/settings'
import { settings } from '$lib/settings.svelte'
import { get } from 'svelte/store'
const urlToEmbed = (inputUrl: string) => {
@@ -50,7 +50,7 @@
if (autoplay) url.searchParams.set('autoplay', '1')
return `https://${youtubeDomain(
$userSettings.embeds.youtube,
settings.embeds.youtube,
)}/embed/${videoID}?${url.searchParams.toString()}`
}
@@ -98,8 +98,8 @@
type = 'none',
thumbnail = undefined,
url,
opened = $bindable(!$userSettings.embeds.clickToView),
autoplay = $userSettings.embeds.clickToView,
opened = $bindable(!settings.embeds.clickToView),
autoplay = settings.embeds.clickToView,
class: clazz = '',
}: Props = $props()
@@ -1,7 +1,7 @@
<script lang="ts">
import { stopPropagation } from 'svelte/legacy'
import { userSettings, type View } from '$lib/settings'
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'
@@ -24,7 +24,7 @@
<!--disabled preloads here since most people will hover over every image while scrolling-->
<svelte:element
this={$userSettings.expandImages ? 'button' : 'a'}
this={settings.expandImages ? 'button' : 'a'}
href={postLink(post)}
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
data-sveltekit-preload-data="off"
@@ -10,7 +10,7 @@
import ExpandableImage, {
showImage,
} from '$lib/components/ui/ExpandableImage.svelte'
import { userSettings } from '$lib/settings.js'
import { settings } from '$lib/settings.svelte.js'
import type { Post } from 'lemmy-js-client'
import PostIframe from './PostIframe.svelte'
import { Button, Material, modal } from 'mono-svelte'
@@ -31,7 +31,7 @@
post,
type = 'none',
opened = undefined,
blur = post.nsfw && $userSettings.nsfwBlur,
blur = post.nsfw && settings.nsfwBlur,
}: Props = $props()
</script>
@@ -6,7 +6,7 @@
type MediaType,
} from '$lib/components/lemmy/post/helpers.js'
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
import { userSettings, type View } from '$lib/settings.js'
import { settings, type View } from '$lib/settings.svelte.js'
import { isImage } from '$lib/ui/image'
import type { Post } from 'lemmy-js-client'
import { Material, Popover } from 'mono-svelte'
@@ -34,7 +34,7 @@
post,
type = 'none',
view = 'cozy',
blur = post.nsfw && $userSettings.nsfwBlur,
blur = post.nsfw && settings.nsfwBlur,
style = '',
class: clazz = '',
}: Props = $props()
@@ -50,7 +50,7 @@
{#if post.alt_text}
<Popover
openOnHover
placement={$userSettings.leftAlign ? 'bottom-start' : 'bottom-end'}
placement={settings.leftAlign ? 'bottom-start' : 'bottom-end'}
>
{#snippet target()}
<Material
@@ -68,7 +68,7 @@
</Popover>
{/if}
<svelte:element
this={!$userSettings.expandImages || type != 'image' ? 'a' : 'button'}
this={!settings.expandImages || type != 'image' ? 'a' : 'button'}
href={postLink(post)}
onclick={() => {
if (type == 'image') {