From 0d25abab798c005266a1c0b4eeba957d232d4328 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 16 Dec 2023 02:40:03 -0500 Subject: move blog admin state to pinia store plugin --- front-end/src/views/Blog/blog-api/index.ts | 22 ---- front-end/src/views/Blog/ckeditor/Editor.vue | 15 ++- front-end/src/views/Blog/ckeditor/uploadAdapter.ts | 4 +- front-end/src/views/Blog/components/Channels.vue | 40 +++----- .../views/Blog/components/Channels/ChannelEdit.vue | 15 ++- .../Blog/components/Channels/ChannelTable.vue | 11 +- front-end/src/views/Blog/components/Content.vue | 85 +++++++-------- .../Blog/components/Content/ContentEditor.vue | 29 +++--- .../views/Blog/components/Content/ContentTable.vue | 42 +++++--- .../src/views/Blog/components/ContentSearch.vue | 12 +-- front-end/src/views/Blog/components/FeedFields.vue | 6 +- front-end/src/views/Blog/components/Posts.vue | 63 ++++++------ .../src/views/Blog/components/Posts/PostEdit.vue | 52 ++++++---- .../src/views/Blog/components/Posts/PostTable.vue | 11 +- .../components/podcast-helpers/EpisodeAdder.vue | 12 +-- .../components/podcast-helpers/podcast-form.ts | 4 +- front-end/src/views/Blog/index.vue | 114 ++++++++++----------- 17 files changed, 251 insertions(+), 286 deletions(-) delete mode 100644 front-end/src/views/Blog/blog-api/index.ts (limited to 'front-end/src/views/Blog') diff --git a/front-end/src/views/Blog/blog-api/index.ts b/front-end/src/views/Blog/blog-api/index.ts deleted file mode 100644 index 678883b..0000000 --- a/front-end/src/views/Blog/blog-api/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2023 Vaughn Nugent -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import { ComputedChannels, ComputedContent, ComputedPosts } from '@vnuge/cmnext-admin' - -export interface BlogState { - readonly channels: ComputedChannels, - readonly posts: ComputedPosts, - readonly content: ComputedContent -} \ No newline at end of file diff --git a/front-end/src/views/Blog/ckeditor/Editor.vue b/front-end/src/views/Blog/ckeditor/Editor.vue index 5bbf1cb..e1ee2ce 100644 --- a/front-end/src/views/Blog/ckeditor/Editor.vue +++ b/front-end/src/views/Blog/ckeditor/Editor.vue @@ -76,18 +76,19 @@ import { tryOnMounted } from '@vueuse/shared'; import { apiCall } from '@vnuge/vnlib.browser'; import { Popover, PopoverButton, PopoverPanel, Switch } from '@headlessui/vue' import { Converter } from 'showdown' -import { BlogState } from '../blog-api' import { useCkConfig } from './build.ts' import { useUploadAdapter } from './uploadAdapter'; import ContentSearch from '../components/ContentSearch.vue'; +import { useStore } from '../../../store'; const emit = defineEmits(['change', 'load', 'mode-change']) const props = defineProps<{ - blog: BlogState, podcastMode: boolean }>() +const store = useStore() + let editor = {} const propRefs = toRefs(props) //Init new shodown converter @@ -135,13 +136,9 @@ tryOnMounted(() => defer(() => //Load the editor once the component is mounted apiCall(async ({ toaster }) => { - //Entry script creates promise that resolves when the editor script is loaded - if(window.editorLoadResult){ - //Wait for the editor script to load - await (window.editorLoadResult as Promise) - } + await store.waitForEditor() - if (!window['CKEDITOR']) { + if ('CKEDITOR' in window === false) { toaster.general.error({ title: 'Script Error', text: 'The CKEditor script failed to load, check script permissions.' @@ -155,7 +152,7 @@ tryOnMounted(() => defer(() => //Init the ck config const config = useCkConfig([ //Add the upload adapter - useUploadAdapter(props.blog.content, apiCall, toaster.general) + useUploadAdapter(store.content, apiCall, toaster.general) ]); //Init editor when loading is complete diff --git a/front-end/src/views/Blog/ckeditor/uploadAdapter.ts b/front-end/src/views/Blog/ckeditor/uploadAdapter.ts index 1c22842..74918b9 100644 --- a/front-end/src/views/Blog/ckeditor/uploadAdapter.ts +++ b/front-end/src/views/Blog/ckeditor/uploadAdapter.ts @@ -13,12 +13,12 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -import { ComputedContent } from "@vnuge/cmnext-admin"; import { IToaster } from "@vnuge/vnlib.browser"; import { isNil } from "lodash-es"; import type { AxiosRequestConfig } from "axios"; import type { Editor } from "@ckeditor/ckeditor5-core"; import type { UploadAdapter, UploadResponse, FileLoader } from '@ckeditor/ckeditor5-upload' +import { ContentStore } from "../../../store/cmnextAdminPlugin"; export type ApiCall = (callback: (data: any) => Promise) => Promise; export type CKEditorPlugin = (editor: Editor) => void; @@ -29,7 +29,7 @@ export type CKEditorPlugin = (editor: Editor) => void; * @param apiCall A callback function that wraps the api call * @returns A CKEditor plugin initializer */ -export const useUploadAdapter = (content: ComputedContent, apiCall: ApiCall, toaster?: IToaster): CKEditorPlugin =>{ +export const useUploadAdapter = (content: ContentStore, apiCall: ApiCall, toaster?: IToaster): CKEditorPlugin =>{ const createUploadAdapter = (loader: FileLoader): UploadAdapter => { diff --git a/front-end/src/views/Blog/components/Channels.vue b/front-end/src/views/Blog/components/Channels.vue index 2a160b3..bf29067 100644 --- a/front-end/src/views/Blog/components/Channels.vue +++ b/front-end/src/views/Blog/components/Channels.vue @@ -2,14 +2,13 @@