Toggle home page if user is not logged in to welcome page.
This commit is contained in:
parent
07f50afa32
commit
29c5076c41
8 changed files with 106 additions and 29 deletions
19
src/App.vue
19
src/App.vue
|
|
@ -1,14 +1,18 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { RouterView } from 'vue-router'
|
import { RouterView } from 'vue-router'
|
||||||
|
import { useUserStore } from "@/stores/userStore";
|
||||||
|
|
||||||
import Footer from "@/components/Footer.vue";
|
import Footer from "@/components/Footer.vue";
|
||||||
import Sidebar from "@/components/Sidebar.vue";
|
import Sidebar from "@/components/Sidebar.vue";
|
||||||
import TopBar from "@/components/TopBar.vue";
|
import TopBar from "@/components/TopBar.vue";
|
||||||
|
|
||||||
|
const userStore = useUserStore();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="act-layout">
|
<div class="act-layout">
|
||||||
<TopBar class="act-header"></TopBar>
|
<TopBar class="act-header"></TopBar>
|
||||||
<div class="act-sidebar">
|
<div class="act-sidebar" v-if="!userStore.isAnonymous">
|
||||||
<Sidebar></Sidebar>
|
<Sidebar></Sidebar>
|
||||||
</div>
|
</div>
|
||||||
<div class="act-content">
|
<div class="act-content">
|
||||||
|
|
@ -24,19 +28,18 @@ import TopBar from "@/components/TopBar.vue";
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
$header-height: 60px !default;
|
$header-height: 60px !default;
|
||||||
$footer-height: 90px !default;
|
$sidebar-size: 90px !default;
|
||||||
$footer-width: 100px !default;
|
|
||||||
|
|
||||||
.act-layout {
|
.act-layout {
|
||||||
// To scroll only in the middle, see https://jsfiddle.net/VNVqs/
|
// To scroll only in the middle, see https://jsfiddle.net/VNVqs/
|
||||||
margin-bottom: $footer-height; // for scrolling
|
margin-bottom: $sidebar-size; // for scrolling
|
||||||
margin-top: $header-height; // for scrolling
|
margin-top: $header-height; // for scrolling
|
||||||
.act-footer {
|
.act-footer {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.act-sidebar {
|
.act-sidebar {
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
height: $footer-height;
|
height: $sidebar-size;
|
||||||
left: 0;
|
left: 0;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|
@ -52,7 +55,7 @@ $footer-width: 100px !default;
|
||||||
}
|
}
|
||||||
@media (screen(sm)) {
|
@media (screen(sm)) {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
margin-left: $footer-width;
|
margin-left: $sidebar-size;
|
||||||
.act-footer {
|
.act-footer {
|
||||||
display: block
|
display: block
|
||||||
}
|
}
|
||||||
|
|
@ -60,10 +63,10 @@ $footer-width: 100px !default;
|
||||||
left: 0;
|
left: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
width: $footer-width;
|
width: $sidebar-size;
|
||||||
}
|
}
|
||||||
.act-header {
|
.act-header {
|
||||||
left: $footer-width;
|
left: $sidebar-size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,9 @@
|
||||||
</a>
|
</a>
|
||||||
<RouterLink
|
<RouterLink
|
||||||
class="nav-item"
|
class="nav-item"
|
||||||
to="/about">
|
to="/profile">
|
||||||
<i class="pi pi-info-circle nav-icon" />
|
<i class="pi pi-user nav-icon" />
|
||||||
<span>About</span>
|
<span>Profile</span>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
</nav>
|
</nav>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {ref} from "vue";
|
import {ref} from "vue";
|
||||||
|
import {useRouter} from "vue-router";
|
||||||
|
|
||||||
import Avatar from 'primevue/avatar';
|
import Avatar from 'primevue/avatar';
|
||||||
import Menu from "primevue/menu";
|
import Menu from "primevue/menu";
|
||||||
|
|
@ -10,15 +11,24 @@ import Navigation from "@/components/Navigation.vue";
|
||||||
|
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
userStore.logout();
|
userStore.logout();
|
||||||
};
|
};
|
||||||
|
const profile = () => {
|
||||||
|
router.push({name: "profile"});
|
||||||
|
};
|
||||||
|
|
||||||
// Attach handlers.
|
// Attach handlers.
|
||||||
userActions.map((item) => {
|
userActions.map((item) => {
|
||||||
if (item.cmd === 'logout') {
|
switch (item.cmd) {
|
||||||
item.command = logout;
|
case "logout":
|
||||||
|
item.command = logout;
|
||||||
|
break;
|
||||||
|
case "profile":
|
||||||
|
item.command = profile;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const items = ref(userActions);
|
const items = ref(userActions);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ const toggle = (event) => {
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
userStore.logout();
|
userStore.logout();
|
||||||
};
|
};
|
||||||
|
const profile = () => {
|
||||||
|
router.push({name: "profile"});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const menu = ref();
|
const menu = ref();
|
||||||
|
|
@ -40,8 +43,13 @@ const localActions = [{
|
||||||
}];
|
}];
|
||||||
const allActions = [...userActions, ...localActions];
|
const allActions = [...userActions, ...localActions];
|
||||||
allActions.map((item) => {
|
allActions.map((item) => {
|
||||||
if (item.cmd === 'logout') {
|
switch (item.cmd) {
|
||||||
item.command = logout;
|
case "logout":
|
||||||
|
item.command = logout;
|
||||||
|
break;
|
||||||
|
case "profile":
|
||||||
|
item.command = profile;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const items = ref(allActions);
|
const items = ref(allActions);
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,18 @@
|
||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
|
|
||||||
|
import { useUserStore } from "@/stores/userStore";
|
||||||
import AboutView from '../views/AboutView.vue'
|
import AboutView from '../views/AboutView.vue'
|
||||||
import HomeView from '../views/HomeView.vue'
|
import HomeView from '../views/HomeView.vue'
|
||||||
import LoginView from '../views/LoginView.vue'
|
import LoginView from '../views/LoginView.vue'
|
||||||
import ProfileView from '../views/ProfileView.vue'
|
import ProfileView from '../views/ProfileView.vue'
|
||||||
import StickerBuilderView from '../views/StickerBuilderView.vue'
|
import StickerBuilderView from '../views/StickerBuilderView.vue'
|
||||||
import StickerView from '../views/StickerView.vue'
|
import StickerView from '../views/StickerView.vue'
|
||||||
|
import WelcomeView from '../views/WelcomeView.vue'
|
||||||
|
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(import.meta.env.BASE_URL),
|
history: createWebHistory(import.meta.env.BASE_URL),
|
||||||
routes: [
|
routes: [
|
||||||
{
|
|
||||||
component: ProfileView,
|
|
||||||
meta: {
|
|
||||||
title: '',
|
|
||||||
},
|
|
||||||
name: 'profile',
|
|
||||||
path: '/',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
component: AboutView,
|
component: AboutView,
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -25,6 +21,22 @@ const router = createRouter({
|
||||||
name: 'about',
|
name: 'about',
|
||||||
path: '/about',
|
path: '/about',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
component: HomeView,
|
||||||
|
meta: {
|
||||||
|
title: 'Home',
|
||||||
|
},
|
||||||
|
name: 'home',
|
||||||
|
path: '/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: ProfileView,
|
||||||
|
meta: {
|
||||||
|
title: 'Profile',
|
||||||
|
},
|
||||||
|
name: 'profile',
|
||||||
|
path: '/profile',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
component: StickerBuilderView,
|
component: StickerBuilderView,
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -49,7 +61,24 @@ const router = createRouter({
|
||||||
name: 'login',
|
name: 'login',
|
||||||
path: '/login',
|
path: '/login',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
component: WelcomeView,
|
||||||
|
meta: {
|
||||||
|
title: 'Welcome',
|
||||||
|
},
|
||||||
|
name: 'welcome',
|
||||||
|
path: '/welcome',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.beforeEach((to, from) => {
|
||||||
|
const userStore= useUserStore();
|
||||||
|
if (userStore.isAnonymous && to.name == 'home') {
|
||||||
|
return {name: 'welcome'};
|
||||||
|
} else if (!userStore.isAnonymous && to.name == 'welcome') {
|
||||||
|
return {name: 'home'};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
export const userActions = [{
|
export const userActions = [{
|
||||||
icon: 'pi pi-inbox',
|
cmd: 'profile',
|
||||||
label: 'Inbox',
|
icon: 'pi pi-user',
|
||||||
|
label: 'Profile',
|
||||||
needsAuth: true,
|
needsAuth: true,
|
||||||
}, {
|
}, {
|
||||||
icon: 'pi pi-bell',
|
icon: 'pi pi-bell',
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,26 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import TheWelcome from '../components/TheWelcome.vue'
|
import Panel from 'primevue/panel';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<main>
|
<h1>Activity</h1>
|
||||||
<TheWelcome />
|
<Panel header="user1 contributed to project1">
|
||||||
</main>
|
item 1
|
||||||
|
</Panel>
|
||||||
|
<Panel header="user2 contributed to project2">
|
||||||
|
item 2
|
||||||
|
</Panel>
|
||||||
|
<Panel header="user3 contributed to project3">
|
||||||
|
item 3
|
||||||
|
</Panel>
|
||||||
|
<Panel header="user4 contributed to project4">
|
||||||
|
item 4
|
||||||
|
</Panel>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
h1 {
|
||||||
|
font-size: 150%;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
||||||
9
src/views/WelcomeView.vue
Normal file
9
src/views/WelcomeView.vue
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import TheWelcome from '../components/TheWelcome.vue'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<main>
|
||||||
|
<TheWelcome />
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
Loading…
Reference in a new issue