import * as electronRemote from '@electron/remote'; const electronConsole = electronRemote.getGlobal('console') as Console; import Logger from '../../../../logger/logger'; const LOG = Logger.create(__filename, electronConsole); import React, { FC, useEffect, useState } from 'react'; export interface TableProps { header: JSX.Element; fetchData: () => Promise; mapToRow: (data: T) => JSX.Element; } export default function Table(props: TableProps) { const { header, fetchData, mapToRow } = props; // TODO: Loading indicator + fetch failed indicator const [ dataRows, setDataRows ] = useState([]); const [ loading, setLoading ] = useState(true); const [ fetchFailed, setFetchFailed ] = useState(false); useEffect(() => { (async () => { setLoading(true); try { const data = await fetchData(); setDataRows(data.map(mapToRow)); } catch (e: unknown) { LOG.error('error fetching data for table', e); setFetchFailed(true); } setLoading(false); })(); }, []); return ( {header}{dataRows}
) }