Skip to content

Commit

Permalink
fix: correct empty state and initial state of session picker
Browse files Browse the repository at this point in the history
  • Loading branch information
thraizz committed May 21, 2024
1 parent 544def3 commit afe6cd4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/components/SessionPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { SessionContext } from "../provider/SessionContext";
import { Sessions } from "../types/Sessions";

export const SessionPicker = () => {
const [selected, setSelected] = useState<string[]>([]);
const { sessions, setSessions, fetchSnapshot, initialized } =
useContext(SessionContext);
const [selected, setSelected] = useState<string[]>(() =>
sessions
? Object.keys(sessions).filter((key) => sessions[key].selected)
: [],
);

useEffect(() => {
const _ = async () => await fetchSnapshot();
if (!initialized)
_().then((fetchedSessions) => {
fetchSnapshot().then((fetchedSessions) => {
if (fetchedSessions) {
setSessions(fetchedSessions);
setSelected(Object.keys(fetchedSessions));
Expand Down Expand Up @@ -64,7 +68,9 @@ export const SessionPicker = () => {
>
<span className="block truncate">
{selected.length < 2
? selected
? selected.length
? selected
: "None"
: `${selected.filter((v) => v !== "All").length} sessions`}
</span>
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
Expand Down

0 comments on commit afe6cd4

Please sign in to comment.