refactor: replace $: reactive statements with $derived()

Migrate remaining Svelte 4 reactive statements to Svelte 5 $derived:
- media/audit/+page.svelte: Convert allSelected, hasSelection, selectedSize to $derived
- universe/compose/+page.svelte: Convert postType, initialContent to $derived
- Also migrated all let declarations to $state() in audit page for consistency

All reactive statements now use Svelte 5 runes mode.
This commit is contained in:
Justin Edmund 2025-11-04 19:46:35 -08:00
parent 4337b57dee
commit 5b5785887d
2 changed files with 22 additions and 19 deletions

View file

@ -29,32 +29,33 @@
createdAt: string
}
let loading = true
let deleting = false
let auditData: {
let loading = $state(true)
let deleting = $state(false)
let auditData = $state<{
summary: AuditSummary
orphanedFiles: OrphanedFile[]
missingReferences: string[]
} | null = null
let error: string | null = null
let selectedFiles = new Set<string>()
let showDeleteModal = false
let deleteResults: { succeeded: number; failed: string[] } | null = null
let cleanupResults: {
} | null>(null)
let error = $state<string | null>(null)
let selectedFiles = $state(new Set<string>())
let showDeleteModal = $state(false)
let deleteResults = $state<{ succeeded: number; failed: string[] } | null>(null)
let cleanupResults = $state<{
cleanedMedia: number
cleanedProjects: number
cleanedPosts: number
errors: string[]
} | null = null
let showCleanupModal = false
let cleaningUp = false
} | null>(null)
let showCleanupModal = $state(false)
let cleaningUp = $state(false)
$: allSelected = auditData && selectedFiles.size >= Math.min(20, auditData.orphanedFiles.length)
$: hasSelection = selectedFiles.size > 0
$: selectedSize =
const allSelected = $derived(auditData && selectedFiles.size >= Math.min(20, auditData.orphanedFiles.length))
const hasSelection = $derived(selectedFiles.size > 0)
const selectedSize = $derived(
auditData?.orphanedFiles
.filter((f) => selectedFiles.has(f.publicId))
.reduce((sum, f) => sum + f.size, 0) || 0
)
onMount(() => {
runAudit()

View file

@ -4,10 +4,12 @@
import AdminPage from '$lib/components/admin/AdminPage.svelte'
// Get initial state from URL params
$: postType = ($page.url.searchParams.get('type') as 'post' | 'essay') || 'essay'
$: initialContent = $page.url.searchParams.get('content')
const postType = $derived(($page.url.searchParams.get('type') as 'post' | 'essay') || 'essay')
const initialContent = $derived(
$page.url.searchParams.get('content')
? JSON.parse($page.url.searchParams.get('content')!)
: undefined
)
</script>
<svelte:head>