diff --git a/src/lib/components/admin/AdminPage.svelte b/src/lib/components/admin/AdminPage.svelte index 55874b1..544fc21 100644 --- a/src/lib/components/admin/AdminPage.svelte +++ b/src/lib/components/admin/AdminPage.svelte @@ -51,6 +51,7 @@ box-sizing: border-box; min-height: 110px; padding: $unit-4x; + display: flex; @include breakpoint('phone') { padding: $unit-3x; diff --git a/src/lib/components/admin/UniverseComposer.svelte b/src/lib/components/admin/UniverseComposer.svelte index 3ec0eb2..65b0c02 100644 --- a/src/lib/components/admin/UniverseComposer.svelte +++ b/src/lib/components/admin/UniverseComposer.svelte @@ -86,7 +86,7 @@ function switchToEssay() { const contentParam = content ? encodeURIComponent(JSON.stringify(content)) : '' - goto(`/admin/universe/compose?type=essay${contentParam ? `&content=${contentParam}` : ''}`) + goto(`/admin/posts/new?type=essay${contentParam ? `&content=${contentParam}` : ''}`) } function generateSlug(title: string): string { @@ -151,8 +151,8 @@ function handleMediaSelect(media: Media | Media[]) { const mediaArray = Array.isArray(media) ? media : [media] - const currentIds = attachedPhotos.map(p => p.id) - const newMedia = mediaArray.filter(m => !currentIds.includes(m.id)) + const currentIds = attachedPhotos.map((p) => p.id) + const newMedia = mediaArray.filter((m) => !currentIds.includes(m.id)) attachedPhotos = [...attachedPhotos, ...newMedia] } @@ -161,7 +161,7 @@ } function removePhoto(photoId: number) { - attachedPhotos = attachedPhotos.filter(p => p.id !== photoId) + attachedPhotos = attachedPhotos.filter((p) => p.id !== photoId) } function handlePhotoClick(photo: Media) { @@ -176,7 +176,7 @@ function handleMediaUpdate(updatedMedia: Media) { // Update the photo in the attachedPhotos array - attachedPhotos = attachedPhotos.map(photo => + attachedPhotos = attachedPhotos.map((photo) => photo.id === updatedMedia.id ? updatedMedia : photo ) } @@ -206,7 +206,7 @@ let postData: any = { content, status: 'published', - attachedPhotos: attachedPhotos.map(photo => photo.id) + attachedPhotos: attachedPhotos.map((photo) => photo.id) } if (postType === 'essay') { @@ -234,9 +234,15 @@ } try { + const auth = localStorage.getItem('admin_auth') + const headers: Record = { 'Content-Type': 'application/json' } + if (auth) { + headers.Authorization = `Basic ${auth}` + } + const response = await fetch('/api/posts', { method: 'POST', - headers: { 'Content-Type': 'application/json' }, + headers, body: JSON.stringify(postData) }) @@ -330,7 +336,6 @@ {/if} - {#if attachedPhotos.length > 0}
{#each attachedPhotos as photo} @@ -340,11 +345,7 @@ onclick={() => handlePhotoClick(photo)} title="View media details" > - {photo.altText + {photo.altText + {/snippet} @@ -650,7 +650,7 @@ isUploadModalOpen = false} + onClose={() => (isUploadModalOpen = false)} onUploadComplete={handleUploadComplete} /> diff --git a/src/routes/admin/posts/+page.svelte b/src/routes/admin/posts/+page.svelte index 1f3c616..8813735 100644 --- a/src/routes/admin/posts/+page.svelte +++ b/src/routes/admin/posts/+page.svelte @@ -5,9 +5,9 @@ import AdminHeader from '$lib/components/admin/AdminHeader.svelte' import AdminFilters from '$lib/components/admin/AdminFilters.svelte' import PostListItem from '$lib/components/admin/PostListItem.svelte' - import PostDropdown from '$lib/components/admin/PostDropdown.svelte' import LoadingSpinner from '$lib/components/admin/LoadingSpinner.svelte' import Select from '$lib/components/admin/Select.svelte' + import UniverseComposer from '$lib/components/admin/UniverseComposer.svelte' interface Post { id: number @@ -36,6 +36,9 @@ // Filter state let selectedFilter = $state('all') + // Composer state + let showInlineComposer = $state(true) + // Create filter options const filterOptions = $derived([ { value: 'all', label: 'All posts' }, @@ -140,18 +143,30 @@ applyFilter() } + function handleComposerSaved() { + // Reload posts when a new post is created + loadPosts() + } - - {#snippet actions()} - - {/snippet} - + {#if error}
{error}
{:else} + + {#if showInlineComposer} +
+ +
+ {/if} + {#snippet left()} @@ -241,5 +256,8 @@ gap: $unit-2x; } - + .composer-section { + margin-bottom: $unit-4x; + padding: 0 $unit; + }