mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-23 15:41:33 +00:00
Lesson 12 - use-email-selection composable
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<h1>VMail Inbox</h1>
|
<h1>VMail Inbox</h1>
|
||||||
|
|
||||||
|
<h1>{{emailSelection.emails.size}} emails selected</h1>
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<template #default>
|
<template #default>
|
||||||
@@ -14,10 +15,17 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import MailTable from '@/components/MailTable.vue';
|
import MailTable from '@/components/MailTable.vue';
|
||||||
|
import useEmailSelection from '@/composables/use-email-selection';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
components: {
|
components: {
|
||||||
MailTable
|
MailTable
|
||||||
|
},
|
||||||
|
setup(){
|
||||||
|
return {
|
||||||
|
emailSelection: useEmailSelection()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -32,25 +32,14 @@
|
|||||||
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 { reactive } from 'vue';
|
||||||
|
import useEmailSelection from '@/composables/use-email-selection'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async setup(){
|
async setup(){
|
||||||
let {data: emails} = await axios.get('http://localhost:3000/emails')
|
let {data: emails} = await axios.get('http://localhost:3000/emails')
|
||||||
|
|
||||||
let selected = reactive(new Set())
|
|
||||||
let emailSelection = {
|
|
||||||
emails: selected,
|
|
||||||
toggle(email) {
|
|
||||||
if(selected.has(email)) {
|
|
||||||
selected.delete(email)
|
|
||||||
} else {
|
|
||||||
selected.add(email)
|
|
||||||
}
|
|
||||||
console.log(selected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
emailSelection,
|
emailSelection: useEmailSelection(),
|
||||||
format,
|
format,
|
||||||
emails,
|
emails,
|
||||||
openedEmail: null
|
openedEmail: null
|
||||||
|
|||||||
20
src/composables/use-email-selection.js
Normal file
20
src/composables/use-email-selection.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { reactive } from 'vue';
|
||||||
|
|
||||||
|
let emails = reactive(new Set())
|
||||||
|
|
||||||
|
export const useEmailSelection = function(){
|
||||||
|
let toggle = function(email) {
|
||||||
|
if(emails.has(email)) {
|
||||||
|
emails.delete(email)
|
||||||
|
} else {
|
||||||
|
emails.add(email)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
emails,
|
||||||
|
toggle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useEmailSelection
|
||||||
Reference in New Issue
Block a user