aboutsummaryrefslogtreecommitdiff
path: root/lib/admin/src/index.ts
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-07-12 01:28:23 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-07-12 01:28:23 -0400
commitf64955c69d91e578e580b409ba31ac4b3477da96 (patch)
tree16f01392ddf1abfea13d7d1ede3bfb0459fe8f0d /lib/admin/src/index.ts
Initial commit
Diffstat (limited to 'lib/admin/src/index.ts')
-rw-r--r--lib/admin/src/index.ts87
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/admin/src/index.ts b/lib/admin/src/index.ts
new file mode 100644
index 0000000..b5abe68
--- /dev/null
+++ b/lib/admin/src/index.ts
@@ -0,0 +1,87 @@
+// 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 <https://www.gnu.org/licenses/>.
+
+//Export apis and types
+export * from './types';
+export * from './ordering'
+export * from './feedProperties'
+export * from './posts'
+export * from './content'
+export * from './channels'
+
+import { MaybeRef } from "vue";
+import { get } from '@vueuse/core'
+import { useRouteQuery } from "@vueuse/router";
+import { QueryState, QueryType, SortType, BlogAdminContext } from "./types";
+
+export interface BlogAdminConfig {
+ readonly postUrl: MaybeRef<string>;
+ readonly contentUrl: MaybeRef<string>;
+ readonly channelUrl: MaybeRef<string>;
+ readonly defaultPageSize?: number;
+}
+
+const createQueryState = (): QueryState => {
+ //setup filter search query
+ const search = useRouteQuery<string>(QueryType.Filter, '', { mode: 'replace' });
+
+ //Get sort order query
+ const sort = useRouteQuery<SortType>(QueryType.Sort, SortType.CreatedTime, { mode: 'replace' });
+
+ //Selected channel id
+ const channel = useRouteQuery<string>(QueryType.Channel, '', { mode: 'replace' });
+
+ //Edits are in push mode because they are used to navigate to edit pages
+
+ const channelEdit = useRouteQuery<string>(QueryType.ChannelEdit, '', { mode: 'push' });
+
+ const content = useRouteQuery<string>(QueryType.Content, '', { mode: 'push' });
+ //Get the selected post id from the route
+ const post = useRouteQuery<string>(QueryType.Post, '', { mode: 'push' });
+
+ return {
+ post,
+ channel,
+ content,
+ channelEdit,
+ search,
+ sort
+ }
+}
+
+/**
+ * Create a blog context object from the given configuration
+ * @param param0 The blog configuration object
+ * @returns A blog context object to pass to the blog admin components
+ */
+export const createBlogContext = ({ channelUrl, postUrl, contentUrl }: BlogAdminConfig): BlogAdminContext => {
+
+ const queryState = createQueryState();
+
+ const getQuery = (): QueryState => queryState;
+
+ const getPostUrl = (): string => get(postUrl)
+
+ const getContentUrl = (): string => get(contentUrl)
+
+ const getChannelUrl = (): string => get(channelUrl)
+
+ return{
+ getQuery,
+ getPostUrl,
+ getChannelUrl,
+ getContentUrl,
+ }
+} \ No newline at end of file