Skip to content

Commit

Permalink
fix: resolve stale data display in ResultTable after CSV import
Browse files Browse the repository at this point in the history
- Add table key to force re-render on CSV import
- Simplify data update logic
- Fix issue where old results were incorrectly displayed
  • Loading branch information
ligsnf committed Dec 24, 2024
1 parent ffc35c4 commit 8c541e9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/routes/index.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const Route = createLazyFileRoute('/')({

function Index() {
const [data, setData] = useState<Result[]>(() => db.getData())
const [tableKey, setTableKey] = useState(0)
const [, setDeletedItems] = useState<Map<number, Result>>(() => new Map<number, Result>())
const [uploadDialogOpen, setUploadDialogOpen] = useState(false);

Expand Down Expand Up @@ -72,8 +73,9 @@ function Index() {
const result = csvProcessor(csvData);

if (result.success && result.results) {
const newData = setResults(result.results);
setData([...newData]); // Force a re-render by creating a new array
setResults(result.results); // Update the database
setData(result.results); // Update the state
setTableKey(prev => prev + 1); // Force table re-render
setUploadDialogOpen(false);

if (result.warnings) {
Expand Down Expand Up @@ -156,7 +158,8 @@ function Index() {
</Card>
</div>
<div className="container mx-auto py-4">
<ResultTable
<ResultTable
key={tableKey}
data={data}
onResultUpdate={(id, result) => setData(updateResult(id, result))}
onResultDelete={handleResultDelete}
Expand Down

0 comments on commit 8c541e9

Please sign in to comment.