add notifications
This commit is contained in:
parent
d2487a86a4
commit
b28c897f5d
5
hn-vue/package-lock.json
generated
5
hn-vue/package-lock.json
generated
@ -11026,6 +11026,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/vuelidate/-/vuelidate-0.7.6.tgz",
|
"resolved": "https://registry.npmjs.org/vuelidate/-/vuelidate-0.7.6.tgz",
|
||||||
"integrity": "sha512-suzIuet1jGcyZ4oUSW8J27R2tNrJ9cIfklAh63EbAkFjE380iv97BAiIeolRYoB9bF9usBXCu4BxftWN1Dkn3g=="
|
"integrity": "sha512-suzIuet1jGcyZ4oUSW8J27R2tNrJ9cIfklAh63EbAkFjE380iv97BAiIeolRYoB9bF9usBXCu4BxftWN1Dkn3g=="
|
||||||
},
|
},
|
||||||
|
"vuex": {
|
||||||
|
"version": "3.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/vuex/-/vuex-3.6.0.tgz",
|
||||||
|
"integrity": "sha512-W74OO2vCJPs9/YjNjW8lLbj+jzT24waTo2KShI8jLvJW8OaIkgb3wuAMA7D+ZiUxDOx3ubwSZTaJBip9G8a3aQ=="
|
||||||
|
},
|
||||||
"watchpack": {
|
"watchpack": {
|
||||||
"version": "1.7.5",
|
"version": "1.7.5",
|
||||||
"resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.7.5.tgz",
|
"resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.7.5.tgz",
|
||||||
|
|||||||
@ -11,7 +11,8 @@
|
|||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"vue": "^2.6.11",
|
"vue": "^2.6.11",
|
||||||
"vue-router": "^3.4.9",
|
"vue-router": "^3.4.9",
|
||||||
"vuelidate": "^0.7.6"
|
"vuelidate": "^0.7.6",
|
||||||
|
"vuex": "^3.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vue/cli-plugin-babel": "~4.5.0",
|
"@vue/cli-plugin-babel": "~4.5.0",
|
||||||
|
|||||||
@ -6,5 +6,14 @@
|
|||||||
<router-link :to="{ name: 'register' }">Créer un compte</router-link>
|
<router-link :to="{ name: 'register' }">Créer un compte</router-link>
|
||||||
</nav>
|
</nav>
|
||||||
<router-view></router-view>
|
<router-view></router-view>
|
||||||
|
<notifications-panel />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import NotificationsPanel from "./components/NotificationsPanel";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: { NotificationsPanel },
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|||||||
19
hn-vue/src/components/NotificationsPanel.vue
Normal file
19
hn-vue/src/components/NotificationsPanel.vue
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<h2>Mes notifications</h2>
|
||||||
|
<p v-if="messages.length === 0">Aucune notification disponible ...</p>
|
||||||
|
<ul v-else>
|
||||||
|
<li v-for="message in messages" :key="message">{{ message }}</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { mapState } from "vuex";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
computed: {
|
||||||
|
...mapState(["messages"]),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@ -2,13 +2,18 @@ import Vue from "vue";
|
|||||||
import Vuelidate from "vuelidate";
|
import Vuelidate from "vuelidate";
|
||||||
import Layout from "./Layout.vue";
|
import Layout from "./Layout.vue";
|
||||||
import createRouter from "./router";
|
import createRouter from "./router";
|
||||||
|
import createStore from "./store";
|
||||||
|
import Notifications from "./plugins/Notifications";
|
||||||
|
|
||||||
Vue.config.productionTip = false;
|
Vue.config.productionTip = false;
|
||||||
Vue.use(Vuelidate);
|
Vue.use(Vuelidate);
|
||||||
|
Vue.use(Notifications);
|
||||||
|
|
||||||
const router = createRouter();
|
const router = createRouter();
|
||||||
|
const store = createStore();
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
router,
|
router,
|
||||||
|
store,
|
||||||
render: (h) => h(Layout),
|
render: (h) => h(Layout),
|
||||||
}).$mount("#app");
|
}).$mount("#app");
|
||||||
|
|||||||
@ -42,7 +42,10 @@ export default {
|
|||||||
password: this.password,
|
password: this.password,
|
||||||
confirmPassword: this.confirmPassword,
|
confirmPassword: this.confirmPassword,
|
||||||
});
|
});
|
||||||
this.$router.push({ name: "links" });
|
this.$redirectWithMessage(
|
||||||
|
{ name: "links" },
|
||||||
|
"Votre compte a bien été créé !"
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.err = e;
|
this.err = e;
|
||||||
}
|
}
|
||||||
|
|||||||
12
hn-vue/src/plugins/Notifications.js
Normal file
12
hn-vue/src/plugins/Notifications.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
export default {
|
||||||
|
install(Vue) {
|
||||||
|
Vue.prototype.$message = function(message) {
|
||||||
|
this.$store.dispatch("addMessage", message);
|
||||||
|
};
|
||||||
|
|
||||||
|
Vue.prototype.$redirectWithMessage = function(to, message) {
|
||||||
|
this.$message(message);
|
||||||
|
this.$router.push(to);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
27
hn-vue/src/store.js
Normal file
27
hn-vue/src/store.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import Vue from "vue";
|
||||||
|
import Vuex from "vuex";
|
||||||
|
|
||||||
|
Vue.use(Vuex);
|
||||||
|
|
||||||
|
export default function createStore() {
|
||||||
|
return new Vuex.Store({
|
||||||
|
state: {
|
||||||
|
messages: [],
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
pushMessage(state, message) {
|
||||||
|
state.messages = [...state.messages, message];
|
||||||
|
},
|
||||||
|
removeMessage(state, message) {
|
||||||
|
state.messages = state.messages.filter((m) => m !== message);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
addMessage({ commit }, message) {
|
||||||
|
commit("pushMessage", message);
|
||||||
|
|
||||||
|
setTimeout(() => commit("removeMessage", message), 3000);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user