Skip to content

Commit

Permalink
refactor: reload thread every time all mails are reloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman committed Dec 2, 2024
1 parent 0f5a05b commit f172d1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
15 changes: 5 additions & 10 deletions frontend/src/components/MailDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
v-model="showSendModal"
:mailID="draftMailID"
:replyDetails="replyDetails"
@reloadMails="reloadMails"
@reloadMails="emit('reloadMails')"
/>
</template>
<script setup>
Expand Down Expand Up @@ -147,10 +147,10 @@ const mailThread = createResource({
auto: !!props.mailID,
})
const reloadMails = () => {
emit('reloadMails')
mailThread.reload()
const reloadThread = () => {
if (props.mailID) mailThread.reload()
}
defineExpose({ reloadThread })
const mailBody = (bodyHTML) => {
bodyHTML = bodyHTML.replace(/<br\s*\/?>/, '')
Expand Down Expand Up @@ -200,12 +200,7 @@ const getReplyHtml = (html, creation) => {
return `<br><blockquote>${replyHeader} <br> ${html}</blockquote>`
}
watch(
() => props.mailID,
(newName) => {
if (newName) mailThread.reload()
}
)
watch(() => props.mailID, reloadThread)
</script>
<style>
.prose
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/pages/Drafts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
</div>
<div class="flex-1 overflow-auto w-2/3">
<MailDetails
ref="mailDetails"
:mailID="currentMail.draft"
type="Outgoing Mail"
@reloadMails="reloadDrafts"
Expand All @@ -56,14 +57,15 @@
</template>
<script setup>
import { Breadcrumbs, createResource, createListResource } from 'frappe-ui'
import { computed, inject, watch } from 'vue'
import { ref, computed, inject, watch } from 'vue'
import HeaderActions from '@/components/HeaderActions.vue'
import { formatNumber, startResizing, singularize } from '@/utils'
import MailDetails from '@/components/MailDetails.vue'
import { useDebounceFn } from '@vueuse/core'
import SidebarDetail from '@/components/SidebarDetail.vue'
import { userStore } from '@/stores/user'
const mailDetails = ref(null)
const socket = inject('$socket')
const user = inject('$user')
const { currentMail, setCurrentMail } = userStore()
Expand All @@ -80,7 +82,9 @@ const draftMails = createListResource({
pageLength: 50,
cache: ['draftMails', user.data?.name],
onSuccess(data) {
if (!currentMail.draft && data.length) setCurrentMail('draft', data[0].name)
if (!data.length) return
if (!currentMail.draft) setCurrentMail('draft', data[0].name)
mailDetails.value?.reloadThread()
},
})
Expand Down

0 comments on commit f172d1d

Please sign in to comment.