Commit 1f10e819 authored by Michael Vrana's avatar Michael Vrana

Import over url

parent b1cf6e07
Pipeline #85738 failed with stages
in 5 minutes and 1 second
This diff is collapsed.
import React, { useLayoutEffect, memo } from 'react'
import { useDispatch } from 'react-redux'
import { algorithmGraphFromJSON } from '../../interfaces/AlgorithmGraph'
import { algorithmDataActions } from '../../reducers/algorithmData'
import { useSnackbar } from 'notistack'
const { importGraph } = algorithmDataActions
export const QueryImporter = memo(() => {
const dispatch = useDispatch()
const { enqueueSnackbar } = useSnackbar()
useLayoutEffect(() => {
const urlParams = new URLSearchParams(window.location.search)
const importUrl = urlParams.get('importUrl')
if (!importUrl) return
fetch(importUrl)
.then((res) => res.text())
.then((json) => algorithmGraphFromJSON(json))
.then((algorithmGraph) => dispatch(importGraph(algorithmGraph)))
.catch((err) => {
console.error(err)
enqueueSnackbar('Error while importing project', {
variant: 'error'
})
})
}, [])
return null
})
......@@ -17,6 +17,7 @@ import { ReduxState } from '../../reducers'
import { algorithmUIActions } from '../../reducers/algorithmUI'
import { WebUITheme } from '../../interfaces/Theme'
import { useAlgorithmKeybinds } from '../../hooks/useAlgorithmKeybinds'
import { QueryImporter } from './QueryImporter'
const { setAlgorithmToolbarOpen } = algorithmUIActions
......@@ -80,6 +81,7 @@ export const WebUI = () => {
</AppBar>
<AlgorithmToolbar />
<AlgorithmCanvas />
<QueryImporter />
</div>
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment