cleanup: $lib/feature/comment
This commit is contained in:
5 files changed
+12
-19
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
|
import { env } from '$env/dynamic/public'
|
||||||
import { client } from '$lib/api/client.svelte'
|
import { client } from '$lib/api/client.svelte'
|
||||||
import type { Community, Person } from '$lib/api/types'
|
import type { Community, Person } from '$lib/api/types'
|
||||||
import { SvelteURL } from 'svelte/reactivity'
|
import { SvelteURL } from 'svelte/reactivity'
|
||||||
@@ -26,6 +27,7 @@ export const searchParam = (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// why is this using SvelteURL brother
|
||||||
export const fullCommunityName = (name: string, actorId: string) =>
|
export const fullCommunityName = (name: string, actorId: string) =>
|
||||||
`${name}@${new SvelteURL(actorId).hostname}`
|
`${name}@${new SvelteURL(actorId).hostname}`
|
||||||
|
|
||||||
@@ -33,8 +35,8 @@ export const placeholders = {
|
|||||||
get: (type: 'url' | 'post' | 'body' | 'comment') => {
|
get: (type: 'url' | 'post' | 'body' | 'comment') => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'post':
|
case 'post':
|
||||||
return Math.random() < 0.01
|
return Math.random() < 0.01 && env.PUBLIC_XYLIGHT_MODE
|
||||||
? 'A C E C* B* G D E E F G F E D C E'
|
? 'top 10 reasons why TCP is brilliant and UDP is a spawn of satan'
|
||||||
: t.get('placeholders.title')
|
: t.get('placeholders.title')
|
||||||
case 'body':
|
case 'body':
|
||||||
return t.get('placeholders.body')
|
return t.get('placeholders.body')
|
||||||
@@ -46,6 +48,8 @@ export const placeholders = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lol this function was made 3 years ago when lil xylight
|
||||||
|
// was still learning cs
|
||||||
export function moveItem<T>(
|
export function moveItem<T>(
|
||||||
array: T[],
|
array: T[],
|
||||||
currentIndex: number,
|
currentIndex: number,
|
||||||
@@ -62,10 +66,7 @@ export function moveItem<T>(
|
|||||||
|
|
||||||
const newArray = [...array]
|
const newArray = [...array]
|
||||||
|
|
||||||
// Remove the item from the current index
|
|
||||||
const [item] = newArray.splice(currentIndex, 1)
|
const [item] = newArray.splice(currentIndex, 1)
|
||||||
|
|
||||||
// Insert the item at the new index
|
|
||||||
newArray.splice(newIndex, 0, item)
|
newArray.splice(newIndex, 0, item)
|
||||||
|
|
||||||
return newArray
|
return newArray
|
||||||
@@ -139,7 +140,6 @@ export function fuzzySearch(text: string, pattern: string): number {
|
|||||||
lastIndex = index
|
lastIndex = index
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bonus for matching start of words
|
|
||||||
if (textLower.startsWith(patternLower)) {
|
if (textLower.startsWith(patternLower)) {
|
||||||
score += 2
|
score += 2
|
||||||
} else if (textLower.includes(' ' + patternLower)) {
|
} else if (textLower.includes(' ' + patternLower)) {
|
||||||
@@ -167,6 +167,9 @@ export function snapshot<T>(item: T) {
|
|||||||
return $state.snapshot(item)
|
return $state.snapshot(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// these methods should really not exist
|
||||||
|
// instead we should use lemmy's url_content_type which
|
||||||
|
// gives us a mimetype (which is more reliable)
|
||||||
export const isImage = (url: string | undefined) => {
|
export const isImage = (url: string | undefined) => {
|
||||||
try {
|
try {
|
||||||
if (!url) return false
|
if (!url) return false
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
content: value,
|
content: value,
|
||||||
post_id: postId,
|
post_id: postId,
|
||||||
parent_id: parentId,
|
parent_id: parentId,
|
||||||
|
language_id: language,
|
||||||
})
|
})
|
||||||
oncomment?.(response)
|
oncomment?.(response)
|
||||||
|
|
||||||
|
|||||||
@@ -28,11 +28,7 @@
|
|||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div class={['flex flex-col flex-1 rounded-none list-none', clazz]}>
|
||||||
class={['flex flex-col flex-1 rounded-none list-none', clazz]}
|
|
||||||
color="none"
|
|
||||||
padding="none"
|
|
||||||
>
|
|
||||||
{#if meta}
|
{#if meta}
|
||||||
<div class="flex flex-row justify-between items-center gap-2">
|
<div class="flex flex-row justify-between items-center gap-2">
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
@@ -68,7 +64,6 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<Comment
|
<Comment
|
||||||
postId={comment.post.id}
|
|
||||||
node={{ children: [], comment_view: comment, depth: 1, expanded: true }}
|
node={{ children: [], comment_view: comment, depth: 1, expanded: true }}
|
||||||
replying={false}
|
replying={false}
|
||||||
{meta}
|
{meta}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
let { nodes = $bindable(), post }: Props = $props()
|
let { nodes = $bindable(), post }: Props = $props()
|
||||||
|
|
||||||
let childrenPage = 0
|
|
||||||
|
|
||||||
async function fetchChildren(parent: CommentNodeI) {
|
async function fetchChildren(parent: CommentNodeI) {
|
||||||
if (
|
if (
|
||||||
!(
|
!(
|
||||||
@@ -37,7 +35,6 @@
|
|||||||
max_depth: 5,
|
max_depth: 5,
|
||||||
parent_id: parent.comment_view.comment.id,
|
parent_id: parent.comment_view.comment.id,
|
||||||
type_: 'All',
|
type_: 'All',
|
||||||
page: childrenPage,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (newComments.comments.length == 0) {
|
if (newComments.comments.length == 0) {
|
||||||
@@ -52,7 +49,6 @@
|
|||||||
newComments.comments,
|
newComments.comments,
|
||||||
parent.depth,
|
parent.depth,
|
||||||
)[0].children
|
)[0].children
|
||||||
childrenPage++
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@@ -24,9 +24,7 @@
|
|||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
|
|
||||||
let selected = $derived(
|
let selected = $derived(
|
||||||
page.url.pathname.startsWith(
|
page.url.pathname.startsWith(href ?? '2026-02-08 hey guyz') ?? false,
|
||||||
href ?? 'The power of fluffy boys shines within you.',
|
|
||||||
) ?? false,
|
|
||||||
)
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user