diff --git a/src/vite-frontend/src/api/usePaginationAPI.ts b/src/vite-frontend/src/api/usePaginationAPI.ts index 73d927d..c89ac71 100644 --- a/src/vite-frontend/src/api/usePaginationAPI.ts +++ b/src/vite-frontend/src/api/usePaginationAPI.ts @@ -1,34 +1,62 @@ import { ref, Ref } from "@vue/reactivity"; -import { listArticles } from "@/api/index"; +import { listArticles, feedArticle } from "@/api/index"; import { usePagination } from "@/ts/usePagination"; -export interface Todo { - id: number; - title: string; +export interface ArticleList { + slug: string, + title: string, + description: string, + favorited: boolean, + favoritesCount: number, + createdAt: string, + author: { + username: string, + image: string + } } export function usePaginationApi( currentPage: Ref, rowsPerPage?: Ref ) { - const articleLists: Ref = ref([]); + const articleLists: Ref = ref([]); const listsAreLoading = ref(false); + const isEmpty = ref(false); - const { paginatedArray, numberOfPages } = usePagination({ + const { paginatedArray, numberOfPages } = usePagination({ rowsPerPage, arrayToPaginate: articleLists, currentPage }); + const feedLists = async () => { + listsAreLoading.value = true; + isEmpty.value = false; + try{ + const { data } = await feedArticle(); + articleLists.value = data.articles; + if(data.articlesCount == 0){ + isEmpty.value = true; + } + } catch (err) { + console.log(err); + } finally { + listsAreLoading.value = false; + } + } + const loadLists = async () => { listsAreLoading.value = true; + isEmpty.value = false; try { const { data } = await listArticles(); articleLists.value = data.articles; - console.log(articleLists.value); + if(data.articlesCount == 0){ + isEmpty.value = true; + } } catch (err) { console.log(err); } finally { @@ -39,7 +67,9 @@ export function usePaginationApi( return { articleLists: paginatedArray, loadLists, + feedLists, listsAreLoading, + isEmpty, numberOfPages }; } \ No newline at end of file diff --git a/src/vite-frontend/src/components/ArticleListFeed.vue b/src/vite-frontend/src/components/ArticleListFeed.vue index c5a2393..ce79475 100644 --- a/src/vite-frontend/src/components/ArticleListFeed.vue +++ b/src/vite-frontend/src/components/ArticleListFeed.vue @@ -1,45 +1,46 @@ diff --git a/src/vite-frontend/src/views/TheHome.vue b/src/vite-frontend/src/views/TheHome.vue index ea9fbe3..8a2e88e 100644 --- a/src/vite-frontend/src/views/TheHome.vue +++ b/src/vite-frontend/src/views/TheHome.vue @@ -26,28 +26,27 @@ :class="{ active : globalActive }">Global Feed -
+
Loading articles...
No articles are here... yet.
- - - +
+ + +
+
+ +
-
- {{test}} -
@@ -78,48 +74,49 @@ import { useStore } from "vuex"; export default { name: "TheHome", components: { - 'article-list': articleList, + 'article-list-feed': articleList, 'article-list-global': articleListGlobal, 'tag-lists': tagLists, 'pagination-component': pagination, }, setup(){ - const isLoading = ref(true); - const isEmpty = ref(false); const store = useStore(); - const isLogin = store.state.token == '' ? false : true; + const isLogin = ref(false); const feedActive = ref(true); const globalActive = ref(false); const currentPage = ref(1); const rowsPerPage = ref(20); - const { articleLists, listsAreLoading, loadLists, numberOfPages } = usePaginationApi(currentPage, rowsPerPage); + const { articleLists, listsAreLoading, isEmpty, loadLists, feedLists, numberOfPages } = usePaginationApi(currentPage, rowsPerPage); - const onChangeLoading = (val : boolean) => { - isLoading.value = val; - } - const emptyCheck = (val: boolean) => { - isEmpty.value = val; - } - - const feedSelect = () => { + const feedSelect = async () => { feedActive.value=true; globalActive.value=false; - isEmpty.value=false; - isLoading.value=true; + await feedLists(); } - const globalSelect = () => { + const globalSelect = async () => { feedActive.value=false; globalActive.value=true; - isEmpty.value=false; - isLoading.value=true; + await loadLists(); + } + const updateFavorite = async (index: number) => { + console.log("index" , index); } - onMounted(async () => loadLists()) + onMounted(async () => { + isLogin.value = store.state.token ? true : false; + if(isLogin.value == false) { + await loadLists(); + globalActive.value = true; + }else{ + await feedLists(); + feedActive.value = true; + } + }) - return { isLoading, isEmpty, isLogin, currentPage, rowsPerPage, numberOfPages, feedActive, globalActive, articleLists, onChangeLoading, emptyCheck, feedSelect, globalSelect }; + return { listsAreLoading, isEmpty, isLogin, currentPage, rowsPerPage, numberOfPages, feedActive, globalActive, articleLists, updateFavorite, feedSelect, globalSelect }; } }