diff --git a/client/src/pages/BoardPage.tsx b/client/src/pages/BoardPage.tsx index 130a042..5080f34 100644 --- a/client/src/pages/BoardPage.tsx +++ b/client/src/pages/BoardPage.tsx @@ -73,7 +73,8 @@ export function BoardPage() { const [orgName, setOrgName] = useState('') const [teams, setTeams] = useState([]) - const [teamId, setTeamId] = useState(null) + // Remember the selected team across refreshes (it used to snap back to the first team). + const [teamId, setTeamId] = useState(() => localStorage.getItem('teamup.board.team')) const [board, setBoard] = useState(null) const [newTeam, setNewTeam] = useState('') const [newTask, setNewTask] = useState('') @@ -90,7 +91,10 @@ export function BoardPage() { try { const result = await api.get(`/api/orgboard/teams?organizationId=${organizationId}`) setTeams(result) - setTeamId((current) => current ?? result[0]?.id ?? null) + // Keep the current/remembered team if it still exists; otherwise fall back to the first. + setTeamId((current) => + current && result.some((team) => team.id === current) ? current : result[0]?.id ?? null, + ) } catch (err) { toast.error((err as Error).message) } @@ -112,6 +116,11 @@ export function BoardPage() { if (teamId) void loadBoard(teamId) }, [teamId, loadBoard]) + // Persist the selected team so a refresh stays on it. + useEffect(() => { + if (teamId) localStorage.setItem('teamup.board.team', teamId) + }, [teamId]) + async function run(action: () => Promise) { try { await action()