more stable but unfinished sharing refactor
This commit is contained in:
+42
-10
@@ -554,6 +554,11 @@ const getPersonalContext = (userId = pb.authStore.model?.id) =>
|
||||
) || null
|
||||
: null;
|
||||
|
||||
const getSubscribedBucketContexts = () =>
|
||||
store.subscribedBuckets
|
||||
.map(id => store.contexts.find(context => context.id === id))
|
||||
.filter((context): context is ShareContext => !!context && !context.deletedAt && context.kind === "bucket");
|
||||
|
||||
export const matchesFilter = (task: Task) => {
|
||||
const currentUserId = pb.authStore.model?.id;
|
||||
const ctx = currentTaskContext();
|
||||
@@ -1532,9 +1537,8 @@ export const initStore = async () => {
|
||||
|
||||
// STAGE 2 & 3: Background Sync
|
||||
const backgroundSync = async () => {
|
||||
const subscribedBucketKeys = store.subscribedBuckets
|
||||
.map(id => store.contexts.find(context => context.id === id)?.key)
|
||||
.filter(Boolean);
|
||||
const subscribedBucketTags = getSubscribedBucketContexts()
|
||||
.map(context => buildShareTag(context.displayName));
|
||||
const supervisedUserIds = store.supervisedContexts.map(context => context.ownerUserId);
|
||||
const collaborativeKeys = store.contexts
|
||||
.filter(context =>
|
||||
@@ -1553,8 +1557,8 @@ export const initStore = async () => {
|
||||
fields: LIST_FIELDS,
|
||||
requestKey: null
|
||||
}),
|
||||
(subscribedBucketKeys.length > 0) ? pb.collection(TASGRID_COLLECTION).getFullList({
|
||||
filter: `(${subscribedBucketKeys.map(key => `tags ~ "@${key}"`).join(' || ')}) && completed = false`,
|
||||
(subscribedBucketTags.length > 0) ? pb.collection(TASGRID_COLLECTION).getFullList({
|
||||
filter: `(${subscribedBucketTags.map(tag => `tags ~ "${tag}"`).join(' || ')}) && completed = false`,
|
||||
sort: '-created',
|
||||
fields: LIST_FIELDS,
|
||||
requestKey: null
|
||||
@@ -2379,9 +2383,8 @@ export const loadAllHistory = async () => {
|
||||
toast.promise(
|
||||
(async () => {
|
||||
// Fetch ALL tasks for user (including completed)
|
||||
const bucketKeys = store.subscribedBuckets
|
||||
.map(id => store.contexts.find(context => context.id === id)?.key)
|
||||
.filter(Boolean);
|
||||
const bucketTags = getSubscribedBucketContexts()
|
||||
.map(context => buildShareTag(context.displayName));
|
||||
const supervisedUserIds = store.supervisedContexts.map(context => context.ownerUserId);
|
||||
const collaborativeTags = store.contexts
|
||||
.filter(context =>
|
||||
@@ -2396,9 +2399,9 @@ export const loadAllHistory = async () => {
|
||||
pb.collection(TASGRID_COLLECTION).getFullList({ filter: relationFilter("user", userId), sort: '-created', fields: LIST_FIELDS, requestKey: null })
|
||||
];
|
||||
|
||||
if (bucketKeys.length > 0) {
|
||||
if (bucketTags.length > 0) {
|
||||
promises.push(pb.collection(TASGRID_COLLECTION).getFullList({
|
||||
filter: bucketKeys.map(key => `tags ~ "@${key}"`).join(' || '),
|
||||
filter: bucketTags.map(tag => `tags ~ "${tag}"`).join(' || '),
|
||||
sort: '-created',
|
||||
fields: LIST_FIELDS,
|
||||
requestKey: null
|
||||
@@ -2602,6 +2605,35 @@ export const shareTask = async (_taskId: string, _userId: string, _access: 'view
|
||||
toast.info("Direct task sharing has been replaced by @user tags.");
|
||||
};
|
||||
|
||||
export const loadTasksForOwner = async (userId: string) => {
|
||||
if (!pb.authStore.isValid || !userId) return;
|
||||
|
||||
try {
|
||||
const records = await pb.collection(TASGRID_COLLECTION).getFullList({
|
||||
filter: relationFilter("user", userId),
|
||||
sort: '-created',
|
||||
fields: LIST_FIELDS,
|
||||
requestKey: `owner-context-${userId}`
|
||||
});
|
||||
|
||||
setStore("tasks", (currentTasks) => {
|
||||
const taskMap = new Map(currentTasks.map(task => [task.id, task]));
|
||||
records.forEach((record: any) => {
|
||||
if (record.tags?.includes("__template__")) return;
|
||||
const mapped = mapRecordToTask(record);
|
||||
const existing = taskMap.get(mapped.id);
|
||||
if (existing && existing.content) {
|
||||
mapped.content = existing.content;
|
||||
}
|
||||
taskMap.set(mapped.id, mapped);
|
||||
});
|
||||
return Array.from(taskMap.values());
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Failed to load owner context tasks:", err);
|
||||
}
|
||||
};
|
||||
|
||||
export const revokeShare = async (_taskId: string, _userId: string) => {
|
||||
if (!pb.authStore.isValid) return;
|
||||
toast.info("Remove the matching @user tag from the task instead.");
|
||||
|
||||
Reference in New Issue
Block a user