Skip to content

Commit

Permalink
Tracker: Fix extra refresh (#2160)
Browse files Browse the repository at this point in the history
Signed-off-by: Dvinyanin Alexandr <dvinyanin.alexandr@gmail.com>
  • Loading branch information
Dvinyanin authored Jun 29, 2022
1 parent 168ae1c commit 8b8c992
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions plugins/tracker-resources/src/components/myissues/MyIssues.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,52 @@
['subscribed', tracker.string.Subscribed]
]
const currentUser = getCurrentAccount() as EmployeeAccount
const queries: { [n: string]: DocumentQuery<Issue> | undefined } = { assigned: { assignee: currentUser.employee } }
const assigned = { assignee: currentUser.employee }
const created = { _id: { $in: [] as Ref<Issue>[] } }
const subscribed = { _id: { $in: [] as Ref<Issue>[] } }
const createdQuery = createQuery()
$: createdQuery.query<TxCollectionCUD<Issue, Issue>>(
core.class.TxCollectionCUD,
{ modifiedBy: currentUser._id, objectClass: tracker.class.Issue, collection: 'subIssues' },
{
modifiedBy: currentUser._id,
objectClass: tracker.class.Issue,
collection: 'subIssues',
'tx._class': core.class.TxCreateDoc
},
(result) => {
queries.created = { _id: { $in: result.map(({ tx: { objectId } }) => objectId) } }
}
created._id.$in = result.map(({ tx: { objectId } }) => objectId)
},
{ sort: { _id: 1 } }
)
const subscribedQuery = createQuery()
$: subscribedQuery.query(
notification.class.LastView,
{ user: getCurrentAccount()._id, attachedToClass: tracker.class.Issue, lastView: { $gte: 0 } },
(result) => {
queries.subscribed = { _id: { $in: result.map(({ attachedTo }) => attachedTo as Ref<Issue>) } }
}
const newSub = result.map(({ attachedTo }) => attachedTo as Ref<Issue>)
const curSub = subscribed._id.$in
if (curSub.length !== newSub.length || curSub.some((id, i) => newSub[i] !== id)) {
subscribed._id.$in = newSub
}
},
{ sort: { _id: 1 } }
)
let [[mode]] = config
function handleChangeMode (newMode: string) {
if (newMode === mode) return
mode = newMode
}
function getQuery (mode: string, queries: { [key: string]: DocumentQuery<Issue> }) {
return queries[mode]
}
$: query = getQuery(mode, { assigned, created, subscribed })
</script>

<IssuesView query={queries[mode]} title={tracker.string.MyIssues}>
<IssuesView {query} title={tracker.string.MyIssues}>
<svelte:fragment slot="afterHeader">
<ModeSelector {config} {mode} onChange={handleChangeMode} />
</svelte:fragment>
Expand Down

0 comments on commit 8b8c992

Please sign in to comment.