-
Notifications
You must be signed in to change notification settings - Fork 0
Exercise 7 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Exercise 7 #15
Changes from all commits
4e2da46
915c38c
d0c57dc
768b930
8b5492a
140d234
1b79863
75fbc25
2d9f1a0
642e37a
268b116
ee22481
56767f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| /.idea/ | ||
| /webapp/coverage/ | ||
| /archive/ | ||
|
|
||
| /webapp/.nuxt-storybook | ||
| /webapp/storybook-static | ||
| git-crypt-key |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| <template> | ||
| <v-form v-model="isFormValid"> | ||
| <v-container> | ||
| <v-row> | ||
| <v-col> | ||
| <v-text-field | ||
| v-model="credentials.email" | ||
| id="email" | ||
| :rules="nameRules" | ||
| :counter="64" | ||
| label="User name" | ||
| required | ||
| ></v-text-field> | ||
| </v-col> | ||
| </v-row> | ||
| <v-row> | ||
| <v-col> | ||
| <v-text-field | ||
| v-model="credentials.password" | ||
| :rules="pwdRules" | ||
| label="Password" | ||
| id="password" | ||
| required | ||
| type="password" | ||
| ></v-text-field> | ||
| </v-col> | ||
| </v-row> | ||
| <v-row> | ||
| <v-col> | ||
| <v-btn | ||
| v-on:submit.prevent | ||
| id="login" | ||
| class="mr-4" | ||
| :disabled="!isFormValid" | ||
| @click="login" | ||
| > | ||
| Login | ||
| </v-btn> | ||
| </v-col> | ||
| </v-row> | ||
| </v-container> | ||
| </v-form> | ||
| </template> | ||
|
|
||
| <script> | ||
|
|
||
| import gql from 'graphql-tag'; | ||
|
|
||
| export default { | ||
| name: 'LoginForm', | ||
| data: () => ({ | ||
| isFormValid: false, | ||
| credentials: { | ||
| "email": '', | ||
| 'password': '', | ||
| }, | ||
| }), | ||
| methods: { | ||
| async login() { | ||
| const creds = this.credentials; | ||
| try { | ||
| const { data: { login } } = await this.$apollo.mutate({ | ||
| mutation: gql`mutation login($email: String!, $password: String!) { | ||
| login(email: $email, password: $password) | ||
| }`, | ||
| variables: creds, | ||
| }); | ||
|
|
||
| await this.$apolloHelpers.onLogin(login); // Stores the token in a cookie called apollo-token | ||
| this.$store.commit('setPrincipal', login); | ||
| } | ||
| catch (e) { | ||
| } | ||
| } | ||
| }, | ||
| computed: { | ||
| nameRules() { | ||
| return [ | ||
| name => { | ||
| return !!name || 'User name is required!' | ||
| }, | ||
| name => { | ||
| return name.length <= 64 || 'User name cannot exceed 64 chars!' | ||
| } | ||
| ] | ||
| }, | ||
| pwdRules() { | ||
| return [ | ||
| pwd => !!pwd || 'Password is required', | ||
| pwd => pwd.length >= 8 || 'Password must be at least 8 chars!' | ||
| ] | ||
| }, | ||
|
MaykAkifovski marked this conversation as resolved.
|
||
|
|
||
| }, | ||
| } | ||
| </script> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <template> | ||
| <div> | ||
| <v-app-bar | ||
| dense | ||
| light | ||
| > | ||
| <v-toolbar-title>Blog</v-toolbar-title> | ||
| <v-spacer></v-spacer> | ||
|
|
||
| <v-btn v-if="logged" @click="logout">Logout</v-btn> | ||
| <v-btn v-else><nuxt-link to="/login">Login</nuxt-link></v-btn> | ||
| </v-app-bar> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script> | ||
| import { mapGetters } from 'vuex' | ||
|
|
||
| export default { | ||
| name: 'Menu', | ||
| methods: { | ||
| async logout() { | ||
| await this.$apolloHelpers.onLogout(); // Deletes the cookie containing the token | ||
| this.$store.commit('removePrincipal'); | ||
| }, | ||
| }, | ||
| computed: { | ||
| ...mapGetters({ | ||
| logged: 'isAuthenticated', | ||
| }) | ||
| } | ||
| } | ||
| </script> | ||
|
MaykAkifovski marked this conversation as resolved.
|
||
|
|
||
| <style scoped> | ||
| button a { | ||
| color: inherit; | ||
| text-decoration: none; | ||
| } | ||
| </style> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,62 @@ | ||
| <template> | ||
| <div> | ||
| <h1>{{ newsItem.title }} {{ (newsItem.votes) }}</h1> | ||
| <button class="upvote" @click="incrementVotes">Upvote</button> | ||
| <button class="downvote" @click="decrementVotes">Downvote</button> | ||
| <button class="remove" @click="removeMe">Remove</button> | ||
| <button v-if="isAuth" class="upvote" @click="incrementVotes">Upvote</button> | ||
| <button v-if="isAuth" class="downvote" @click="decrementVotes">Downvote</button> | ||
| <button v-if="ownsPost" class="remove" @click="removeMe">Remove</button> | ||
|
MaykAkifovski marked this conversation as resolved.
|
||
| </div> | ||
| </template> | ||
|
|
||
| <script> | ||
| import gql from 'graphql-tag'; | ||
| import { mapGetters } from 'vuex'; | ||
| export default { | ||
| name: "NewsItem", | ||
| props: { | ||
| newsItem: { | ||
| title: {type: String, required: true}, | ||
| votes: {type: String, required: true}, | ||
| author: {type: Object, required: true} | ||
| } | ||
| }, | ||
| methods: { | ||
| incrementVotes() { | ||
| this.$emit('updateNews', { ...this.newsItem, votes: (this.newsItem.votes + 1)}) | ||
| async incrementVotes() { | ||
| const mutation = gql` | ||
| mutation ($title: ID!) { | ||
| upvote(title: $title) { | ||
| votes | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Request the |
||
| } | ||
| } | ||
| `; | ||
| try { | ||
| const { data: {upvote}} = await this.$apollo.mutate({ | ||
| mutation, | ||
| variables: { title: this.newsItem.title } | ||
| }) | ||
| this.$emit('updateNews', {...this.newsItem, votes: upvote.votes}); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could remove all code to update things that have been previously cached. |
||
| } | ||
| catch (e) { console.log(e.message); } | ||
| }, | ||
| decrementVotes() { | ||
| this.$emit('updateNews', { ...this.newsItem, votes: (this.newsItem.votes - 1)}) | ||
| }, | ||
| removeMe() { | ||
| this.$emit('removeNews', this.newsItem) | ||
| } | ||
| }, | ||
| computed: { | ||
| ...mapGetters({ | ||
| isAuth: 'isAuthenticated', | ||
| user: 'getPrincipal' | ||
| }), | ||
| ownsPost() { | ||
| return this.isAuth && this.user.id === this.newsItem.author.id; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| </script> | ||
|
|
||
| <style scoped> | ||
|
|
||
| </style> | ||
| </style> | ||
Uh oh!
There was an error while loading. Please reload this page.