From d441391cdc7d313b826c5b4e2163d9cdba13d829 Mon Sep 17 00:00:00 2001 From: Tal Yaron Date: Thu, 5 Sep 2024 10:19:42 +0300 Subject: [PATCH] linting and type check --- .../getMultiStageStatements.ts | 4 +- src/model/statements/statementsSlice.ts | 9 +- src/view/components/triangle/Triangle.tsx | 8 +- .../statement/components/SwitchScreens.tsx | 2 - .../settings/statementSettingsCont.ts | 3 +- .../solutions/StatementSolutionsPage.tsx | 331 +++++++++--------- .../components/emptyScreen/EmptyScreen.tsx | 108 +++--- .../suggestionCards/SuggestionCards.tsx | 110 +++--- .../suggestionCard/SuggestionCard.tsx | 316 ++++++++--------- .../solutions/statementSolutionsCont.ts | 48 +-- .../solutions/statementSolutionsHooks.ts | 38 -- .../components/vote/StatementVote.tsx | 2 +- 12 files changed, 468 insertions(+), 511 deletions(-) delete mode 100644 src/view/pages/statement/components/solutions/statementSolutionsHooks.ts diff --git a/src/controllers/db/multiStageQuestion/getMultiStageStatements.ts b/src/controllers/db/multiStageQuestion/getMultiStageStatements.ts index 03c2c273a..51c606c4d 100644 --- a/src/controllers/db/multiStageQuestion/getMultiStageStatements.ts +++ b/src/controllers/db/multiStageQuestion/getMultiStageStatements.ts @@ -11,7 +11,7 @@ export async function getFirstEvaluationOptions( ): Promise { try { - console.log("getFirstEvaluationOptions") + const dispatch = store.dispatch; const urlBase = isProduction() ? "qeesi7aziq-uc.a.run.app" : "http://localhost:5001/synthesistalyaron/us-central1"; @@ -23,7 +23,7 @@ export async function getFirstEvaluationOptions( const { randomStatements, error } = await response.json(); if (error) throw new Error(error); z.array(StatementSchema).parse(randomStatements); - console.log(randomStatements) + dispatch(setCurrentMultiStepOptions(randomStatements)); diff --git a/src/model/statements/statementsSlice.ts b/src/model/statements/statementsSlice.ts index 15a14d4c6..4300da962 100644 --- a/src/model/statements/statementsSlice.ts +++ b/src/model/statements/statementsSlice.ts @@ -15,8 +15,6 @@ import { // Helpers import { updateArray } from "../../controllers/general/helpers"; -import { sortSubStatements } from "../../view/pages/statement/components/solutions/statementSolutionsCont"; - enum StatementScreen { chat = "chat", @@ -393,9 +391,7 @@ export const statementOptionsSelector = .sort((a, b) => a.createdAt - b.createdAt) .map((statement) => ({ ...statement })); - const sortedSubStatements = sortSubStatements(subStatements, state.statements.screen); - - return sortedSubStatements; + return subStatements; }; export const questionsSelector = (statementId: string | undefined) => (state: RootState) => state.statements.statements.filter((statement) => statement.parentId === statementId && statement.statementType === StatementType.question).sort((a, b) => a.createdAt - b.createdAt); @@ -467,7 +463,8 @@ export const subscriptionParentStatementSelector = (parentId: string) => export const myStatementsByStatementIdSelector = (statementId: string) => { const user = store.getState().user.user; - return createSelector( + +return createSelector( (state: RootState) => state.statements.statements, (statements) => statements.filter((st) => st.parentId === statementId && st.creatorId === user?.uid) diff --git a/src/view/components/triangle/Triangle.tsx b/src/view/components/triangle/Triangle.tsx index 514214674..89e03c5c9 100644 --- a/src/view/components/triangle/Triangle.tsx +++ b/src/view/components/triangle/Triangle.tsx @@ -14,12 +14,12 @@ interface Props { const Triangle: FC = ({ statement }) => { const {t} = useLanguage(); - const subStatements = useSelector( + const subStatements:Statement[] = useSelector( statementOptionsSelector(statement.statementId) - ).filter((s) => s.evaluation?.sumCon !== undefined); + ).filter((s:Statement) => s.evaluation?.sumCon !== undefined); let maxEvaluators = 0; - subStatements.forEach((subStatement) => { + subStatements.forEach((subStatement:Statement) => { if (subStatement.evaluation?.numberOfEvaluators !== undefined && subStatement.evaluation?.numberOfEvaluators > maxEvaluators) maxEvaluators = subStatement.evaluation.numberOfEvaluators; }); @@ -29,7 +29,7 @@ const Triangle: FC = ({ statement }) => {
- {subStatements.map((subStatement) => { + {subStatements.map((subStatement:Statement) => { return ( ); diff --git a/src/view/pages/statement/components/SwitchScreens.tsx b/src/view/pages/statement/components/SwitchScreens.tsx index b34271f82..18e6a355c 100644 --- a/src/view/pages/statement/components/SwitchScreens.tsx +++ b/src/view/pages/statement/components/SwitchScreens.tsx @@ -53,7 +53,6 @@ export default function SwitchScreens({ return ( @@ -83,7 +82,6 @@ export default function SwitchScreens({ return ( void; showNav?: boolean; questions?: boolean; @@ -31,178 +30,178 @@ interface StatementEvaluationPageProps { } const StatementEvaluationPage: FC = ({ - statement, - handleShowTalker, - questions = false, - toggleAskNotifications, - currentPage = `suggestion`, + statement, + handleShowTalker, + questions = false, + toggleAskNotifications, + currentPage = `suggestion`, }) => { - try { - // Hooks + try { + // Hooks - const navigate = useNavigate(); - const { t } = useLanguage(); - const isMultiStage = + const navigate = useNavigate(); + const { t } = useLanguage(); + const isMultiStage = statement.questionSettings?.questionType === QuestionType.multipleSteps; - const currentStage = statement.questionSettings?.currentStage; - const stageInfo = getStagesInfo(currentStage); - const useSearchForSimilarStatements = + const currentStage = statement.questionSettings?.currentStage; + const stageInfo = getStagesInfo(currentStage); + const useSearchForSimilarStatements = statement.statementSettings?.enableSimilaritiesSearch || false; - // Use States - const [showModal, setShowModal] = useState(false); - const [showToast, setShowToast] = useState(false); - const [showExplanation, setShowExplanation] = useState( - currentStage === QuestionStage.explanation && isMultiStage && !questions - ); - - useEffect(() => { - if (questions) { - setShowToast(false); - } - }, [questions]); - - useEffect(() => { - if (!showToast && !questions) { - setShowToast(true); - } - if ( - currentStage === QuestionStage.explanation && + // Use States + const [showModal, setShowModal] = useState(false); + const [showToast, setShowToast] = useState(false); + const [showExplanation, setShowExplanation] = useState( + currentStage === QuestionStage.explanation && isMultiStage && !questions + ); + + useEffect(() => { + if (questions) { + setShowToast(false); + } + }, [questions]); + + useEffect(() => { + if (!showToast && !questions) { + setShowToast(true); + } + if ( + currentStage === QuestionStage.explanation && isMultiStage && !questions - ) { - setShowExplanation(true); - } - if (currentStage === QuestionStage.voting && !questions) { - //redirect us react router dom to voting page - navigate(`/statement/${statement.statementId}/vote`); - } - }, [statement.questionSettings?.currentStage, questions]); - - const message = stageInfo ? stageInfo.message : false; - - return ( - <> -
-
- {isMultiStage && message && ( - - {getToastButtons(currentStage)} - - )} - -
-
-
- -
- {showExplanation && ( - - - - )} - {showModal && ( - - )} - - ); - - function getToastButtons(questionStage: QuestionStage | undefined) { - try { - switch (questionStage) { - case QuestionStage.voting: - case QuestionStage.firstEvaluation: - case QuestionStage.secondEvaluation: - case QuestionStage.finished: - case QuestionStage.explanation: - return ( -