mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-23 15:41:33 +00:00
Lesson 14, pt 1 - Bulk Action Bar Buttons
This commit is contained in:
@@ -8,8 +8,8 @@
|
|||||||
</span>
|
</span>
|
||||||
<span class="buttons">
|
<span class="buttons">
|
||||||
<button @click="emailSelection.markRead">Mark Read</button>
|
<button @click="emailSelection.markRead">Mark Read</button>
|
||||||
<button @click="emailSelection.markUnread()">Mark Unread</button>
|
<button @click="emailSelection.markUnread">Mark Unread</button>
|
||||||
<button @click="emailSelection.archive()">Archive</button>
|
<button @click="emailSelection.archive">Archive</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
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 BulkActionBar from '@/components/BulkActionBar.vue';
|
import BulkActionBar from '@/components/BulkActionBar.vue';
|
||||||
import { reactive } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
import useEmailSelection from '@/composables/use-email-selection'
|
import useEmailSelection from '@/composables/use-email-selection'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -42,8 +42,8 @@
|
|||||||
return {
|
return {
|
||||||
emailSelection: useEmailSelection(),
|
emailSelection: useEmailSelection(),
|
||||||
format,
|
format,
|
||||||
emails,
|
emails: ref(emails),
|
||||||
openedEmail: null
|
openedEmail: ref(null)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
@@ -19,19 +19,24 @@ export const useEmailSelection = function(){
|
|||||||
emails.add(email)
|
emails.add(email)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
let markRead = () => {
|
let forSelected = (fn) => {
|
||||||
emails.forEach((email) => {
|
emails.forEach((email) => {
|
||||||
email.read = true;
|
fn(email);
|
||||||
axios.put(`http://localhost:3000/emails/${email.id}`, email)
|
axios.put(`http://localhost:3000/emails/${email.id}`, email)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
let markRead = () => forSelected(e => e.read = true)
|
||||||
|
let markUnread = () => forSelected(e => e.read = false)
|
||||||
|
let archive = () => { forSelected(e => e.archived = true); clear() }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
emails,
|
emails,
|
||||||
toggle,
|
toggle,
|
||||||
clear,
|
clear,
|
||||||
addMultiple,
|
addMultiple,
|
||||||
markRead
|
markRead,
|
||||||
|
markUnread,
|
||||||
|
archive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user