()
| 14 | import SEO from "../components/common/SEO"; |
| 15 | |
| 16 | const SavedGraphTemplate: FC = () => { |
| 17 | const { user } = useAuthState(); |
| 18 | const { uid } = useParams<{ uid: string }>(); |
| 19 | const [graph, setGraph] = useState<PersonalGraph | null>(null); |
| 20 | |
| 21 | useEffect(() => { |
| 22 | if (!user) { |
| 23 | console.error("No user found for fetching graph {}", uid); |
| 24 | return; |
| 25 | } |
| 26 | if (!uid) { |
| 27 | console.error("No uid found for fetching graph"); |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | getPersonalGraph(user.uid, uid).then((graph) => { |
| 32 | setGraph(graph); |
| 33 | }); |
| 34 | }, [uid, user]); |
| 35 | |
| 36 | const saveGraph = useCallback( |
| 37 | (graphInfo: PersonalGraphInfo) => { |
| 38 | if (!graph) { |
| 39 | console.error("No graph found for saving"); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | const newGraph = graph; |
| 44 | newGraph.data = graphInfo; |
| 45 | |
| 46 | updatePersonalGraph(user!.uid, newGraph); |
| 47 | }, |
| 48 | [graph, user] |
| 49 | ); |
| 50 | |
| 51 | // If no graph has been loaded, don't return anything yet. TODO - Add loading screen |
| 52 | if (!graph) return null; |
| 53 | |
| 54 | return ( |
| 55 | <> |
| 56 | <SEO title={graph.name} description="View and edit your saved graph" /> |
| 57 | <div className="h-full overflow-hidden"> |
| 58 | {/* Must leave the transition because somehow it messes the opacity of the modals */} |
| 59 | <Transition |
| 60 | show={graph !== null} |
| 61 | appear={true} |
| 62 | enter="transition-all duration-500 delay-500" |
| 63 | enterFrom="opacity-0 scale-150" |
| 64 | enterTo="opacity-100 scale-100" |
| 65 | className="h-full w-full" |
| 66 | > |
| 67 | <SavedGraphBanner /> |
| 68 | <Graph |
| 69 | initialAddresses={graph.data.addresses} |
| 70 | initialPaths={graph.data.edges} |
| 71 | onAutoSave={saveGraph} |
| 72 | key={graph.uid} |
| 73 | /> |
nothing calls this directly
no test coverage detected