collapse realtime subsciption
This commit is contained in:
+51
-28
@@ -357,6 +357,39 @@ const writeScopedPrefs = (rawPrefs: any, scopedPrefs: ScopedTaskgridPrefs) => ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const applyScopedPrefsToStore = (prefs: ScopedTaskgridPrefs) => {
|
||||||
|
const currentUserId = pb.authStore.model?.id;
|
||||||
|
const personalContext = currentUserId ? getPersonalContext(currentUserId) : null;
|
||||||
|
|
||||||
|
setStore({
|
||||||
|
pWeight: prefs.pWeight || 1.0,
|
||||||
|
uWeight: prefs.uWeight || 1.0,
|
||||||
|
matrixScaleDays: prefs.matrixScaleDays || 30,
|
||||||
|
prefId: currentUserId,
|
||||||
|
subscribedBuckets: prefs.subscribedBuckets || [],
|
||||||
|
personalContextSupervisorIds: personalContext?.supervisorUserIds || prefs.supervisorUserIds || [],
|
||||||
|
tagDefinitions: (prefs.tagDefinitions || []).filter((def: TagDefinition) => !def.name.startsWith("@")),
|
||||||
|
filterTemplates: prefs.filterTemplates || [],
|
||||||
|
quickloadTasks: prefs.quickloadTasks || [],
|
||||||
|
dismissedTaskUpdateIndicators: prefs.dismissedTaskUpdateIndicators || {},
|
||||||
|
collapsedUntilUpdatedTasks: prefs.collapsedUntilUpdatedTasks || {},
|
||||||
|
noteFilter: prefs.noteFilter || {
|
||||||
|
query: "",
|
||||||
|
tags: [],
|
||||||
|
priorityMin: 1,
|
||||||
|
priorityMax: 10,
|
||||||
|
urgencyMin: 1,
|
||||||
|
urgencyMax: 10,
|
||||||
|
editedToday: false,
|
||||||
|
ownedByMe: false,
|
||||||
|
starred: false,
|
||||||
|
jobStatus: [],
|
||||||
|
jobDivision: []
|
||||||
|
},
|
||||||
|
filter: prefs.filter || store.filter
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const unwrapRelationId = (value: unknown): string | null => {
|
const unwrapRelationId = (value: unknown): string | null => {
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
return value || null;
|
return value || null;
|
||||||
@@ -1763,6 +1796,8 @@ const shouldTaskBeVisible = (task: any, currentUserId: string): boolean => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const subscribeToRealtime = async () => {
|
export const subscribeToRealtime = async () => {
|
||||||
|
const currentUserId = pb.authStore.model?.id;
|
||||||
|
|
||||||
// Unsubscribe first to avoid duplicates
|
// Unsubscribe first to avoid duplicates
|
||||||
await pb.collection(TASGRID_COLLECTION).unsubscribe('*');
|
await pb.collection(TASGRID_COLLECTION).unsubscribe('*');
|
||||||
|
|
||||||
@@ -1919,6 +1954,19 @@ export const subscribeToRealtime = async () => {
|
|||||||
}
|
}
|
||||||
void syncSupervisedContexts();
|
void syncSupervisedContexts();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (currentUserId) {
|
||||||
|
await pb.collection('users').unsubscribe(currentUserId);
|
||||||
|
pb.collection('users').subscribe(currentUserId, (e) => {
|
||||||
|
if (e.action !== 'update') return;
|
||||||
|
|
||||||
|
const prefs = readScopedPrefs(e.record?.Taskgrid_pref || {});
|
||||||
|
applyScopedPrefsToStore({
|
||||||
|
...prefs,
|
||||||
|
subscribedBuckets: prefs.subscribedBuckets || e.record?.subscribedBuckets || []
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const runLegacyTagMigration = async (force = false) => {
|
const runLegacyTagMigration = async (force = false) => {
|
||||||
@@ -2280,34 +2328,9 @@ export const initStore = async () => {
|
|||||||
if (userId) {
|
if (userId) {
|
||||||
const user = await pb.collection('users').getOne(userId, { requestKey: null });
|
const user = await pb.collection('users').getOne(userId, { requestKey: null });
|
||||||
const prefs = readScopedPrefs(user.Taskgrid_pref || {});
|
const prefs = readScopedPrefs(user.Taskgrid_pref || {});
|
||||||
const personalContext = getPersonalContext(userId);
|
applyScopedPrefsToStore({
|
||||||
|
...prefs,
|
||||||
setStore({
|
subscribedBuckets: prefs.subscribedBuckets || user.subscribedBuckets || []
|
||||||
pWeight: prefs.pWeight || 1.0,
|
|
||||||
uWeight: prefs.uWeight || 1.0,
|
|
||||||
matrixScaleDays: prefs.matrixScaleDays || 30,
|
|
||||||
prefId: userId,
|
|
||||||
subscribedBuckets: prefs.subscribedBuckets || user.subscribedBuckets || [],
|
|
||||||
personalContextSupervisorIds: personalContext?.supervisorUserIds || prefs.supervisorUserIds || [],
|
|
||||||
tagDefinitions: (prefs.tagDefinitions || []).filter((def: TagDefinition) => !def.name.startsWith("@")),
|
|
||||||
filterTemplates: prefs.filterTemplates || [],
|
|
||||||
quickloadTasks: prefs.quickloadTasks || [],
|
|
||||||
dismissedTaskUpdateIndicators: prefs.dismissedTaskUpdateIndicators || {},
|
|
||||||
collapsedUntilUpdatedTasks: prefs.collapsedUntilUpdatedTasks || {},
|
|
||||||
noteFilter: prefs.noteFilter || {
|
|
||||||
query: "",
|
|
||||||
tags: [],
|
|
||||||
priorityMin: 1,
|
|
||||||
priorityMax: 10,
|
|
||||||
urgencyMin: 1,
|
|
||||||
urgencyMax: 10,
|
|
||||||
editedToday: false,
|
|
||||||
ownedByMe: false,
|
|
||||||
starred: false,
|
|
||||||
jobStatus: [],
|
|
||||||
jobDivision: []
|
|
||||||
},
|
|
||||||
filter: prefs.filter || store.filter
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (prefErr) {
|
} catch (prefErr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user