feat: [FE] Profile and Settings connection, Implement Unfollow, follow API, getProfile.
This commit is contained in:
@@ -30,7 +30,8 @@ const routes = [
|
|||||||
{
|
{
|
||||||
path: "/@:username",
|
path: "/@:username",
|
||||||
name: "Profile",
|
name: "Profile",
|
||||||
component: () => import(/* webpackChunkName "inputTag" */ '@/views/TheProfile.vue')
|
component: () => import(/* webpackChunkName "inputTag" */ '@/views/TheProfile.vue'),
|
||||||
|
props: true
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ export default createStore({
|
|||||||
setToken(state, token){
|
setToken(state, token){
|
||||||
state.token = token;
|
state.token = token;
|
||||||
},
|
},
|
||||||
|
getToken(state){
|
||||||
|
return state.token
|
||||||
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
LOGIN({commit}, user){
|
LOGIN({commit}, user){
|
||||||
@@ -20,7 +23,7 @@ export default createStore({
|
|||||||
commit("setToken", user.token);
|
commit("setToken", user.token);
|
||||||
localStorage.setItem("username", user.username);
|
localStorage.setItem("username", user.username);
|
||||||
localStorage.setItem("token", user.token);
|
localStorage.setItem("token", user.token);
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,16 +7,29 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
<div class="col-xs-12 col-md-10 offset-md-1">
|
<div class="col-xs-12 col-md-10 offset-md-1">
|
||||||
<img src="http://i.imgur.com/Qr71crq.jpg" class="user-img"/>
|
<img :src="profile.image" class="user-img"/>
|
||||||
<h4>Eric Simons</h4>
|
<h4>{{ profile.username }}</h4>
|
||||||
<p>
|
<p>
|
||||||
Cofounder @GoThinkster, lived in Aol's HQ for a few months, kinda looks like Peeta from the
|
{{ profile.bio }}
|
||||||
Hunger Games
|
|
||||||
</p>
|
</p>
|
||||||
<button class="btn btn-sm btn-outline-secondary action-btn">
|
<button class="btn btn-sm btn-outline-secondary action-btn" @click="stateUpdate">
|
||||||
<i class="ion-plus-round"></i>
|
<div v-if="isMe">
|
||||||
|
<i class="ion-gear-a"></i>
|
||||||
Follow Eric Simons
|
|
||||||
|
Edit Profile Settings
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<div v-if="profile.following">
|
||||||
|
<i class="ion-plus-round"></i>
|
||||||
|
|
||||||
|
unFollow {{profile.username}}
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<i class="ion-plus-round"></i>
|
||||||
|
|
||||||
|
Follow {{profile.username}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -89,9 +102,84 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export default {
|
import {onMounted, reactive, ref, UnwrapNestedRefs} from "vue";
|
||||||
name: "TheProfile.vue"
|
import { useStore } from "vuex";
|
||||||
}
|
import axios from "axios";
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import router from "@/router";
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: "TheProfile.vue",
|
||||||
|
props:{
|
||||||
|
username: String,
|
||||||
|
},
|
||||||
|
setup(props){
|
||||||
|
|
||||||
|
const url = import.meta.env.VITE_BASE_URL;
|
||||||
|
const store = useStore();
|
||||||
|
const token = store.state.token;
|
||||||
|
|
||||||
|
const isMe = ref(false);
|
||||||
|
const profile = reactive({
|
||||||
|
image: "",
|
||||||
|
username: "",
|
||||||
|
bio: "",
|
||||||
|
following: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const setProfile = ( data: any ) => {
|
||||||
|
profile.image = data.image;
|
||||||
|
profile.bio = data.bio;
|
||||||
|
profile.following = data.following;
|
||||||
|
profile.username = data.username;
|
||||||
|
}
|
||||||
|
|
||||||
|
const stateUpdate = () => {
|
||||||
|
if(isMe.value){
|
||||||
|
router.push({name:"Settings"});
|
||||||
|
}else{
|
||||||
|
if(profile.following){
|
||||||
|
axios.delete(url + "/api/profiles/" + profile.username + "/follow",{
|
||||||
|
headers:{
|
||||||
|
Authorization : "TOKEN " + token,
|
||||||
|
"Content-Type": `application/json`,
|
||||||
|
}
|
||||||
|
}).then(response => {
|
||||||
|
setProfile(response.data.profile)
|
||||||
|
console.log(response)
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
axios.post(url + "/api/profiles/" + profile.username + "/follow",{
|
||||||
|
headers:{
|
||||||
|
Authorization : "TOKEN " + token,
|
||||||
|
"Content-Type": `application/json`,
|
||||||
|
}
|
||||||
|
}).then(response => {
|
||||||
|
setProfile(response.data.profile)
|
||||||
|
console.log(response)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
onMounted(() =>{
|
||||||
|
axios.get(url + "/api/profiles/" + props.username)
|
||||||
|
.then(response => {
|
||||||
|
const getProfile = response.data.profile;
|
||||||
|
setProfile(getProfile)
|
||||||
|
if(getProfile.username.localeCompare(store.state.username) == 0){
|
||||||
|
isMe.value = true;
|
||||||
|
}else{
|
||||||
|
isMe.value = false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return { url, isMe, profile, stateUpdate }
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export default {
|
|||||||
user.bio = getuser.bio
|
user.bio = getuser.bio
|
||||||
user.email = getuser.email
|
user.email = getuser.email
|
||||||
user.username = getuser.username
|
user.username = getuser.username
|
||||||
user.image = user.image
|
user.image = getuser.image
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateUser = () => {
|
const updateUser = () => {
|
||||||
@@ -73,7 +73,9 @@ export default {
|
|||||||
}})
|
}})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
store.dispatch("LOGIN",response.data.user);
|
store.dispatch("LOGIN",response.data.user);
|
||||||
router.push('/@'+ response.data.user.username);
|
router.push({
|
||||||
|
name: 'Profile',
|
||||||
|
params: {username: response.data.user.username}})
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error =>{
|
.catch(error =>{
|
||||||
@@ -90,10 +92,8 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
console.log(response)
|
store.dispatch("LOGIN",response.data.user)
|
||||||
window.localStorage.setItem("token",response.data.user.token);
|
|
||||||
getUser(response.data.user);
|
getUser(response.data.user);
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error =>{
|
.catch(error =>{
|
||||||
const code = error.response.data.errors.code;
|
const code = error.response.data.errors.code;
|
||||||
|
|||||||
Reference in New Issue
Block a user