more stable but unfinished sharing refactor
This commit is contained in:
@@ -3,7 +3,7 @@ import { LayoutDashboard, ListTodo, Settings, Clock, ArrowUpCircle, PanelLeftClo
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
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 { pb } from "@/lib/pocketbase";
|
||||||
import { createSignal, createEffect } from "solid-js";
|
import { createSignal, createEffect } from "solid-js";
|
||||||
|
|
||||||
@@ -170,6 +170,7 @@ export const ContextSwitcher: Component<{
|
|||||||
setCurrentTaskContext({ bucketId: id, name });
|
setCurrentTaskContext({ bucketId: id, name });
|
||||||
} else {
|
} else {
|
||||||
setCurrentTaskContext({ userId: id, name });
|
setCurrentTaskContext({ userId: id, name });
|
||||||
|
void loadTasksForOwner(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close popover
|
// Close popover
|
||||||
|
|||||||
+42
-10
@@ -554,6 +554,11 @@ const getPersonalContext = (userId = pb.authStore.model?.id) =>
|
|||||||
) || null
|
) || null
|
||||||
: 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) => {
|
export const matchesFilter = (task: Task) => {
|
||||||
const currentUserId = pb.authStore.model?.id;
|
const currentUserId = pb.authStore.model?.id;
|
||||||
const ctx = currentTaskContext();
|
const ctx = currentTaskContext();
|
||||||
@@ -1532,9 +1537,8 @@ export const initStore = async () => {
|
|||||||
|
|
||||||
// STAGE 2 & 3: Background Sync
|
// STAGE 2 & 3: Background Sync
|
||||||
const backgroundSync = async () => {
|
const backgroundSync = async () => {
|
||||||
const subscribedBucketKeys = store.subscribedBuckets
|
const subscribedBucketTags = getSubscribedBucketContexts()
|
||||||
.map(id => store.contexts.find(context => context.id === id)?.key)
|
.map(context => buildShareTag(context.displayName));
|
||||||
.filter(Boolean);
|
|
||||||
const supervisedUserIds = store.supervisedContexts.map(context => context.ownerUserId);
|
const supervisedUserIds = store.supervisedContexts.map(context => context.ownerUserId);
|
||||||
const collaborativeKeys = store.contexts
|
const collaborativeKeys = store.contexts
|
||||||
.filter(context =>
|
.filter(context =>
|
||||||
@@ -1553,8 +1557,8 @@ export const initStore = async () => {
|
|||||||
fields: LIST_FIELDS,
|
fields: LIST_FIELDS,
|
||||||
requestKey: null
|
requestKey: null
|
||||||
}),
|
}),
|
||||||
(subscribedBucketKeys.length > 0) ? pb.collection(TASGRID_COLLECTION).getFullList({
|
(subscribedBucketTags.length > 0) ? pb.collection(TASGRID_COLLECTION).getFullList({
|
||||||
filter: `(${subscribedBucketKeys.map(key => `tags ~ "@${key}"`).join(' || ')}) && completed = false`,
|
filter: `(${subscribedBucketTags.map(tag => `tags ~ "${tag}"`).join(' || ')}) && completed = false`,
|
||||||
sort: '-created',
|
sort: '-created',
|
||||||
fields: LIST_FIELDS,
|
fields: LIST_FIELDS,
|
||||||
requestKey: null
|
requestKey: null
|
||||||
@@ -2379,9 +2383,8 @@ export const loadAllHistory = async () => {
|
|||||||
toast.promise(
|
toast.promise(
|
||||||
(async () => {
|
(async () => {
|
||||||
// Fetch ALL tasks for user (including completed)
|
// Fetch ALL tasks for user (including completed)
|
||||||
const bucketKeys = store.subscribedBuckets
|
const bucketTags = getSubscribedBucketContexts()
|
||||||
.map(id => store.contexts.find(context => context.id === id)?.key)
|
.map(context => buildShareTag(context.displayName));
|
||||||
.filter(Boolean);
|
|
||||||
const supervisedUserIds = store.supervisedContexts.map(context => context.ownerUserId);
|
const supervisedUserIds = store.supervisedContexts.map(context => context.ownerUserId);
|
||||||
const collaborativeTags = store.contexts
|
const collaborativeTags = store.contexts
|
||||||
.filter(context =>
|
.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 })
|
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({
|
promises.push(pb.collection(TASGRID_COLLECTION).getFullList({
|
||||||
filter: bucketKeys.map(key => `tags ~ "@${key}"`).join(' || '),
|
filter: bucketTags.map(tag => `tags ~ "${tag}"`).join(' || '),
|
||||||
sort: '-created',
|
sort: '-created',
|
||||||
fields: LIST_FIELDS,
|
fields: LIST_FIELDS,
|
||||||
requestKey: null
|
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.");
|
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) => {
|
export const revokeShare = async (_taskId: string, _userId: string) => {
|
||||||
if (!pb.authStore.isValid) return;
|
if (!pb.authStore.isValid) return;
|
||||||
toast.info("Remove the matching @user tag from the task instead.");
|
toast.info("Remove the matching @user tag from the task instead.");
|
||||||
|
|||||||
Reference in New Issue
Block a user