Skip to content

Commit

Permalink
fix: adapt typings
Browse files Browse the repository at this point in the history
  • Loading branch information
thraizz committed Dec 14, 2023
1 parent 3fbdf98 commit 4adb065
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/AveragesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const AveragesTable = () => {
if (sessions) {
const { field } = columnDef;
const values = Object.values(sessions).map((session) => {
return session.results.map((result) => result[field]);
return session?.results.map(
(result: { [x: string]: string }) => result[field],
);
});
const average =
values.flat().reduce((a, b) => a + b, 0) / values.flat().length;
Expand Down
26 changes: 13 additions & 13 deletions src/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ export const DataTable = () => {
]);

// Get the session where selected is true
const jsonFileWithoutEmptyRows =
sessions &&
Object.values(sessions)
.filter((session) => session.selected)
?.reduce(
(acc, curr) => {
if (curr.results.length > 0) {
acc.push(...curr.results);
}
return acc;
},
[] as Array<Record<string, string>>,
);
const jsonFileWithoutEmptyRows = sessions
? (Object.values(sessions)
.filter((session) => session.selected)
?.reduce(
(acc, curr) => {
if (curr.results.length > 0) {
acc.push(...curr.results);
}
return acc;
},
[] as Array<Record<string, string>>,
) as Array<Record<string, string>>)
: [];

return (
<>
Expand Down
5 changes: 2 additions & 3 deletions src/SessionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, {
} from "react";

export type SessionType = Record<string, DocumentData> | null;

export interface SessionContextInterface {
sessions: SessionType;
setSession: (sessions: SessionType) => void;
Expand All @@ -18,9 +19,7 @@ const SessionContext = createContext<SessionContextInterface>({
});

const SessionProvider: React.FC<PropsWithChildren> = ({ children }) => {
const [sessions, setSession] = useState<Record<string, DocumentData> | null>(
null,
);
const [sessions, setSession] = useState<SessionType>(null);
const memoizedValue = useMemo(
() => ({
sessions,
Expand Down

0 comments on commit 4adb065

Please sign in to comment.