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

@@ -13,7 +13,7 @@
PlusCircle,
MinusCircle,
} from 'svelte-hero-icons'
import type { CommentNodeI } from './comments'
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'
@@ -21,7 +21,7 @@
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
import { getClient } from '$lib/lemmy.js'
import { Disclosure, toast } from 'mono-svelte'
import { profile } from '$lib/auth.js'
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'
@@ -110,7 +110,7 @@
<form onsubmit={preventDefault(save)} class="contents">
<CommentForm
postId={node.comment_view.comment.id}
bind:value={newComment}
value={newComment}
actions={false}
preview={true}
on:confirm={save}
@@ -235,7 +235,7 @@
</div>
{#if actions}
<CommentActions
bind:comment={node.comment_view}
comment={node.comment_view}
bind:replying
on:edit={() => (editing = true)}
disabled={node.comment_view.banned_from_community ||
@@ -259,7 +259,6 @@
children: [],
comment_view: e.detail.comment_view,
depth: node.depth + 1,
ui: {},
},
...node.children,
]
@@ -22,13 +22,13 @@
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
import { profile } from '$lib/auth.js'
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/translations'
import Translation from '$lib/components/translate/Translation.svelte'
import { text } from '$lib/components/translate/translation'
import { userSettings } from '$lib/settings'
import { settings } from '$lib/settings.svelte'
interface Props {
comment: CommentView
@@ -54,12 +54,12 @@
<div
class="flex flex-row items-center gap-0.5 h-7 w-full"
class:flex-row-reverse={$userSettings.posts.reverseActions}
class:flex-row-reverse={settings.posts.reverseActions}
>
<CommentVote
bind:upvotes={comment.counts.upvotes}
bind:downvotes={comment.counts.downvotes}
bind:vote={comment.my_vote}
upvotes={comment.counts.upvotes}
downvotes={comment.counts.downvotes}
vote={comment.my_vote}
commentId={comment.comment.id}
/>
<Button
@@ -101,7 +101,7 @@
<Icon src={Square2Stack} mini size="16" />
<div>{$t('comment.actions.link')}</div>
</MenuButton>
{#if $userSettings.translator}
{#if settings.translator}
<MenuButton
on:click={() => {
// @ts-ignore
@@ -3,10 +3,10 @@
import { getClient } from '$lib/lemmy.js'
import { createEventDispatcher } from 'svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import { profile } from '$lib/auth.js'
import { profile } from '$lib/auth.svelte.js'
import { toast } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { placeholders } from '$lib/util.js'
import { placeholders } from '$lib/util.svelte.js'
import { Button } from 'mono-svelte'
import { t } from '$lib/translations'
import { errorMessage } from '$lib/lemmy/error'
@@ -3,7 +3,7 @@
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
import { publishedToDate } from '$lib/components/util/date.js'
import { getInstance } from '$lib/lemmy.js'
import { userSettings } from '$lib/settings.js'
import { settings } from '$lib/settings.svelte.js'
import { t } from '$lib/translations'
import type { CommentView } from 'lemmy-js-client'
import { Button, Material } from 'mono-svelte'
@@ -20,7 +20,7 @@
let {
comment,
view = $userSettings.view,
view = settings.view,
community = false,
meta = true,
class: clazz = '',
@@ -2,7 +2,7 @@
import { run } from 'svelte/legacy'
import type { Post } from 'lemmy-js-client'
import type { CommentNodeI } from './comments'
import type { CommentNodeI } from './comments.svelte'
import { createWindowVirtualizer } from '@tanstack/svelte-virtual'
import Comments from './Comments.svelte'
import { browser } from '$app/environment'
@@ -24,7 +24,7 @@
estimateSize: () => 30,
scrollMargin: virtualListEl?.offsetTop,
initialRect: {
height: 1500,
height: browser ? 1 : 1500,
width: 99999,
},
overscan: 5,
@@ -35,9 +35,11 @@
let items = $derived($virtualizer.getVirtualItems())
run(() => {
if (virtualItemEls.length)
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
const updateItems = () =>
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
$effect(() => {
if (virtualItemEls) updateItems()
})
onMount(() => {
@@ -8,8 +8,8 @@
Icon,
} from 'svelte-hero-icons'
import { getClient, site } from '$lib/lemmy'
import { userSettings } from '$lib/settings'
import { profile } from '$lib/auth.js'
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'
@@ -1,22 +1,15 @@
<script lang="ts">
import Comments from './Comments.svelte'
import Comment from './Comment.svelte'
import { buildCommentsTree, type CommentNodeI } from './comments'
import { buildCommentsTree, type CommentNodeI } from './comments.svelte'
import { page } from '$app/stores'
import { onMount, setContext } from 'svelte'
import {
ChevronDoubleDown,
ChevronDown,
Icon,
Plus,
PlusCircle,
ArrowDownCircle,
} from 'svelte-hero-icons'
import { Icon, ArrowDownCircle } from 'svelte-hero-icons'
import { getClient } from '$lib/lemmy.js'
import type { CommentView, Post } from 'lemmy-js-client'
import { fly } from 'svelte/transition'
import { toast } from 'mono-svelte'
import { profile } from '$lib/auth.js'
import { profile } from '$lib/auth.svelte.js'
import { Button } from 'mono-svelte'
import { afterNavigate, goto } from '$app/navigation'
import { backOut, expoOut } from 'svelte/easing'
@@ -121,8 +114,7 @@
{#each nodes as node, index (node.comment_view.comment.id)}
<Comment
postId={post.id}
bind:node={nodes[index]}
bind:open={node.ui.open}
node={nodes[index]}
op={post.creator_id == node.comment_view.creator.id}
contentClass="pl-3 {node.children.length > 0 ||
node.comment_view.counts.child_count > 0
@@ -130,7 +122,7 @@
: ''} ml-3 border-slate-200 dark:border-zinc-800"
>
{#if node.children?.length > 0}
<Comments {post} bind:nodes={nodes[index].children} isParent={false} />
<Comments {post} nodes={nodes[index].children} isParent={false} />
{/if}
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
<svelte:element
@@ -5,9 +5,6 @@ export interface CommentNodeI {
children: Array<CommentNodeI>
depth: number
loading?: boolean
ui: {
open?: boolean
}
}
function getCommentParentId(comment?: Comment): number | undefined {
@@ -40,10 +37,7 @@ export function buildCommentsTree(
const node: CommentNodeI = {
comment_view,
children: [],
depth: depth,
ui: {
open: true,
},
depth: depth
}
min_depth = Math.min(min_depth, depth)
if (filter(comment_view)) {
@@ -109,7 +103,6 @@ export function insertCommentIntoTree(
comment_view: cv,
children: [],
depth: 0,
ui: {},
}
const parentId = getCommentParentId(cv.comment)