Skip to content

Commit a9edd79

Browse files
committed
Remove nav logic from app component
1 parent 22ee86d commit a9edd79

File tree

2 files changed

+101
-101
lines changed

2 files changed

+101
-101
lines changed

src/App.vue

Lines changed: 14 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,34 @@
11
<template>
22
<div id="app">
3-
<div id="nav">
4-
<router-link to="/">Home</router-link>
5-
<router-link v-if="user" :to="{ name: 'dashboard' }"
6-
>Dashboard</router-link
7-
>
8-
<template v-if="!user">
9-
<router-link :to="{ name: 'authenticate' }" class="navButton">
10-
<span>Login</span>
11-
</router-link>
12-
</template>
13-
14-
<template v-else>
15-
<span>Hello, {{ user.name }}.</span>
16-
<button type="button" @click="logout">Log out</button>
17-
</template>
18-
</div>
19-
<router-view />
3+
<app-nav />
4+
<router-view class="page" />
205
</div>
216
</template>
227

238
<script>
9+
import AppNav from './components/AppNav'
10+
2411
export default {
25-
computed: {
26-
user() {
27-
return this.$store.state.user
28-
}
29-
},
30-
methods: {
31-
logout() {
32-
this.$store.dispatch('logout')
33-
}
34-
}
12+
name: 'App',
13+
components: { AppNav }
3514
}
3615
</script>
3716

38-
<style>
17+
<style lang="scss">
18+
@import "./assets/styles/global.scss";
3919
#app {
4020
font-family: 'Avenir', Helvetica, Arial, sans-serif;
4121
-webkit-font-smoothing: antialiased;
4222
-moz-osx-font-smoothing: grayscale;
4323
text-align: center;
4424
color: #2c3e50;
4525
}
46-
#nav {
26+
27+
.page{
4728
display: flex;
48-
flex-wrap: wrap;
49-
padding: 0.2em;
50-
margin-bottom: 3em;
51-
background: linear-gradient(to right, #16c0b0, #84cf6a);
52-
}
53-
#nav a {
54-
font-weight: bold;
55-
color: #2c3e50;
56-
margin: auto 0.8em auto 0.4em;
57-
}
58-
#nav a.router-link-exact-active {
59-
color: white;
60-
}
61-
#nav button {
62-
color: #2c3e50;
63-
background: white;
64-
margin-left: auto;
65-
}
66-
#nav span {
67-
margin: auto 1em auto 0em;
68-
}
69-
#nav a span {
70-
vertical-align: middle;
71-
margin: auto !important;
72-
}
73-
a:visited {
74-
color: #2c3e50;
75-
}
76-
body {
77-
padding: 0em;
78-
margin: 0em;
79-
}
80-
button {
81-
width: 5em;
82-
height: 2em;
83-
border-radius: 5%;
84-
margin: 0.5em;
85-
font-size: 1em;
86-
color: white;
87-
background: linear-gradient(to right, #16c0b0, #84cf6a);
88-
}
89-
form {
90-
display: block;
91-
width: 14em;
92-
margin: auto;
93-
}
94-
form p {
95-
color: red;
96-
}
97-
input {
98-
display: block;
99-
width: 100%;
100-
height: 1.6em;
101-
padding: 0.5em;
102-
margin-bottom: 1em;
103-
font: 1em 'Avenir', Helvetica, sans-serif;
104-
}
105-
.authLink {
106-
font-size: 0.8em;
107-
text-decoration: underline;
108-
color: #2c3e50;
109-
}
110-
.navButton {
111-
background: white;
112-
color: #2c3e50 !important;
113-
text-decoration: none;
114-
font-size: 1em;
115-
font-weight: 500 !important;
116-
width: 5em;
117-
height: 1.8em;
118-
border-radius: 5%;
119-
margin: 0.5em 0.5em 0.5em auto !important;
29+
justify-content: center;
30+
flex-direction: column;
31+
align-items: center;
32+
min-height: calc(100vh - 56px);
12033
}
12134
</style>

src/components/AppNav.vue

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<template>
2+
<div id="nav">
3+
<router-link to="/">
4+
Home
5+
</router-link>
6+
7+
<template v-if="user">
8+
<router-link to="dashboard">
9+
Dashboard
10+
</router-link>
11+
12+
<span class="nav-welcome">Hello, {{ user.name }}.</span>
13+
14+
<button type="button" @click="logout">
15+
Log out
16+
</button>
17+
</template>
18+
19+
<template v-else>
20+
<router-link to="authenticate" class="button">
21+
Login
22+
</router-link>
23+
</template>
24+
</div>
25+
</template>
26+
27+
<script>
28+
export default {
29+
name: 'AppNav',
30+
computed: {
31+
user () {
32+
return this.$store.state.user
33+
}
34+
},
35+
methods: {
36+
logout () {
37+
this.$store.dispatch('logout')
38+
}
39+
}
40+
}
41+
</script>
42+
43+
<style lang="scss" scoped>
44+
#nav {
45+
display: flex;
46+
align-items: center;
47+
min-height: 50px;
48+
padding: 0.2em 1em;
49+
background: linear-gradient(to right, #16c0b0, #84cf6a);
50+
}
51+
52+
.nav-welcome {
53+
margin-left: auto;
54+
margin-right: 1rem;
55+
color: white;
56+
}
57+
58+
a {
59+
font-weight: bold;
60+
color: #2c3e50;
61+
margin: auto 0.8em auto 0.4em;
62+
text-decoration: none;
63+
border-top: 2px solid transparent;
64+
border-bottom: 2px solid transparent;
65+
}
66+
67+
.router-link-exact-active {
68+
color: white;
69+
border-bottom: 2px solid #fff;
70+
}
71+
72+
button,
73+
.button {
74+
margin-left: auto;
75+
background: white;
76+
text-decoration: none;
77+
color: #2c3e50;
78+
79+
&.router-link-active {
80+
color: #2c3e50;
81+
}
82+
}
83+
84+
.nav-welcome + button {
85+
margin-left: 0;
86+
}
87+
</style>

0 commit comments

Comments
 (0)