From 530b0297176bd7c69844327a48db493dc09b7326 Mon Sep 17 00:00:00 2001 From: Joe Still Date: Sun, 25 May 2025 14:52:14 -0500 Subject: [PATCH] Add updated timestamp and sort by update --- src/components/Board.jsx | 27 ++++++++++--------- .../20250524131418_card_update_timestamp.sql | 14 ++++++++++ 2 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 supabase/migrations/20250524131418_card_update_timestamp.sql diff --git a/src/components/Board.jsx b/src/components/Board.jsx index 97547f4..b87cc6b 100644 --- a/src/components/Board.jsx +++ b/src/components/Board.jsx @@ -131,7 +131,7 @@ export default function Board(props) { const columns = ['Topics', 'Discussing', 'Done'] // type: lean const [voteSort, setVoteSort] = useState( - () => localStorage.getItem('voteSort') || 'created' + () => localStorage.getItem('voteSort') || 'updated' ) useEffect(() => { @@ -327,7 +327,8 @@ export default function Board(props) { const cardColumnSet = async (card_id, col) => { - const { error } = await supabase.from('cards').update({col}).eq('id', card_id) + const update = { col, updated: new Date().toISOString() } + const { error } = await supabase.from('cards').update(update).eq('id', card_id) } const [editing, setEditing] = useState([]) @@ -348,7 +349,7 @@ export default function Board(props) { event.preventDefault() const card_id = event.target.id.value const content = event.target.content.value - const update = { content } + const update = { content, updated: new Date().toISOString() } const { error } = await supabase .from('cards').update(update).eq('id', card_id) cardEditToggle(card_id) @@ -437,8 +438,8 @@ export default function Board(props) { const voteTotals = calculateVotes() const cardSortFn = (a, b) => { - if(voteSort === "created") { - return new Date(a.created).getTime() - new Date(b.created).getTime() + if(voteSort === "updated") { + return new Date(a.updated).getTime() - new Date(b.updated).getTime() } // else sort by vote calculation @@ -450,7 +451,7 @@ export default function Board(props) { const withinFilter = (card) => { if(timeFilter === 'all') return true - const created = new Date(card.created) + const updatedDate = new Date(card.updated) const now = new Date() const startOfWeek = new Date(now) startOfWeek.setHours(0, 0, 0, 0) @@ -459,10 +460,10 @@ export default function Board(props) { startOfLastWeek.setDate(startOfLastWeek.getDate() - 7) if(timeFilter === 'this') { - return created >= startOfWeek + return updatedDate >= startOfWeek } if(timeFilter === 'last') { - return created >= startOfLastWeek && created < startOfWeek + return updatedDate >= startOfLastWeek && updatedDate < startOfWeek } return true } @@ -630,7 +631,7 @@ export default function Board(props) {
-
@@ -733,7 +734,7 @@ export default function Board(props) {
- {new Date(card.created).toLocaleDateString()} {/*{new Date(card.created).toLocaleTimeString()}*/} + {new Date(card.updated).toLocaleDateString()} {/*{new Date(card.updated).toLocaleTimeString()}*/}
@@ -761,12 +762,12 @@ export default function Board(props) {
-