Skip to content

Commit

Permalink
Merge pull request #17 from gwu-libraries/fix-refetch-query
Browse files Browse the repository at this point in the history
Temp fix (page refresh) to reloading, need to set up subscriptions
  • Loading branch information
alepbloyd authored Aug 29, 2024
2 parents d08339d + 0282f91 commit 58ebc64
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 21 deletions.
24 changes: 18 additions & 6 deletions react/src/components/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ function SideBar() {
doi: doiSearch,
investigationId: investigationId,
},
onCompleted: (data) => {},
onCompleted: (data) => {
{
{
window.location.reload();
}
}
},
onError: (data) => {
console.log(data);
},
refetchQueries: [USE_INVESTIGATION_GRAPH],
// refetchQueries: [USE_INVESTIGATION_GRAPH],
});

let doiInputHandler = (e) => {
Expand All @@ -55,11 +61,17 @@ function SideBar() {
bodyText: noteBodyText,
investigationId: investigationId,
},
onCompleted: (data) => {},
onCompleted: (data) => {
{
{
window.location.reload();
}
}
},
onError: (data) => {
console.log(data);
},
refetchQueries: [USE_INVESTIGATION_GRAPH],
// refetchQueries: [USE_INVESTIGATION_GRAPH],
});

return (
Expand All @@ -82,12 +94,12 @@ function SideBar() {
></input>
<button onClick={() => addAuthor()}>Add Author</button> */}

<input
{/* <input
className="border-4 border-solid border-red-500"
value={noteBodyText}
onChange={noteTextInputHandler}
></input>
<button onClick={() => addNote()}>Add Sticky Note</button>
<button onClick={() => addNote()}>Add Sticky Note</button> */}
</>
);
}
Expand Down
9 changes: 4 additions & 5 deletions react/src/components/graph/InvestigationGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function InvestigationGraph({
[]
);


const initialNodes = [];
const initialEdges = [];

Expand Down Expand Up @@ -70,20 +69,21 @@ function InvestigationGraph({
for (let i = 0; i <= workEdges.length - 1; i++) {
if (workEdges[i].visible) {
initialEdges.push({
source: `work-${workEdges[i].citationNode.id}`,
target: `work-${workEdges[i].referenceNode.id}`,
target: `work-${workEdges[i].citationNode.id}`,
source: `work-${workEdges[i].referenceNode.id}`,
id: `workedge-${workEdges[i].id}`,
label: "citation/reference",
style: {
strokeWidth: 2,
stroke: "#FF0072",
},
markerStart: {
markerEnd: {
type: MarkerType.ArrowClosed,
width: 20,
height: 20,
color: "#FF0072",
},
animated: true,
});
}
}
Expand Down Expand Up @@ -114,7 +114,6 @@ function InvestigationGraph({
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
// onConnect={onConnect}
nodeTypes={nodeTypes}
nodesDraggable={true}
fitView
Expand Down
10 changes: 8 additions & 2 deletions react/src/components/graph/nodes/AuthorNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ function AuthorNode({ data }) {

const [addAuthorWorks] = useMutation(ADD_AUTHOR_WORKS, {
errorPolicy: "ignore",
onCompleted: (data) => {},
onCompleted: (data) => {
{
{
window.location.reload();
}
}
},
onError: (data) => {
console.log(data);
},
refetchQueries: [USE_INVESTIGATION_GRAPH],
// refetchQueries: [USE_INVESTIGATION_GRAPH],
});

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion react/src/components/graph/nodes/NoteNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function NoteNode({
investigationId: investigationId,
noteNodeId: id
},
refetchQueries: [USE_INVESTIGATION_GRAPH] // this doesn't seem to work for trigger refresh of graph, not sure why? It works in root node
// refetchQueries: [USE_INVESTIGATION_GRAPH] // this doesn't seem to work for trigger refresh of graph, not sure why? It works in root node
})

return (
Expand Down
14 changes: 11 additions & 3 deletions react/src/components/graph/nodes/WorkDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ function WorkDetails({
const { investigationId } = useParams();
const [addAuthor] = useMutation(CREATE_AUTHOR_NODE, {
errorPolicy: "ignore",
onCompleted: (data) => {},
onCompleted: (data) => {
{
{
window.location.reload();
}
}
},
onError: (data) => {
console.log(data);
},
refetchQueries: [USE_INVESTIGATION_GRAPH],
// refetchQueries: [USE_INVESTIGATION_GRAPH],
});

return (
Expand All @@ -50,7 +56,9 @@ function WorkDetails({
>
<tr className="border border-slate-700">
<td
colSpan={Math.max(authors.length, keywords.length, topics.length) + 1}
colSpan={
Math.max(authors.length, keywords.length, topics.length) + 1
}
>
{abstract}
</td>
Expand Down
22 changes: 18 additions & 4 deletions react/src/components/graph/nodes/WorkNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,29 @@ function WorkNode({ data }) {
openalexId: data.workData.work.openalexId,
investigationId: investigationId,
},
refetchQueries: [USE_INVESTIGATION_GRAPH],
onCompleted: (data) => {
{
{
window.location.reload();
}
}
},
// refetchQueries: [USE_INVESTIGATION_GRAPH],
});

const [addCitations] = useMutation(ADD_CITATIONS, {
variables: {
openalexId: data.workData.work.openalexId,
investigationId: investigationId,
},
refetchQueries: [USE_INVESTIGATION_GRAPH],
onCompleted: (data) => {
{
{
window.location.reload();
}
}
},
// refetchQueries: [USE_INVESTIGATION_GRAPH],
});

useEffect(() => {
Expand All @@ -84,8 +98,8 @@ function WorkNode({ data }) {
}}
ref={noderef}
>
<Handle type="source" position={Position.Top} id="top-handle" />
<Handle type="target" position={Position.Bottom} id="bottom-handle" />
<Handle type="target" position={Position.Top} id="top-handle" />
<Handle type="source" position={Position.Bottom} id="bottom-handle" />
<label htmlFor="text">{data.workData.work.title}</label>
<button onClick={() => addReferences()}>Show References</button>
<p></p>
Expand Down

0 comments on commit 58ebc64

Please sign in to comment.