-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
598 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Producer, asyncAction, producerToAction } from "@ouestware/atoms"; | ||
import Graph from "graphology"; | ||
import { SerializedGraph } from "graphology-types"; | ||
|
||
import { appearanceAtom } from "../appearance"; | ||
import { AppearanceState } from "../appearance/types"; | ||
import { resetStates } from "../context/dataContexts"; | ||
import { fileAtom } from "../file"; | ||
import { graphDatasetActions } from "../graph"; | ||
import { initializeGraphDataset } from "../graph/utils"; | ||
import { resetCamera } from "../sigma"; | ||
|
||
/** | ||
* Actions: | ||
* ******** | ||
*/ | ||
// TODO: this code has a lot in commons with core/file/index.ts/open | ||
// we should mutialize it | ||
const importGraph = asyncAction(async (data: SerializedGraph, title?: string) => { | ||
if (fileAtom.get().status.type === "loading") throw new Error("A file is already being loaded"); | ||
fileAtom.set((prev) => ({ ...prev, status: { type: "loading" } })); | ||
try { | ||
const graph = Graph.from(data); | ||
if (title) graph.setAttribute("title", title); | ||
|
||
const { setGraphDataset } = graphDatasetActions; | ||
resetStates(false); | ||
setGraphDataset({ ...initializeGraphDataset(graph) }); | ||
resetCamera({ forceRefresh: true }); | ||
} catch (e) { | ||
fileAtom.set((prev) => ({ ...prev, status: { type: "error", message: (e as Error).message } })); | ||
throw e; | ||
} finally { | ||
fileAtom.set((prev) => ({ ...prev, status: { type: "idle" } })); | ||
} | ||
}); | ||
|
||
const updateAppearance: Producer<AppearanceState, [Partial<AppearanceState>]> = (newState) => { | ||
return (state) => ({ ...state, ...newState }); | ||
}; | ||
|
||
export const broadcastActions = { | ||
importGraph, | ||
updateAppearance: producerToAction(updateAppearance, appearanceAtom), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.