Skip to content

Commit 567bd62

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 <[email protected]>
1 parent 022117d commit 567bd62

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/NotificationsApp.vue

Lines changed: 9 additions & 1 deletion
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
@@ -255,6 +258,8 @@ export default {
255258
256259
onOpen() {
257260
this.requestWebNotificationPermissions()
261+
setCurrentTabAsActive(this.tabId)
262+
this._fetch()
258263
},
259264
260265
handleNetworkOffline() {
@@ -282,6 +287,8 @@ export default {
282287
.delete(generateOcsUrl('apps/notifications/api/v2/notifications'))
283288
.then(() => {
284289
this.notifications = []
290+
this.open = false
291+
setCurrentTabAsActive(this.tabId)
285292
})
286293
.catch(() => {
287294
showError(t('notifications', 'Failed to dismiss all notifications'))
@@ -290,6 +297,7 @@ export default {
290297
291298
onRemove(index) {
292299
this.notifications.splice(index, 1)
300+
setCurrentTabAsActive(this.tabId)
293301
},
294302
295303
/**

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)