Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/demo/views/AuoProcessingView.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import type { NMRiumCore } from '@zakodium/nmrium-core';
import init from '@zakodium/nmrium-core-plugins';
import { FileCollection } from 'file-collection';
import { useEffect, useState } from 'react';

import { useCore } from '../../component/context/CoreContext.js';

import type { BaseViewProps } from './BaseView.js';
import BaseView from './BaseView.js';
import { Loading } from './Loading.js';

const core = init();

interface ExternalLoadViewProps extends Omit<BaseViewProps, 'data'> {
file: string;
baseURL: string;
}

async function loadSpectrumFromURL(core: NMRiumCore, url: string) {
async function loadSpectrumFromURL(url: string) {
const { pathname: relativePath, origin: baseURL } = new URL(url);
const source = {
entries: [
Expand All @@ -34,15 +34,14 @@ async function loadSpectrumFromURL(core: NMRiumCore, url: string) {

export default function ExternalLoadView(props: ExternalLoadViewProps) {
const [data, setData] = useState();
const core = useCore();

const { file, baseURL, ...otherProps } = props;

useEffect(() => {
void loadSpectrumFromURL(core, file).then((d: any) => {
void loadSpectrumFromURL(file).then((d: any) => {
setData(d);
});
}, [baseURL, core, file]);
}, [baseURL, file]);

if (!data) {
return <Loading />;
Expand Down
13 changes: 7 additions & 6 deletions src/demo/views/WebSourceView.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { CustomWorkspaces, NMRiumCore } from '@zakodium/nmrium-core';
import type { CustomWorkspaces } from '@zakodium/nmrium-core';
import init from '@zakodium/nmrium-core-plugins';
import { useCallback, useEffect, useState } from 'react';
import { ObjectInspector } from 'react-inspector';

import { useCore } from '../../component/context/CoreContext.js';
import type { NMRiumWorkspace } from '../../component/main/index.js';
import { NMRium } from '../../component/main/index.js';
import type { PageConfig } from '../layouts/Main.js';

async function loadFromURL(core: NMRiumCore, url: string) {
const core = init();

async function loadFromURL(url: string) {
const { pathname: relativePath, origin: baseURL } = new URL(url);
return core.readFromWebSource({ entries: [{ relativePath, baseURL }] });
}
Expand Down Expand Up @@ -36,12 +38,11 @@ export default function WebSourceView(props: WebSourceViewProps) {
const [callbackData, setCallbackData] = useState<any[]>([]);
const [isCallbackVisible, showCallback] = useState(false);

const core = useCore();
useEffect(() => {
void loadFromURL(core, file).then((d) => {
void loadFromURL(file).then((d) => {
setData(d as any);
});
}, [baseURL, core, file, props]);
}, [baseURL, file, props]);

const changeHandler = useCallback((logData) => {
setCallbackData((prevLogs) => {
Expand Down
Loading