import * as shape from 'd3-shape'; import React, {useContext, useEffect, useState} from 'react'; import {View} from 'react-native'; import {Button, Dialog, Portal} from 'react-native-paper'; import {Grid, LineChart, YAxis} from 'react-native-svg-charts'; import {DatabaseContext} from './App'; import Best from './best'; export default function ViewBest({ best, setBest, }: { best?: Best; setBest: (best?: Best) => void; }) { const [data, setData] = useState([]); const [unit, setUnit] = useState(); const db = useContext(DatabaseContext); useEffect(() => { const selectBest = ` SELECT max(weight) AS weight, STRFTIME('%Y-%m-%d', created) as created, unit FROM sets WHERE name = ? GROUP BY name, STRFTIME('%Y-%m-%d', created) `; const refresh = async () => { const [result] = await db.executeSql(selectBest, [best?.name]); if (result.rows.length === 0) return; console.log(`${ViewBest.name}.${refresh.name}:`, result.rows.raw()); setData(result.rows.raw().map(row => row.weight)); setUnit(result.rows.item(0).unit); }; refresh(); }, [best, db]); const contentInset = {top: 20, bottom: 20}; return ( setBest(undefined)}> {best?.name} `${value}${unit}`} /> ); }