Skip to content
Open
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
854 changes: 854 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.1",
"eslint": "^10.3.0",
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.2",
"globals": "^17.6.0",
"jsdom": "^28.1.0",
"vite": "^8.0.12",
"vite-plugin-pwa": "^1.3.0",
"vitest": "^4.1.7"
Expand Down
184 changes: 0 additions & 184 deletions src/App.css

This file was deleted.

70 changes: 21 additions & 49 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,29 @@
import { useEffect, useState } from 'react';
import { loadAll, put, remove } from './db';
import usePredictions from './hooks/usePredictions';
import PredictionForm from './components/PredictionForm';
import PredictionList from './components/PredictionList';
import ScoreSummary from './components/ScoreSummary';
import ReliabilityDiagram from './components/ReliabilityDiagram';
import DataIO from './components/DataIO';
import './App.css';

function App() {
const [predictions, setPredictions] = useState([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
loadAll().then((all) => {
setPredictions(all);
setLoading(false);
});
}, []);

async function addPrediction({ text, probability, category, resolveBy }) {
const prediction = {
id: crypto.randomUUID(),
text,
probability,
category,
createdAt: new Date().toISOString(),
resolveBy,
resolvedAt: null,
outcome: null,
notes: '',
};
await put(prediction);
setPredictions((prev) => [...prev, prediction]);
}

async function resolvePrediction(id, outcome) {
const target = predictions.find((p) => p.id === id);
if (!target) return;
const updated = { ...target, outcome, resolvedAt: new Date().toISOString() };
await put(updated);
setPredictions((prev) => prev.map((p) => (p.id === id ? updated : p)));
}

async function deletePrediction(id) {
await remove(id);
setPredictions((prev) => prev.filter((p) => p.id !== id));
}

async function importPredictions(incoming) {
for (const prediction of incoming) {
await put(prediction);
}
setPredictions(await loadAll());
const {
predictions,
loading,
error,
resolvedItems,
addPrediction,
resolvePrediction,
deletePrediction,
importPredictions,
} = usePredictions();

if (error) {
return (
<main>
<h1>brierly</h1>
<p role="alert">Could not load your predictions: {error}</p>
</main>
);
}

return (
Expand All @@ -62,8 +34,8 @@ function App() {
<p>Loading…</p>
) : (
<>
<ScoreSummary predictions={predictions} />
<ReliabilityDiagram predictions={predictions} />
<ScoreSummary resolvedItems={resolvedItems} openCount={predictions.length - resolvedItems.length} />
<ReliabilityDiagram resolvedItems={resolvedItems} />
<PredictionList
predictions={predictions}
onResolve={resolvePrediction}
Expand Down
Binary file removed src/assets/hero.png
Binary file not shown.
1 change: 0 additions & 1 deletion src/assets/react.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/assets/vite.svg

This file was deleted.

12 changes: 12 additions & 0 deletions src/components/DataIO.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ function DataIO({ predictions, onImport }) {
if (!Array.isArray(data)) {
throw new Error('expected a JSON array of predictions');
}
for (let i = 0; i < data.length; i++) {
const item = data[i];
if (typeof item.id !== 'string' || !item.id) {
throw new Error(`item ${i}: missing or invalid "id" (expected non-empty string)`);
}
if (typeof item.text !== 'string' || !item.text) {
throw new Error(`item ${i}: missing or invalid "text" (expected non-empty string)`);
}
if (typeof item.probability !== 'number' || item.probability < 0 || item.probability > 1) {
throw new Error(`item ${i}: missing or invalid "probability" (expected number between 0 and 1)`);
}
}
await onImport(data);
} catch (err) {
setError(`Import failed: ${err.message}`);
Expand Down
3 changes: 1 addition & 2 deletions src/components/PredictionForm.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useRef, useState } from 'react';

const CATEGORIES = ['work', 'markets', 'personal'];
import { CATEGORIES } from '../constants';

// Default resolve-by a week out, as YYYY-MM-DD (so the Phase 3 nudge has a
// real date to compare against, not a graveyard).
Expand Down
Loading