mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-11 18:54:31 +00:00
Global non-persisted state with useEmailSelection composition function
This commit is contained in:
21
src/components/BulkActionBar.vue
Normal file
21
src/components/BulkActionBar.vue
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
{{emailSelection.emails.size}}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { useEmailSelection } from '../composition/useEmailSelection';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
setup(){
|
||||||
|
let { emailSelection } = useEmailSelection();
|
||||||
|
|
||||||
|
return { emailSelection }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<table class="mail-table">
|
<table class="mail-table">
|
||||||
{{emailSelection.emails.size}}
|
<BulkActionBar />
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="email in unarchivedEmails"
|
<tr v-for="email in unarchivedEmails"
|
||||||
:key="email.id"
|
:key="email.id"
|
||||||
@@ -33,7 +34,8 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import MailView from '@/components/MailView.vue';
|
import MailView from '@/components/MailView.vue';
|
||||||
import ModalView from '@/components/ModalView.vue';
|
import ModalView from '@/components/ModalView.vue';
|
||||||
import { reactive } from 'vue';
|
import BulkActionBar from '@/components/BulkActionBar.vue';
|
||||||
|
import { useEmailSelection } from '../composition/useEmailSelection';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async setup(){
|
async setup(){
|
||||||
@@ -41,17 +43,7 @@
|
|||||||
let emails = response.data;
|
let emails = response.data;
|
||||||
let openedEmail = null;
|
let openedEmail = null;
|
||||||
|
|
||||||
|
let { emailSelection } = useEmailSelection();
|
||||||
let emailSelection = reactive({
|
|
||||||
emails: new Set(),
|
|
||||||
toggle(id) {
|
|
||||||
if(this.emails.has(id)) {
|
|
||||||
this.emails.delete(id)
|
|
||||||
} else {
|
|
||||||
this.emails.add(id);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
format,
|
format,
|
||||||
@@ -62,7 +54,8 @@
|
|||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
MailView,
|
MailView,
|
||||||
ModalView
|
ModalView,
|
||||||
|
BulkActionBar
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
unarchivedEmails(){
|
unarchivedEmails(){
|
||||||
|
|||||||
19
src/composition/useEmailSelection.js
Normal file
19
src/composition/useEmailSelection.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { reactive } from 'vue';
|
||||||
|
|
||||||
|
let emails = new Set()
|
||||||
|
export const useEmailSelection = function(){
|
||||||
|
let emailSelection = reactive({
|
||||||
|
emails: emails,
|
||||||
|
toggle(id) {
|
||||||
|
if(this.emails.has(id)) {
|
||||||
|
this.emails.delete(id)
|
||||||
|
} else {
|
||||||
|
this.emails.add(id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return { emailSelection }
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useEmailSelection;
|
||||||
Reference in New Issue
Block a user