From 69544520d5834ab341a9b1b34df1d5938bd8170f Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Mon, 28 Jul 2025 16:36:30 +0800 Subject: [PATCH 1/3] hook categories --- src/partials/ArticlesListPartial.vue | 21 +++++++++---------- .../api/response/categories-response.ts | 14 +++++++++++++ src/stores/api/store.ts | 12 ++++++++++- 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/stores/api/response/categories-response.ts diff --git a/src/partials/ArticlesListPartial.vue b/src/partials/ArticlesListPartial.vue index e85364d8..04301b7c 100644 --- a/src/partials/ArticlesListPartial.vue +++ b/src/partials/ArticlesListPartial.vue @@ -4,17 +4,8 @@ @@ -31,15 +22,23 @@ import { useApiStore } from '@api/store.ts'; import { debugError } from '@api/http-error.ts'; import ArticleItemPartial from '@partials/ArticleItemPartial.vue'; import type { PostResponse, PostsCollectionResponse } from '@api/response/posts-response.ts'; +import { CategoriesCollectionResponse, CategoryResponse } from '@api/response/categories-response.ts'; const apiStore = useApiStore(); + const collection = ref(); const items = ref([]); +const categoriesCollection = ref(); +const categories = ref([]); + onMounted(async () => { try { collection.value = await apiStore.getPosts(); items.value = collection.value.data as PostResponse[]; + + categoriesCollection.value = await apiStore.getCategories(); + categories.value = categoriesCollection.value.data as CategoryResponse[]; } catch (error) { debugError(error); } diff --git a/src/stores/api/response/categories-response.ts b/src/stores/api/response/categories-response.ts new file mode 100644 index 00000000..9a7b712e --- /dev/null +++ b/src/stores/api/response/categories-response.ts @@ -0,0 +1,14 @@ +export interface CategoriesCollectionResponse { + page: number; + total: number; + page_size: number; + total_pages: number; + data: CategoryResponse[]; +} + +export interface CategoryResponse { + uuid: string; + name: string; + slug: string; + description: string; +} diff --git a/src/stores/api/store.ts b/src/stores/api/store.ts index 3cb5ab7f..2938ca2f 100644 --- a/src/stores/api/store.ts +++ b/src/stores/api/store.ts @@ -3,6 +3,7 @@ import { parseError } from '@api/http-error.ts'; import { ProfileResponse } from '@api/response/profile-response.ts'; import { ApiClient, ApiResponse, defaultCreds } from '@api/client.ts'; import type { PostResponse, PostsCollectionResponse } from '@api/response/posts-response.ts'; +import { CategoriesCollectionResponse } from '@api/response/categories-response.ts'; const STORE_KEY = 'api-client-store'; @@ -31,8 +32,17 @@ export const useApiStore = defineStore(STORE_KEY, { return parseError(error); } }, + async getCategories(): Promise { + const url = 'categories?limit=5'; + + try { + return await this.client.get(url); + } catch (error) { + return parseError(error); + } + }, async getPosts(): Promise { - const url = 'posts'; + const url = 'posts?limit=5'; try { return await this.client.get(url); From 5c95a66581fd2958a9e54c9c1bb3b7035de177ce Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Mon, 28 Jul 2025 17:18:31 +0800 Subject: [PATCH 2/3] format --- src/pages/PostPage.vue | 2 +- src/partials/ArticleItemPartial.vue | 11 +++- src/partials/ArticlesListPartial.vue | 61 ++++++++++++++++++++--- src/partials/AvatarPartial.vue | 2 +- src/stores/api/client.ts | 17 +++++++ src/stores/api/response/posts-response.ts | 8 +++ src/stores/api/store.ts | 6 +-- 7 files changed, 93 insertions(+), 14 deletions(-) diff --git a/src/pages/PostPage.vue b/src/pages/PostPage.vue index c13cad05..35d3c659 100644 --- a/src/pages/PostPage.vue +++ b/src/pages/PostPage.vue @@ -86,7 +86,7 @@

{{ post.excerpt }}

- +
diff --git a/src/partials/ArticleItemPartial.vue b/src/partials/ArticleItemPartial.vue index 190037d3..852ed8a0 100644 --- a/src/partials/ArticleItemPartial.vue +++ b/src/partials/ArticleItemPartial.vue @@ -1,7 +1,16 @@ diff --git a/src/stores/api/response/posts-response.ts b/src/stores/api/response/posts-response.ts index eec2f40f..e04a6d26 100644 --- a/src/stores/api/response/posts-response.ts +++ b/src/stores/api/response/posts-response.ts @@ -46,9 +46,9 @@ export interface PostsTagResponse { } export interface PostsFilters { - text: ?string; - title: ?string; - author: ?string; - category: ?string; - tag: ?string; + text?: string; + title?: string; + author?: string; + category?: string; + tag?: string; } diff --git a/src/stores/api/store.ts b/src/stores/api/store.ts index 7c0ec8fa..f7e2e9ad 100644 --- a/src/stores/api/store.ts +++ b/src/stores/api/store.ts @@ -9,6 +9,7 @@ const STORE_KEY = 'api-client-store'; export interface ApiStoreState { client: ApiClient; + searchTerm: string; } const client = new ApiClient(defaultCreds); @@ -16,8 +17,12 @@ const client = new ApiClient(defaultCreds); export const useApiStore = defineStore(STORE_KEY, { state: (): ApiStoreState => ({ client: client, + searchTerm: '', }), actions: { + setSearchTerm(term: string): void { + this.searchTerm = term; + }, boot(): void { if (this.client.isDev()) { console.log('API client booted ...');