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

View File

@@ -11,8 +11,6 @@ import { Route as RelationshipRoute } from "@/routes/_app/_authenticated/documen
export function DocumentView({ documentId }: { documentId: DocumentId }) { export function DocumentView({ documentId }: { documentId: DocumentId }) {
const { docResult } = useDocument(documentId); const { docResult } = useDocument(documentId);
console.info(`Rendering document: `, docResult);
if (docResult?.type !== "ready") { if (docResult?.type !== "ready") {
return <Loader />; return <Loader />;
} }
@@ -50,16 +48,14 @@ export function DocumentView({ documentId }: { documentId: DocumentId }) {
<ul className="flex flex-row gap-1"> <ul className="flex flex-row gap-1">
{relationshipList.map((relationshipType) => ( {relationshipList.map((relationshipType) => (
<Link <Link
key={relationshipType}
to={RelationshipRoute.to} to={RelationshipRoute.to}
params={{ params={{
documentId, documentId,
relationshipType, relationshipType,
}} }}
> >
<div <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">
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"
>
{displayName(relationshipType)} ( {displayName(relationshipType)} (
{relationshipCounts[relationshipType] ?? 0}) {relationshipCounts[relationshipType] ?? 0})
</div> </div>

View File

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

View File

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

View File

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