|
| 1 | +import React, { useState, useMemo } from "react" |
| 2 | +import useEventCallback from "use-event-callback" |
| 3 | + |
| 4 | +import MainLayout from "../MainLayout" |
| 5 | + |
| 6 | +const emptyAr = [] |
| 7 | + |
| 8 | +// This is a cloudflare CORs proxy from the project maintainer @seveibar |
| 9 | +const defaultCorsProxy = |
| 10 | + "https://corsproxy.seve.workers.dev/corsproxy/?apiurl={URL}" |
| 11 | + |
| 12 | +const defaultEnabledTools = [ |
| 13 | + "create-durations", |
| 14 | + "create-timestamps", |
| 15 | + "label-durations", |
| 16 | + "label-timestamps", |
| 17 | +] |
| 18 | +const defaultGraphs = [{ keyName: "value" }] |
| 19 | + |
| 20 | +export const ReactTimeSeries = ({ |
| 21 | + corsProxy = defaultCorsProxy, |
| 22 | + interface: iface, |
| 23 | + sample, |
| 24 | + onModifySample, |
| 25 | +}) => { |
| 26 | + const { |
| 27 | + timeFormat, |
| 28 | + enabledTools = defaultEnabledTools, |
| 29 | + durationLabels = emptyAr, |
| 30 | + timestampLabels = emptyAr, |
| 31 | + graphs = defaultGraphs, |
| 32 | + allowCustomLabels, |
| 33 | + } = iface |
| 34 | + let { timeData: sampleTimeData, audioUrl, csvUrl, annotation } = sample |
| 35 | + |
| 36 | + const timeData = useMemo(() => { |
| 37 | + if (sampleTimeData) return sampleTimeData |
| 38 | + // TODO load audioUrl |
| 39 | + // TODO load csvUrl |
| 40 | + }, [sampleTimeData, audioUrl, csvUrl]) |
| 41 | + |
| 42 | + const curveGroups = useMemo(() => {}, [timeData, graphs]) |
| 43 | + |
| 44 | + const [timestamps, setTimestamps] = useState(() => { |
| 45 | + if (!annotation?.timestamps) return [] |
| 46 | + // TODO derive timestamps |
| 47 | + return [] |
| 48 | + }) |
| 49 | + const [durationGroups, setDurationGroups] = useState(() => { |
| 50 | + if (!annotation?.durations) return [] |
| 51 | + // TODO derive timestamps |
| 52 | + return [] |
| 53 | + }) |
| 54 | + |
| 55 | + const onChangeDurationGroups = useEventCallback(() => {}) |
| 56 | + const onChangeTimestamps = useEventCallback(() => {}) |
| 57 | + |
| 58 | + return ( |
| 59 | + <MainLayout |
| 60 | + curveGroups={curveGroups} |
| 61 | + timeFormat={timeFormat} |
| 62 | + durationGroups={durationGroups} |
| 63 | + onChangeDurationGroups={onChangeDurationGroups} |
| 64 | + timestamps={timestamps} |
| 65 | + onChangeTimestamps={onChangeTimestamps} |
| 66 | + /> |
| 67 | + ) |
| 68 | +} |
| 69 | + |
| 70 | +export default ReactTimeSeries |
0 commit comments