Skip to content

Commit 221eade

Browse files
refactor: initialize session with store instance
Signed-off-by: Luka Trovic <[email protected]>
1 parent 4fb0388 commit 221eade

File tree

3 files changed

+32
-51
lines changed

3 files changed

+32
-51
lines changed

src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import { subscribe } from '@nextcloud/event-bus'
1313
import ClickOutside from 'vue-click-outside'
1414
import './shared-init.js'
1515
import './models/index.js'
16-
import './sessions.js'
16+
import { initSessions } from './sessions.js'
1717

1818
// the server snap.js conflicts with vertical scrolling so we disable it
1919
document.body.setAttribute('data-snap-ignore', 'true')
2020

2121
const store = storeFactory()
2222
sync(store, router)
23+
initSessions(store)
2324

2425
Vue.prototype.t = translate
2526
Vue.prototype.n = translatePlural

src/sessions.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { listen } from '@nextcloud/notify_push'
77
import { sessionApi } from './services/SessionApi.js'
8-
import storeFactory from './store/main.js'
98
import axios from '@nextcloud/axios'
109

1110
const SESSION_INTERVAL = 90 // in seconds
@@ -14,7 +13,7 @@ let hasPush = false
1413

1514
let syncRunning = false
1615

17-
const store = storeFactory()
16+
let store = null
1817

1918
/**
2019
* used to verify, whether an event is originated by ourselves
@@ -30,28 +29,35 @@ function isOurSessionToken(token) {
3029
}
3130
}
3231

33-
hasPush = listen('deck_board_update', (name, body) => {
34-
// ignore update events which we have triggered ourselves
35-
if (isOurSessionToken(body._causingSessionToken)) return
32+
/**
33+
*
34+
* @param storeInstance
35+
*/
36+
export function initSessions(storeInstance) {
37+
store = storeInstance
38+
hasPush = listen('deck_board_update', (name, body) => {
39+
// ignore update events which we have triggered ourselves
40+
if (isOurSessionToken(body._causingSessionToken)) return
3641

37-
// only handle update events for the currently open board
38-
const currentBoardId = store.state.currentBoard?.id
39-
if (body.id !== currentBoardId) return
42+
// only handle update events for the currently open board
43+
const currentBoardId = store.state.currentBoard?.id
44+
if (body.id !== currentBoardId) return
4045

41-
store.dispatch('refreshBoard', currentBoardId)
42-
})
46+
store.dispatch('refreshBoard', currentBoardId)
47+
})
4348

44-
listen('deck_card_update', (name, body) => {
49+
listen('deck_card_update', (name, body) => {
4550

46-
// ignore update events which we have triggered ourselves
47-
if (isOurSessionToken(body._causingSessionToken)) return
51+
// ignore update events which we have triggered ourselves
52+
if (isOurSessionToken(body._causingSessionToken)) return
4853

49-
// only handle update events for the currently open board
50-
const currentBoardId = store.state.currentBoard?.id
51-
if (body.boardId !== currentBoardId) return
54+
// only handle update events for the currently open board
55+
const currentBoardId = store.state.currentBoard?.id
56+
if (body.boardId !== currentBoardId) return
5257

53-
store.dispatch('loadStacks', currentBoardId)
54-
})
58+
store.dispatch('loadStacks', currentBoardId)
59+
})
60+
}
5561

5662
/**
5763
* is the notify_push app active and can

src/store/card.js

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -188,39 +188,13 @@ export default function cardModuleFactory() {
188188
return state.cards.find((card) => card.id === id)
189189
},
190190
},
191-
cardById: state => (id) => {
192-
return state.cards.find((card) => card.id === id)
193-
},
194-
},
195-
mutations: {
196-
addCard(state, card) {
197-
card.labels = card.labels || []
198-
card.assignedUsers = card.assignedUsers || []
199-
const existingIndex = state.cards.findIndex(_card => _card.id === card.id)
200-
if (existingIndex !== -1) {
201-
const existingCard = state.cards.find(_card => _card.id === card.id)
202-
Vue.set(state.cards, existingIndex, Object.assign({}, existingCard, card))
203-
} else {
204-
state.cards.push(card)
205-
}
206-
},
207-
deleteCard(state, card) {
208-
const existingIndex = state.cards.findIndex(_card => _card.id === card.id)
209-
if (existingIndex !== -1) {
210-
state.cards.splice(existingIndex, 1)
211-
}
212-
},
213-
updateCard(state, card) {
214-
const existingIndex = state.cards.findIndex(_card => _card.id === card.id)
215-
if (existingIndex !== -1) {
216-
Vue.set(state.cards, existingIndex, Object.assign({}, state.cards[existingIndex], card))
217-
}
218-
},
219-
updateCardsReorder(state, cards) {
220-
for (const newCard of cards) {
221-
const existingIndex = state.cards.findIndex(_card => _card.id === newCard.id)
191+
mutations: {
192+
addCard(state, card) {
193+
card.labels = card.labels || []
194+
card.assignedUsers = card.assignedUsers || []
195+
const existingIndex = state.cards.findIndex(_card => _card.id === card.id)
222196
if (existingIndex !== -1) {
223-
const existingCard = state.cards[existingIndex]
197+
const existingCard = state.cards.find(_card => _card.id === card.id)
224198
Vue.set(state.cards, existingIndex, Object.assign({}, existingCard, card))
225199
} else {
226200
state.cards.push(card)

0 commit comments

Comments
 (0)