Fix: board remembers the selected team across refresh
The board's selected team was local state that defaulted to the first team on every load, so a refresh snapped away from the team you were on (and its tasks appeared to vanish). Now the selection is restored from localStorage, validated against the current teams, and persisted on change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -73,7 +73,8 @@ export function BoardPage() {
|
|||||||
|
|
||||||
const [orgName, setOrgName] = useState('')
|
const [orgName, setOrgName] = useState('')
|
||||||
const [teams, setTeams] = useState<Team[]>([])
|
const [teams, setTeams] = useState<Team[]>([])
|
||||||
const [teamId, setTeamId] = useState<string | null>(null)
|
// Remember the selected team across refreshes (it used to snap back to the first team).
|
||||||
|
const [teamId, setTeamId] = useState<string | null>(() => localStorage.getItem('teamup.board.team'))
|
||||||
const [board, setBoard] = useState<Board | null>(null)
|
const [board, setBoard] = useState<Board | null>(null)
|
||||||
const [newTeam, setNewTeam] = useState('')
|
const [newTeam, setNewTeam] = useState('')
|
||||||
const [newTask, setNewTask] = useState('')
|
const [newTask, setNewTask] = useState('')
|
||||||
@@ -90,7 +91,10 @@ export function BoardPage() {
|
|||||||
try {
|
try {
|
||||||
const result = await api.get<Team[]>(`/api/orgboard/teams?organizationId=${organizationId}`)
|
const result = await api.get<Team[]>(`/api/orgboard/teams?organizationId=${organizationId}`)
|
||||||
setTeams(result)
|
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) {
|
} catch (err) {
|
||||||
toast.error((err as Error).message)
|
toast.error((err as Error).message)
|
||||||
}
|
}
|
||||||
@@ -112,6 +116,11 @@ export function BoardPage() {
|
|||||||
if (teamId) void loadBoard(teamId)
|
if (teamId) void loadBoard(teamId)
|
||||||
}, [teamId, loadBoard])
|
}, [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<unknown>) {
|
async function run(action: () => Promise<unknown>) {
|
||||||
try {
|
try {
|
||||||
await action()
|
await action()
|
||||||
|
|||||||
Reference in New Issue
Block a user