diff --git a/src/vite-frontend/src/api/index.ts b/src/vite-frontend/src/api/index.ts index 455b7b9..020ab42 100644 --- a/src/vite-frontend/src/api/index.ts +++ b/src/vite-frontend/src/api/index.ts @@ -74,6 +74,16 @@ const createArticle = async (article: object | undefined): Promise => { + let currentToken = localStorage.getItem("token"); + return await axiosService.put('/api/articles/' + slug, { article },{ + headers :{ + Authorization : "TOKEN " + currentToken, + "Content-Type": `application/json`, + } + }) +} + const listArticles = async (): Promise => { let currentToken = localStorage.getItem("token"); if(currentToken == null){ @@ -100,6 +110,19 @@ const listArticlesByUsername = async (author: string): Promise => } } +const listArticlesByFavorite = async (author: string): Promise => { + let currentToken = localStorage.getItem("token"); + if(currentToken == null){ + return await axiosService.get('/api/articles?favorited=' + author); + }else{ + return await axiosService.get('/api/articles?favorited=' + author,{ + headers:{ + Authorization: "TOKEN " + currentToken, + } + }) + } +} + const feedArticle = async (): Promise => { let currentToken = localStorage.getItem("token"); return await axiosService.get('/api/articles/feed?limit=1000&offset=0',{ @@ -182,5 +205,6 @@ export { signUp, signIn, unfollowUser, getArticle, addCommentToArticle, getCommentsFromArticle, favoriteArticle, unFavoriteArticle, + listArticlesByFavorite, updateArticle, getTags } \ No newline at end of file diff --git a/src/vite-frontend/src/api/usePaginationAPI.ts b/src/vite-frontend/src/api/usePaginationAPI.ts index 5bfc49e..a03f3dc 100644 --- a/src/vite-frontend/src/api/usePaginationAPI.ts +++ b/src/vite-frontend/src/api/usePaginationAPI.ts @@ -1,5 +1,5 @@ import { ref, Ref } from "@vue/reactivity"; -import { listArticles, feedArticle } from "@/api/index"; +import {listArticles, feedArticle, listArticlesByUsername, listArticlesByFavorite} from "@/api/index"; import { usePagination } from "@/ts/usePagination"; @@ -63,11 +63,45 @@ export function usePaginationApi( } }; + const loadMyArticles = async (author: string) => { + listsAreLoading.value = true; + isEmpty.value = false; + try{ + const { data } = await listArticlesByUsername(author); + articleLists.value = data.articles; + if(data.articlesCount == 0){ + isEmpty.value = true; + } + }catch (err){ + console.log(err); + }finally { + listsAreLoading.value = false; + } + } + + const loadFavoriteArticles = async (author: string) => { + listsAreLoading.value = true; + isEmpty.value = false; + try{ + const { data } = await listArticlesByFavorite(author); + articleLists.value = data.articles; + if(data.articlesCount == 0){ + isEmpty.value = true; + } + }catch (err){ + console.log(err); + }finally { + listsAreLoading.value = false; + } + } + return { articleLists: paginatedArray, loadLists, feedLists, + loadMyArticles, + loadFavoriteArticles, listsAreLoading, isEmpty, numberOfPages diff --git a/src/vite-frontend/src/router/index.ts b/src/vite-frontend/src/router/index.ts index 92a7f62..98aa2cc 100644 --- a/src/vite-frontend/src/router/index.ts +++ b/src/vite-frontend/src/router/index.ts @@ -33,6 +33,12 @@ const routes = [ name: "ArticleEditor", component: () => import(/* webpackChunkName "inputTag" */ '@/views/TheArticle.vue') }, + { + path: "/editor/@:slug", + name: "ArticleUpdateEditor", + component: () => import(/* webpackChunkName "inputTag" */ '@/views/ArticleUpdate.vue'), + props: true + }, { path: "/@:username", name: "Profile", diff --git a/src/vite-frontend/src/views/ArticleUpdate.vue b/src/vite-frontend/src/views/ArticleUpdate.vue new file mode 100644 index 0000000..cc8378b --- /dev/null +++ b/src/vite-frontend/src/views/ArticleUpdate.vue @@ -0,0 +1,74 @@ + + + + + \ No newline at end of file diff --git a/src/vite-frontend/src/views/TheArticleDetail.vue b/src/vite-frontend/src/views/TheArticleDetail.vue index ddd142d..01dfae2 100644 --- a/src/vite-frontend/src/views/TheArticleDetail.vue +++ b/src/vite-frontend/src/views/TheArticleDetail.vue @@ -12,7 +12,15 @@ {{ articleDetail.article.author.username }} {{convertDate(articleDetail.article.createdAt)}} - + +    - + + -   -