more stable but unfinished sharing refactor

This commit is contained in:
2026-03-19 16:20:37 -05:00
parent 37004e4b4a
commit 727cfe0083
2 changed files with 44 additions and 11 deletions
+2 -1
View File
@@ -3,7 +3,7 @@ import { LayoutDashboard, ListTodo, Settings, Clock, ArrowUpCircle, PanelLeftClo
import { cn } from "@/lib/utils";
import { Button } from "./ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { store, currentTaskContext, setCurrentTaskContext } from "@/store";
import { store, currentTaskContext, setCurrentTaskContext, loadTasksForOwner } from "@/store";
import { pb } from "@/lib/pocketbase";
import { createSignal, createEffect } from "solid-js";
@@ -170,6 +170,7 @@ export const ContextSwitcher: Component<{
setCurrentTaskContext({ bucketId: id, name });
} else {
setCurrentTaskContext({ userId: id, name });
void loadTasksForOwner(id);
}
// Close popover
+42 -10
View File
@@ -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.");