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>
|
||||
<table class="mail-table">
|
||||
{{emailSelection.emails.size}}
|
||||
<BulkActionBar />
|
||||
|
||||
<tbody>
|
||||
<tr v-for="email in unarchivedEmails"
|
||||
:key="email.id"
|
||||
@@ -33,7 +34,8 @@
|
||||
import axios from 'axios';
|
||||
import MailView from '@/components/MailView.vue';
|
||||
import ModalView from '@/components/ModalView.vue';
|
||||
import { reactive } from 'vue';
|
||||
import BulkActionBar from '@/components/BulkActionBar.vue';
|
||||
import { useEmailSelection } from '../composition/useEmailSelection';
|
||||
|
||||
export default {
|
||||
async setup(){
|
||||
@@ -41,17 +43,7 @@
|
||||
let emails = response.data;
|
||||
let openedEmail = null;
|
||||
|
||||
|
||||
let emailSelection = reactive({
|
||||
emails: new Set(),
|
||||
toggle(id) {
|
||||
if(this.emails.has(id)) {
|
||||
this.emails.delete(id)
|
||||
} else {
|
||||
this.emails.add(id);
|
||||
}
|
||||
},
|
||||
})
|
||||
let { emailSelection } = useEmailSelection();
|
||||
|
||||
return {
|
||||
format,
|
||||
@@ -62,7 +54,8 @@
|
||||
},
|
||||
components: {
|
||||
MailView,
|
||||
ModalView
|
||||
ModalView,
|
||||
BulkActionBar
|
||||
},
|
||||
computed: {
|
||||
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