Skip to content

Commit 1398543

Browse files
committed
fix(multi-tab): Fix interactions when multiple tabs are active
- Deleting a notification in a tab makes that tab the active one - Deleting all notifications makes the tab the active one - Clicking the bell loads the newest state from the shared storage Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 022117d commit 1398543

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/NotificationsApp.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ import IconClose from 'vue-material-design-icons/Close.vue'
9696
import IconMessageOutline from 'vue-material-design-icons/MessageOutline.vue'
9797
import IconNotification from './Components/IconNotification.vue'
9898
import NotificationItem from './Components/NotificationItem.vue'
99-
import { getNotificationsData } from './services/notificationsService.js'
99+
import {
100+
getNotificationsData,
101+
setCurrentTabAsActive,
102+
} from './services/notificationsService.js'
100103
import { createWebNotification } from './services/webNotificationsService.js'
101104
102105
const sessionKeepAlive = loadState('core', 'config', { session_keepalive: true }).session_keepalive
@@ -253,8 +256,11 @@ export default {
253256
}
254257
},
255258
256-
onOpen() {
259+
async onOpen() {
257260
this.requestWebNotificationPermissions()
261+
262+
await setCurrentTabAsActive(this.tabId)
263+
await this._fetch()
258264
},
259265
260266
handleNetworkOffline() {
@@ -282,6 +288,8 @@ export default {
282288
.delete(generateOcsUrl('apps/notifications/api/v2/notifications'))
283289
.then(() => {
284290
this.notifications = []
291+
this.open = false
292+
setCurrentTabAsActive(this.tabId)
285293
})
286294
.catch(() => {
287295
showError(t('notifications', 'Failed to dismiss all notifications'))
@@ -290,6 +298,7 @@ export default {
290298
291299
onRemove(index) {
292300
this.notifications.splice(index, 1)
301+
setCurrentTabAsActive(this.tabId)
293302
},
294303
295304
/**

src/services/notificationsService.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ async function getNotificationsData(tabId, lastETag, forceRefresh, hasNotifyPush
4242
}
4343
}
4444

45+
/**
46+
* @param {string|null} tabId unique id for browser tab
47+
*/
48+
async function setCurrentTabAsActive(tabId) {
49+
const lastTab = BrowserStorage.getItem('tabId')
50+
if (lastTab !== tabId) {
51+
// Refresh the data when changing the tab
52+
await getNotificationsData(tabId, '', true, false)
53+
// Enforce this tab one the raise-condition if there was one
54+
BrowserStorage.setItem('tabId', tabId)
55+
}
56+
}
57+
4558
/**
4659
* @param {object} notification notification object
4760
*/
@@ -90,4 +103,5 @@ async function refreshData(lastETag) {
90103

91104
export {
92105
getNotificationsData,
106+
setCurrentTabAsActive,
93107
}

0 commit comments

Comments
 (0)