Gmail API after deleting a draft, sidebar and counter not updated

Viewed 160

I'm having an issue. After I open a new compose view top programtically delete the draft, i run the block below to discard the draft. Initially I thought that this was not working because when I would execute it, I could still see the item in the left sidebar & counter. However when I refresh the page, I can see the draft is indeed deleted. Thoughts?

private async discardDraft() {
    const draftId = await this.composeView.getCurrentDraftID();
    gmailService.discardDraft(draftId);
    this.composeView.close();
}

export async function discardDraft(draftId: string) {
    return request.delete(`/gmail/v1/users/me/drafts/${draftId}`).then(res => true);
}

enter image description here

2 Answers

Try fetching the drafts list again after deleting to update, in essence change your discardDraft function to this:

export async function discardDraft(draftId: string) {
    await request.delete(`/gmail/v1/users/me/drafts/${draftId}`);
    return request.list('/gmail/v1/users/me/drafts').then(res => true);
}

Hope this Helps!

This seems very strange. As a workaround to resolve the things automatically, you can use the refresh() method of the ListRouteView which will basically simulate the action of pushing the refresh button from the Gmail panel (the whole page won't be reloaded).

In case you don't like this "not so clean" option you can check this documentation and maybe you can find more interesting functions that will give you more ideas of possible workarounds.

Related