-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demo: add a test view for auto processing
- Loading branch information
1 parent
0e9ed8d
commit c88d396
Showing
4 changed files
with
117 additions
and
0 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,61 @@ | ||
import { fileCollectionFromWebSource } from 'filelist-utils'; | ||
import { read } from 'nmr-load-save'; | ||
import { useState, useEffect } from 'react'; | ||
|
||
import BaseView, { BaseViewProps } from './BaseView'; | ||
import { Loading } from './Loading'; | ||
|
||
export async function loadData(file) { | ||
const response = await fetch(file); | ||
checkStatus(response); | ||
const data = await response.json(); | ||
return data; | ||
} | ||
|
||
function checkStatus(response) { | ||
if (!response.ok) { | ||
throw new Error(`HTTP ${response.status} - ${response.statusText}`); | ||
} | ||
return response; | ||
} | ||
|
||
interface ExternalLoadViewProps extends Omit<BaseViewProps, 'data'> { | ||
file: string; | ||
baseURL: string; | ||
} | ||
|
||
async function loadSpectrumFromURL(url) { | ||
const { pathname: relativePath, origin: baseURL } = new URL(url); | ||
const source = { | ||
entries: [ | ||
{ | ||
relativePath, | ||
}, | ||
], | ||
baseURL, | ||
}; | ||
const fileCollection = await fileCollectionFromWebSource(source, {}); | ||
|
||
const { nmriumState } = await read(fileCollection, { | ||
experimentalFeatures: true, | ||
onLoadProcessing: { autoProcessing: true }, | ||
}); | ||
return nmriumState; | ||
} | ||
export default function ExternalLoadView(props: ExternalLoadViewProps) { | ||
const [data, setData] = useState(); | ||
|
||
const { file, baseURL, ...otherProps } = props; | ||
|
||
useEffect(() => { | ||
void loadSpectrumFromURL(file).then((d: any) => { | ||
setData(d); | ||
}); | ||
}, [baseURL, file]); | ||
|
||
if (!data) { | ||
return <Loading />; | ||
} | ||
|
||
return <BaseView {...otherProps} data={data} />; | ||
} |
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,50 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import { css } from '@emotion/react'; | ||
|
||
const style = css` | ||
height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: #f4f4f4; | ||
#title { | ||
padding: 20px 0; | ||
} | ||
#title strong:first-child { | ||
color: #c25a00; | ||
} | ||
#loader { | ||
border: 1px solid #f3f3f3; | ||
border-top: 3px solid #c25a00; | ||
border-radius: 50%; | ||
width: 50px; | ||
height: 50px; | ||
animation: spin 0.6s linear infinite; | ||
} | ||
@keyframes spin { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
`; | ||
|
||
export function Loading() { | ||
return ( | ||
<div css={style}> | ||
<span id="title"> | ||
<strong>NMR</strong> | ||
<strong>ium</strong> loading ... | ||
</span> | ||
<div id="loader" /> | ||
</div> | ||
); | ||
} |
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