Skip to content

Commit

Permalink
chore: create folder for pages components
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-acampora committed Oct 11, 2023
1 parent b4f405f commit 50342da
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 97 deletions.
10 changes: 9 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<template>
<v-app light>
<AppBar title=""/>
<v-main class="pt-0">
<router-view></router-view>
</v-main>
</v-app>
</template>

</template>
<script>
import AppBar from "@/components/appbar/AppBar";
export default {
name: "App",
components: {
AppBar,
}
};
</script>
63 changes: 0 additions & 63 deletions src/components/Example.vue

This file was deleted.

18 changes: 16 additions & 2 deletions src/components/appbar/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
</v-toolbar-title>
<v-spacer/>

<v-btn to="/login">
<v-btn to="/login" v-if="!loggedIn">
<span>Login</span>
</v-btn>
<v-btn to="/signup" class="mr-5">
<v-btn to="/signup" class="mr-5" v-if="!loggedIn">
<span>Signup</span>
</v-btn>
<v-btn @click.prevent="logout" class="mr-5" v-if="loggedIn">
<span>Logout</span>
</v-btn>
</v-app-bar>
</v-row>
</template>
Expand All @@ -33,6 +36,17 @@ export default {
props: {
title: String,
},
computed: {
loggedIn() {
return this.$store.state.auth.status.loggedIn;
},
},
methods: {
logout() {
this.$store.dispatch("auth/logout")
this.$router.push("/login")
}
}
};
</script>

Expand Down
12 changes: 3 additions & 9 deletions src/components/profile.vue → src/pages/dashboard/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<div>
{{ data }}
</div>
<v-btn @click.prevent="logout">
<span>Logout</span>
</v-btn>
</template>

<script>
Expand All @@ -22,17 +19,14 @@ import userService from '@/services/user.service';
methods: {
fetchData() {
userService.getUserInfo()
.then(() => {
.then((response) => {
console.log(response)
this.data = "profile";
})
.catch(error => {
console.error('Errore durante la richiesta:', error);
});
},
logout(){
this.$store.dispatch("auth/logout")
this.$router.push("/login")
}
},
}
};
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<template>
<AppBar title=""/>
<v-main class="pt-0">
<v-container fluid>
<v-row>
<!-- Title Column -->
Expand All @@ -21,17 +19,12 @@
</v-col>
</v-row>
</v-container>
</v-main>
</template>

<script>
import AppBar from "../../components/appbar/AppBar.vue";
export default {
name: "HomePage",
components: {
AppBar,
},
data() {
return {
serverMsg: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
},
created() {
if (this.loggedIn) {
this.$router.push("/profile");
this.$router.push("/dashboard");
}
},
methods: {
Expand All @@ -35,11 +35,10 @@ export default {
email: this.email,
password: this.password
}
console.log(user)
this.$store.dispatch("auth/login", user)
.then(
() => {
this.$router.push("/profile")
this.$router.push("/dashboard")
}
)
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<template>
<v-main>
<v-container fluid>
<v-row justify="center">
<v-col cols="12" xs="10" md="4" l="4" xl="2">
Expand Down Expand Up @@ -27,7 +26,6 @@
</v-col>
</v-row>
</v-container>
</v-main>
</template>

<script>
Expand Down Expand Up @@ -56,7 +54,7 @@ export default {
},
mounted() {
if (this.loggedIn) {
this.$router.push("/profile");
this.$router.push("/dashboard");
}
},
methods: {
Expand Down
15 changes: 6 additions & 9 deletions src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { createRouter, createWebHashHistory } from "vue-router";

import HomePage from "../components/homepage/HomePage.vue";
import ExampleComponent from "../components/Example.vue";
import PageNotFound from "../components/pageNotFound/PageNotFound.vue";
import Login from "../components/authentication/Login.vue";
import Signup from "../components/authentication/Signup.vue";
import Profile from "../components/profile.vue";
import HomePage from "../pages/home/HomePage.vue";
import PageNotFound from "../pages/notFound/PageNotFound.vue";
import Login from "../pages/login/Login.vue";
import Signup from "../pages/signup/Signup.vue";
import Dashboard from "../pages/dashboard/dashboard.vue";
import store from '@/store'


const routes = [
{ path: "/", component: HomePage, alias: "/home" },
{ path: "/example", component: ExampleComponent },
{ path: "/login", name: "login", component: Login },
{ path: "/signup", name: "signup", component: Signup },
{ path: "/profile", name: "profile", component: Profile, meta:{requiresAuth:true}},
{ path: "/dashboard", name: "dashboard", component: Dashboard, meta:{requiresAuth:true}},
{ path: "/:pathMatch(.*)*", name: "not-found", component: PageNotFound },
{ path: "/:pathMatch(.*)", name: "bad-not-found", component: PageNotFound },
];
Expand All @@ -27,7 +25,6 @@ const router = createRouter({
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
const auth = store.state.auth.status.loggedIn
console.log(auth)
if (auth) {
next();
} else {
Expand Down

0 comments on commit 50342da

Please sign in to comment.