mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-23 15:41:33 +00:00
Abstract useEmailSelection into separate function
This commit is contained in:
@@ -23,17 +23,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { format } from 'date-fns'
|
import { format } from 'date-fns'
|
||||||
import { ref } from 'vue';
|
import useEmailSelection from '../composition/useEmailSelection';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup(){
|
setup(){
|
||||||
let selectedEmailIds = ref(new Set(['1', '5']))
|
let {selectedEmailIds, toggleEmailSelection} = useEmailSelection();
|
||||||
let toggleEmailSelection = (id) => {
|
|
||||||
if(selectedEmailIds.value.has(id)) {
|
|
||||||
selectedEmailIds.value.delete(id)
|
|
||||||
} else {
|
|
||||||
selectedEmailIds.value.add(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {format, selectedEmailIds, toggleEmailSelection}
|
return {format, selectedEmailIds, toggleEmailSelection}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
19
src/composition/useEmailSelection.js
Normal file
19
src/composition/useEmailSelection.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
export const useEmailSelection = function(){
|
||||||
|
let selectedEmailIds = ref(new Set(['1', '5']))
|
||||||
|
let toggleEmailSelection = (id) => {
|
||||||
|
if(selectedEmailIds.value.has(id)) {
|
||||||
|
selectedEmailIds.value.delete(id)
|
||||||
|
} else {
|
||||||
|
selectedEmailIds.value.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
selectedEmailIds,
|
||||||
|
toggleEmailSelection
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useEmailSelection;
|
||||||
Reference in New Issue
Block a user