diff --git a/components/SceneEditorPanel.vue b/components/SceneEditorPanel.vue index 325809f..ebe2a7c 100644 --- a/components/SceneEditorPanel.vue +++ b/components/SceneEditorPanel.vue @@ -74,6 +74,20 @@ + + + + Publication Status: + + + + {{ published_status ? 'Published' : 'Not Published' }} + + + {{ published_status ? 'Unpublish' : 'Publish' }} + + + @@ -286,7 +300,7 @@ const { data: background_data } = await useAsyncData("backgrounds", async () => watchEffect(() => { const bgdata = background_data.value; - if (bgdata) { + if (bgdata && bgdata.length > 0) { background_options.value = bgdata.map((item) => { return { label: item.note, @@ -327,6 +341,24 @@ async function onUpdateBackground() { background_loading.value = false; } +const published_status = ref(false); +const published_status_loading = ref(false); +watchEffect(() => { + published_status.value = scene.value.published; + published_status_loading.value = false; +}); + +async function onUpdatePublished() { + const fetcher = await $backendAuthCall(); + published_status_loading.value = true; + published_status.value = !published_status.value; + await updateScene(fetcher, scene.value.id, { published: published_status.value }); + const message = `Scene ${published_status.value ? 'published' : 'unpublished'}`; + notification.success({ content: message, duration: 3000 }); + published_status_loading.value = false; +} + + \ No newline at end of file + diff --git a/layouts/naiveui.vue b/layouts/naiveui.vue index a9eebe4..182218f 100644 --- a/layouts/naiveui.vue +++ b/layouts/naiveui.vue @@ -48,7 +48,7 @@ onUnmounted(() => { } #inner { - max-width: 40rem; + max-width: 50rem; margin: 0 auto; color: #FFF; } diff --git a/pages/@[handle]/dashboard.vue b/pages/@[handle]/dashboard.vue index cfdedd0..2b5b097 100644 --- a/pages/@[handle]/dashboard.vue +++ b/pages/@[handle]/dashboard.vue @@ -91,6 +91,7 @@ import { NInput, NRow, NStatistic, + NSwitch, NTabs, NTabPane, useNotification @@ -103,6 +104,7 @@ import { handleStats, HandleStatsResponseT, ImageSummaryT, + SceneUpdateRequestT, updateHandle, } from "~/utils/apis"; @@ -209,6 +211,21 @@ const sceneColumns = [ key: "shares", render: (row: HandleSceneInfoT) => row.shares || 0, }, + { + title: "Published", + key: "published", + render: (row: HandleSceneInfoT) => { + return h(NSwitch, + { + value: row.published, + onUpdateValue: (value) => { + row.published = value; + onSceneUpdate(row); + }, + }, + () => []); + }, + } ]; const sceneData = ref([]); @@ -240,6 +257,11 @@ async function onSceneTablePageChange(page: number) { } } +async function onSceneUpdate(info: HandleSceneInfoT) { + const fetcher = await $backendAuthCall(); + updateScene(fetcher, info._id, info); +} + onMounted(() => { sceneIsLoading.value = false; onSceneTablePageChange(1); diff --git a/utils/apis.ts b/utils/apis.ts index 9986d54..ef071e6 100644 --- a/utils/apis.ts +++ b/utils/apis.ts @@ -242,6 +242,7 @@ export const HandleSceneInfo = t.intersection([ impressions: t.number, likes: t.number, text: t.string, + published: t.boolean, }), t.partial({ clicks: t.number, shares: t.number, @@ -528,6 +529,7 @@ export const GetSceneResponse = t.type({ liked: t.boolean, outgoing_url: t.union([t.string, t.undefined]), previews: ScenePreviews, + published: t.boolean, }); export type GetSceneResponseT = t.TypeOf; @@ -620,6 +622,7 @@ export const SceneUpdateRequest = t.partial({ place: PlaceDetails, text: t.string, content: SceneContentUpdateRequest, + published: t.boolean, }); export type SceneUpdateRequestT = t.TypeOf; diff --git a/utils/fixnaive.mjs b/utils/fixnaive.mjs index 431f579..24fc6f6 100644 --- a/utils/fixnaive.mjs +++ b/utils/fixnaive.mjs @@ -37,6 +37,7 @@ import { NSlider, NSpace, NStatistic, + NSwitch, NTabs, NTabPane, NText, @@ -76,6 +77,7 @@ export { NSlider, NSpace, NStatistic, + NSwitch, NTabs, NTabPane, NText,