Skip to content

Commit

Permalink
Merge pull request #69 from Carifio24/scene-publishing
Browse files Browse the repository at this point in the history
Allow setting scene publication status
  • Loading branch information
pkgw authored Dec 7, 2023
2 parents 367c189 + 55650d6 commit d3e9d63
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
36 changes: 34 additions & 2 deletions components/SceneEditorPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@
</n-button>
</n-space>
</n-grid-item>

<n-grid-item>
<n-text depth="3" style="font-size: smaller;">
Publication Status:
</n-text>
<n-space justify="space-between">
<n-text>
{{ published_status ? 'Published' : 'Not Published' }}
</n-text>
<n-button :loading="published_status_loading" @click="onUpdatePublished">
{{ published_status ? 'Unpublish' : 'Publish' }}
</n-button>
</n-space>
</n-grid-item>
</n-grid>
</template>

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
</script>

<style scoped lang="less">
Expand Down Expand Up @@ -363,4 +395,4 @@ async function onUpdateBackground() {
.action-button-label {
margin-left: 5px;
}
</style>
</style>
2 changes: 1 addition & 1 deletion layouts/naiveui.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ onUnmounted(() => {
}
#inner {
max-width: 40rem;
max-width: 50rem;
margin: 0 auto;
color: #FFF;
}
Expand Down
22 changes: 22 additions & 0 deletions pages/@[handle]/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import {
NInput,
NRow,
NStatistic,
NSwitch,
NTabs,
NTabPane,
useNotification
Expand All @@ -103,6 +104,7 @@ import {
handleStats,
HandleStatsResponseT,
ImageSummaryT,
SceneUpdateRequestT,
updateHandle,
} from "~/utils/apis";
Expand Down Expand Up @@ -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<HandleSceneInfoT[]>([]);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions utils/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<typeof GetSceneResponse>;
Expand Down Expand Up @@ -620,6 +622,7 @@ export const SceneUpdateRequest = t.partial({
place: PlaceDetails,
text: t.string,
content: SceneContentUpdateRequest,
published: t.boolean,
});

export type SceneUpdateRequestT = t.TypeOf<typeof SceneUpdateRequest>;
Expand Down
2 changes: 2 additions & 0 deletions utils/fixnaive.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
NSlider,
NSpace,
NStatistic,
NSwitch,
NTabs,
NTabPane,
NText,
Expand Down Expand Up @@ -76,6 +77,7 @@ export {
NSlider,
NSpace,
NStatistic,
NSwitch,
NTabs,
NTabPane,
NText,
Expand Down

0 comments on commit d3e9d63

Please sign in to comment.