feat : Your Feed API Implement.

This commit is contained in:
kms
2022-11-25 01:05:16 +09:00
parent a1c45d5a82
commit 020c59d380
5 changed files with 57 additions and 21 deletions

View File

@@ -1,5 +1,4 @@
<template> <template>
<div v-for = "art in articles.article"> <div v-for = "art in articles.article">
<div class="article-preview"> <div class="article-preview">
<div class="article-meta"> <div class="article-meta">
@@ -22,17 +21,22 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import {onMounted, reactive, ref, defineEmits} from "vue"; import {onMounted, reactive, ref, defineComponent} from "vue";
import {useStore} from "vuex";
import axios from "axios"; import axios from "axios";
export default { export default defineComponent({
name: "TheArticleList", name: "ArticleListFeed",
props:{ props:{
isEmpty: Boolean,
isLoading: Boolean isLoading: Boolean
}, },
setup(){ setup(props,{emit}){
const url = import.meta.env.VITE_BASE_URL; const url = import.meta.env.VITE_BASE_URL;
const emit = defineEmits(["loading"]) const store = useStore();
const token = store.state.token;
const empty = ref(false);
const articles = reactive({ const articles = reactive({
article: {art:{ article: {art:{
slug: String, slug: String,
@@ -49,7 +53,10 @@ export default {
}) })
onMounted(() => { onMounted(() => {
axios.get(url + "/api/articles") axios.get(url + "/api/articles/feed",{
headers:{
Authorization : "TOKEN " + token
}})
.then(response => { .then(response => {
console.log(response); console.log(response);
articles.article = response.data.articles; articles.article = response.data.articles;
@@ -58,12 +65,15 @@ export default {
console.log(typeof(articles.article)); console.log(typeof(articles.article));
console.log(articles.articlesCount); console.log(articles.articlesCount);
emit("loading",false); emit("loading",false);
if(parseInt(articles.articlesCount) == 0) {
emit("emptied",true);
}
}); });
}) })
return { articles } return { empty, articles }
} }
} })
</script> </script>
<style scoped> <style scoped>

View File

@@ -0,0 +1,13 @@
<template>
</template>
<script lang="ts">
export default {
name: "ArticleListGlobal"
}
</script>
<style scoped>
</style>

View File

@@ -12,7 +12,7 @@ export default createStore({
}, },
setToken(state, token){ setToken(state, token){
state.token = token; state.token = token;
} },
}, },
actions: { actions: {
LOGIN({commit}, user){ LOGIN({commit}, user){

View File

@@ -15,23 +15,28 @@
<div class="col-md-9"> <div class="col-md-9">
<div class="feed-toggle"> <div class="feed-toggle">
<ul class="nav nav-pills outline-active"> <ul class="nav nav-pills outline-active">
<li class="nav-item"> <li class="nav-item" v-if="isLogin">
<a class="nav-link active">Your Feed</a> <a class="nav-link active">Your Feed</a>
<div v-if="isLoading"> <div v-if="isLoading">
Loading articles... Loading articles...
</div> </div>
<div v-if="isEmpty">
No articles are here... yet.
</div>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link">Global Feed</a> <a class="nav-link">Global Feed</a>
</li> </li>
</ul> </ul>
</div> </div>
<article-list :value="isLoading" @loading="onChangeLoading"></article-list> <div v-if="isLogin">
<article-list
:value="isLoading"
:value2="isEmpty"
@loading="onChangeLoading"
@emptied="emptyCheck"></article-list>
</div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<div class="sidebar"> <div class="sidebar">
<p>Popular Tags</p> <p>Popular Tags</p>
@@ -57,19 +62,26 @@
<script lang="ts"> <script lang="ts">
import articleList from '@/components/TheArticleList.vue' import articleList from '@/components/ArticleListFeed.vue'
import {ref} from "vue"; import {ref} from "vue";
import {useStore} from "vuex";
export default { export default {
name: "TheHome", name: "TheHome",
components: {'article-list': articleList}, components: {'article-list': articleList},
setup(){ setup(){
const isLoading = ref(true); const isLoading = ref(true);
const isEmpty = ref(false);
const store = useStore();
const isLogin = store.state.token == '' ? false : true;
const onChangeLoading = (val : boolean) => { const onChangeLoading = (val : boolean) => {
console.log("HELLO?");
isLoading.value = val; isLoading.value = val;
} }
const emptyCheck = (val: boolean) => {
isEmpty.value = val;
}
return { isLoading, onChangeLoading }; return { isLoading, isEmpty, isLogin, onChangeLoading, emptyCheck };
} }
} }
</script> </script>

View File

@@ -84,8 +84,9 @@ export default {
user user
}) })
.then(response => { .then(response => {
store.dispatch("LOGIN",response.data.user).then(allHideError); allHideError();
router.push({name: "Home"}); store.dispatch("LOGIN",response.data.user);
router.push({name:"Home"});
}) })
.catch(error =>{ .catch(error =>{
const code = error.response.data.errors.code; const code = error.response.data.errors.code;