Fixes bug with updating relationships when an item is added

This commit is contained in:
2025-07-15 10:09:53 -07:00
parent 258518d954
commit 8f96062058
5 changed files with 7 additions and 28 deletions

View File

@@ -35,10 +35,6 @@ export function RelationshipList({
return <Loader />;
}
const doc = docResult.value.doc;
console.info("Rendering relationship list: ", relationshipType);
const relationshipResult = docResult.value.relationships[relationshipType];
const relationship =
@@ -60,7 +56,6 @@ export function RelationshipList({
try {
// Check for existing relationship
if (relationship) {
console.debug("Adding to existing relationship", relationship.id);
const updatedRelationship: Relationship = await pb
.collection("relationships")
.update(relationship.id, {
@@ -68,11 +63,10 @@ export function RelationshipList({
});
dispatch({
type: "setRelationship",
docId: doc.id,
docId: root.id,
relationship: updatedRelationship,
});
} else {
console.debug("Creating new relationship");
const updatedRelationship: Relationship = await pb
.collection("relationships")
.create({
@@ -82,7 +76,7 @@ export function RelationshipList({
});
dispatch({
type: "setRelationship",
docId: doc.id,
docId: root.id,
relationship: updatedRelationship,
});
}
@@ -99,7 +93,6 @@ export function RelationshipList({
try {
if (relationship) {
console.debug("Removing from existing relationship", relationship.id);
const updatedRelationship: Relationship = await pb
.collection("relationships")
.update(relationship.id, {
@@ -107,7 +100,7 @@ export function RelationshipList({
});
dispatch({
type: "setRelationship",
docId: doc.id,
docId: root.id,
relationship: updatedRelationship,
});
}

View File

@@ -11,8 +11,6 @@ import { Route as RelationshipRoute } from "@/routes/_app/_authenticated/documen
export function DocumentView({ documentId }: { documentId: DocumentId }) {
const { docResult } = useDocument(documentId);
console.info(`Rendering document: `, docResult);
if (docResult?.type !== "ready") {
return <Loader />;
}
@@ -50,16 +48,14 @@ export function DocumentView({ documentId }: { documentId: DocumentId }) {
<ul className="flex flex-row gap-1">
{relationshipList.map((relationshipType) => (
<Link
key={relationshipType}
to={RelationshipRoute.to}
params={{
documentId,
relationshipType,
}}
>
<div
key={relationshipType}
className="px-3 py-2 rounded bg-slate-800 text-slate-100 border border-slate-700 focus:outline-none focus:ring-2 focus:ring-violet-500 data-selected:bg-violet-900 data-selected:border-violet-700 whitespace-nowrap"
>
<div className="px-3 py-2 rounded bg-slate-800 text-slate-100 border border-slate-700 focus:outline-none focus:ring-2 focus:ring-violet-500 data-selected:bg-violet-900 data-selected:border-violet-700 whitespace-nowrap">
{displayName(relationshipType)} (
{relationshipCounts[relationshipType] ?? 0})
</div>

View File

@@ -13,8 +13,6 @@ export function RelatedDocumentList({ documentId, relationshipType }: Props) {
const { cache } = useDocumentCache();
console.log(documentId, docResult, cache);
if (docResult?.type !== "ready") {
return <Loader />;
}

View File

@@ -19,6 +19,8 @@ export const DocumentContext = createContext<DocumentContextValue | undefined>(
export function DocumentProvider({ children }: { children: ReactNode }) {
const [state, dispatch] = useReducer(reducer, initialState());
console.log("State: ", state);
return (
<DocumentContext.Provider
value={{

View File

@@ -46,11 +46,6 @@ function RouteComponent() {
sort: "-created",
});
console.log("Previous session: ", {
id: prevSession.id,
created: prevSession.created,
});
const newSession = await pb.collection("documents").create({
campaign: campaign.id,
type: "session",
@@ -67,12 +62,7 @@ function RouteComponent() {
filter: `primary = "${prevSession.id}"`,
});
console.log(`Found ${prevRelations.length} previous relations`);
for (const relation of prevRelations) {
console.log(
`Adding ${relation.secondary.length} items to ${relation.type}`,
);
await pb.collection("relationships").create({
primary: newSession.id,
type: relation.type,