diff --git a/src/controllers/db/statements/deleteStatements.ts b/src/controllers/db/statements/deleteStatements.ts index 688c2376..3e31ad57 100644 --- a/src/controllers/db/statements/deleteStatements.ts +++ b/src/controllers/db/statements/deleteStatements.ts @@ -5,30 +5,31 @@ import { DB } from "../config"; export async function deleteStatementFromDB ( - statement: Statement, - isAuthorized: boolean, + statement: Statement, + isAuthorized: boolean, ) { - try { - if(!statement) throw new Error("No statement"); + try { + if(!statement) throw new Error("No statement"); - if(!isAuthorized) alert("You are not authorized to delete this statement"); + if(!isAuthorized) alert("You are not authorized to delete this statement"); - if (!statement) throw new Error("No statement"); - const confirmed = confirm(`Are you sure you want to delete ${statement.statement}?`); - if (!confirmed) return; + if (!statement) throw new Error("No statement"); + const confirmed = confirm(`Are you sure you want to delete ${statement.statement}?`); + if (!confirmed) return; - //check if the statement has children - const childrenRef = collection(DB, Collections.statements) - const q = query(childrenRef, where("parentId", "==", statement.statementId), limit(1)); - const hasChildren = await getDocs(q); - if (hasChildren.docs.length > 0) { - alert("You cannot delete a statement with children. Please delete the children first.") - return; - } - const statementRef = doc(DB, Collections.statements, statement.statementId); - await deleteDoc(statementRef); - } catch (error) { - console.error(error); + //check if the statement has children + const childrenRef = collection(DB, Collections.statements) + const q = query(childrenRef, where("parentId", "==", statement.statementId), limit(1)); + const hasChildren = await getDocs(q); + if (hasChildren.docs.length > 0) { + alert("You cannot delete a statement with children. Please delete the children first.") + + return; + } + const statementRef = doc(DB, Collections.statements, statement.statementId); + await deleteDoc(statementRef); + } catch (error) { + console.error(error); - } + } } \ No newline at end of file diff --git a/src/model/statements/statementsSlice.ts b/src/model/statements/statementsSlice.ts index 1c246609..fc88f586 100644 --- a/src/model/statements/statementsSlice.ts +++ b/src/model/statements/statementsSlice.ts @@ -373,6 +373,7 @@ export const statementSelector = state.statements.statements.find( (statement) => statement.statementId === statementId, ); + // export const statementSubsSelector = // (statementId: string | undefined) => (state: RootState) => // state.statements.statements diff --git a/src/view/pages/statement/StatementMain.tsx b/src/view/pages/statement/StatementMain.tsx index 40f1ac94..ece6f517 100644 --- a/src/view/pages/statement/StatementMain.tsx +++ b/src/view/pages/statement/StatementMain.tsx @@ -21,7 +21,6 @@ import { listenToEvaluations } from "@/controllers/db/evaluation/getEvaluation"; // Redux Store import { useAppDispatch, useAppSelector } from "@/controllers/hooks/reduxHooks"; -import { statementNotificationSelector } from "@/model/statements/statementsSlice"; import { RootState } from "@/model/store"; import { userSelector } from "@/model/users/userSlice"; import { useSelector } from "react-redux"; @@ -73,9 +72,6 @@ const StatementMain: FC = () => { // Redux store const dispatch = useAppDispatch(); const user = useSelector(userSelector); - const hasNotifications = useAppSelector( - statementNotificationSelector(statementId) - ); const subStatements = useAppSelector((state: RootState) => subStatementsSelector(state, statementId) @@ -92,13 +88,6 @@ const StatementMain: FC = () => { // Constants const screen = availableScreen(statement, statementSubscription, page); - // Functions - const toggleAskNotifications = () => { - // Ask for notifications after user interaction. - if (!hasNotifications && !statementSubscription?.userAskedForNotification) { - setAskNotifications(true); - } - }; const handleShowTalker = (_talker: User | null) => { if (!talker) { @@ -252,7 +241,6 @@ const StatementMain: FC = () => { subStatements={subStatements} handleShowTalker={handleShowTalker} setShowAskPermission={setShowAskPermission} - toggleAskNotifications={toggleAskNotifications} /> diff --git a/src/view/pages/statement/components/SimilarStatementsSuggestion/SimilarStatementsSuggestion.tsx b/src/view/pages/statement/components/SimilarStatementsSuggestion/SimilarStatementsSuggestion.tsx index 52896e9c..83aaf1a1 100644 --- a/src/view/pages/statement/components/SimilarStatementsSuggestion/SimilarStatementsSuggestion.tsx +++ b/src/view/pages/statement/components/SimilarStatementsSuggestion/SimilarStatementsSuggestion.tsx @@ -43,7 +43,6 @@ export default function SimilarStatementsSuggestion({ isQuestion, parentStatement, isSendToStoreTemp, - toggleAskNotifications, getSubStatements, }: Readonly) { const { dir } = useLanguage(); @@ -64,7 +63,6 @@ export default function SimilarStatementsSuggestion({ title: newStatementInput.title, description: newStatementInput.description, isOptionSelected: !isQuestion, - toggleAskNotifications, parentStatement, isSendToStoreTemp, }); diff --git a/src/view/pages/statement/components/SwitchScreens.tsx b/src/view/pages/statement/components/SwitchScreens.tsx index 18e6a355..226c7d58 100644 --- a/src/view/pages/statement/components/SwitchScreens.tsx +++ b/src/view/pages/statement/components/SwitchScreens.tsx @@ -21,7 +21,7 @@ interface SwitchScreensProps { statementSubscription:StatementSubscription | undefined; handleShowTalker: (statement: User | null) => void; setShowAskPermission: React.Dispatch>; - toggleAskNotifications: () => void; + } export default function SwitchScreens({ @@ -31,7 +31,7 @@ export default function SwitchScreens({ statementSubscription, handleShowTalker, setShowAskPermission, - toggleAskNotifications, + }: Readonly) { if (!statement) return null; @@ -46,7 +46,7 @@ export default function SwitchScreens({ subStatements={subStatements} handleShowTalker={handleShowTalker} setShowAskPermission={setShowAskPermission} - toggleAskNotifications={toggleAskNotifications} + /> ); case Screen.OPTIONS: @@ -54,7 +54,7 @@ export default function SwitchScreens({ ); case Screen.VOTE: @@ -62,7 +62,7 @@ export default function SwitchScreens({ ); case Screen.MASS_QUESTIONS: @@ -84,7 +84,6 @@ export default function SwitchScreens({ statement={statement} handleShowTalker={handleShowTalker} questions={true} - toggleAskNotifications={toggleAskNotifications} /> ); case Screen.INFO: @@ -97,7 +96,6 @@ export default function SwitchScreens({ subStatements={subStatements} handleShowTalker={handleShowTalker} setShowAskPermission={setShowAskPermission} - toggleAskNotifications={toggleAskNotifications} /> ); } diff --git a/src/view/pages/statement/components/chat/StatementChat.tsx b/src/view/pages/statement/components/chat/StatementChat.tsx index 661b0067..d11a32ec 100644 --- a/src/view/pages/statement/components/chat/StatementChat.tsx +++ b/src/view/pages/statement/components/chat/StatementChat.tsx @@ -18,7 +18,7 @@ interface Props { subStatements: Statement[]; handleShowTalker: (statement: User | null) => void; setShowAskPermission: React.Dispatch>; - toggleAskNotifications: () => void; + } let firstTime = true; @@ -28,7 +28,7 @@ const StatementChat: FC = ({ statement, subStatements, handleShowTalker, - toggleAskNotifications, + }) => { const user = useAppSelector(userSelector); const messagesEndRef = useRef(null); diff --git a/src/view/pages/statement/components/createStatementModal/CreateStatementModal.tsx b/src/view/pages/statement/components/createStatementModal/CreateStatementModal.tsx index 01d87a65..3de5c507 100644 --- a/src/view/pages/statement/components/createStatementModal/CreateStatementModal.tsx +++ b/src/view/pages/statement/components/createStatementModal/CreateStatementModal.tsx @@ -29,7 +29,6 @@ const CreateStatementModal: FC = ({ isOption, setShowModal, getSubStatements, - toggleAskNotifications, isSendToStoreTemp, }) => { const [isOptionSelected, setIsOptionSelected] = useState(isOption); @@ -44,7 +43,6 @@ const CreateStatementModal: FC = ({ title, description, isOptionSelected, - toggleAskNotifications, parentStatement, isSendToStoreTemp, }); diff --git a/src/view/pages/statement/components/createStatementModalSwitch/CreateStatementModalSwitch.tsx b/src/view/pages/statement/components/createStatementModalSwitch/CreateStatementModalSwitch.tsx index 22a26cdc..152ff277 100644 --- a/src/view/pages/statement/components/createStatementModalSwitch/CreateStatementModalSwitch.tsx +++ b/src/view/pages/statement/components/createStatementModalSwitch/CreateStatementModalSwitch.tsx @@ -9,7 +9,7 @@ interface CreateStatementModalSwitchProps { isQuestion: boolean; isMultiStage: boolean; parentStatement: Statement; - toggleAskNotifications: () => void; + } export default function CreateStatementModalSwitch({ @@ -18,14 +18,13 @@ export default function CreateStatementModalSwitch({ isQuestion, isMultiStage, parentStatement, - toggleAskNotifications, + }: CreateStatementModalSwitchProps) { return useSimilarStatements ? ( ) : ( @@ -33,7 +32,6 @@ export default function CreateStatementModalSwitch({ parentStatement={parentStatement} isOption={!isQuestion} setShowModal={setShowModal} - toggleAskNotifications={toggleAskNotifications} isSendToStoreTemp={isMultiStage} /> ); diff --git a/src/view/pages/statement/components/nav/bottom/StatementBottomNav.tsx b/src/view/pages/statement/components/nav/bottom/StatementBottomNav.tsx index 53c2b1d4..508049ca 100644 --- a/src/view/pages/statement/components/nav/bottom/StatementBottomNav.tsx +++ b/src/view/pages/statement/components/nav/bottom/StatementBottomNav.tsx @@ -15,10 +15,10 @@ import SortIcon from "@/assets/icons/sort.svg?react"; import useStatementColor from "@/controllers/hooks/useStatementColor"; import { - NavItem, - optionsArray, - questionsArray, - votesArray, + NavItem, + optionsArray, + questionsArray, + votesArray, } from "./StatementBottomNavModal"; import "./StatementBottomNav.scss"; @@ -30,101 +30,101 @@ interface Props { } const StatementBottomNav: FC = ({ setShowModal, statement }) => { - const { page } = useParams(); + const { page } = useParams(); - const navItems = getNavigationScreens(page); + const navItems = getNavigationScreens(page); - const [isNavigationOpen, setIsNavigationOpen] = useState(false); - const [showSorting, setShowSorting] = useState(false); + const [isNavigationOpen, setIsNavigationOpen] = useState(false); + const [showSorting, setShowSorting] = useState(false); - const statementColor = useStatementColor( - statement.statementType || StatementType.statement - ); + const statementColor = useStatementColor( + statement.statementType || StatementType.statement + ); - //used to check if the user can add a new option in voting and in evaluation screens - const addOption: boolean | undefined = + //used to check if the user can add a new option in voting and in evaluation screens + const addOption: boolean | undefined = statement.statementSettings?.enableAddEvaluationOption; - const addVotingOption: boolean | undefined = + const addVotingOption: boolean | undefined = statement.statementSettings?.enableAddVotingOption; - const showAddOptionEvaluation = page === Screen.OPTIONS && addOption; - const showAddOptionVoting = page === Screen.VOTE && addVotingOption; - const showAddQuestion = page === Screen.QUESTIONS; - const isAddOption = + const showAddOptionEvaluation = page === Screen.OPTIONS && addOption; + const showAddOptionVoting = page === Screen.VOTE && addVotingOption; + const showAddQuestion = page === Screen.QUESTIONS; + const isAddOption = showAddOptionEvaluation || showAddOptionVoting || showAddQuestion; - const handleMidIconClick = () => { - if (isAddOption) { - setShowModal(true); - } - }; - - function handleSortingClick() { - setShowSorting(!showSorting); - } - - return ( - <> - {isNavigationOpen && ( -
setIsNavigationOpen(false)} - /> - )} -
- -
- {navItems.map((navItem, i) => ( -
- setShowSorting(false)} - > - - - {navItem.name} -
- ))} -
- -
-
-
- - ); + const handleMidIconClick = () => { + if (isAddOption) { + setShowModal(true); + } + }; + + function handleSortingClick() { + setShowSorting(!showSorting); + } + + return ( + <> + {isNavigationOpen && ( +
setIsNavigationOpen(false)} + /> + )} +
+ +
+ {navItems.map((navItem, i) => ( +
+ setShowSorting(false)} + > + + + {navItem.name} +
+ ))} +
+ +
+
+
+ + ); }; export default StatementBottomNav; function getNavigationScreens(page: string | undefined): NavItem[] { - if (!page) return optionsArray; - - switch (page) { - case Screen.VOTE: - return votesArray; - case Screen.OPTIONS: - return optionsArray; - case Screen.QUESTIONS: - return questionsArray; - default: - return optionsArray; - } + if (!page) return optionsArray; + + switch (page) { + case Screen.VOTE: + return votesArray; + case Screen.OPTIONS: + return optionsArray; + case Screen.QUESTIONS: + return questionsArray; + default: + return optionsArray; + } } interface NavIconProps { @@ -133,17 +133,17 @@ interface NavIconProps { } const NavIcon: FC = ({ name, color }) => { - const props = { style: { color } }; - switch (name) { - case "New": - return ; - case "Update": - return ; - case "Random": - return ; - case "Agreement": - return ; - default: - return null; - } + const props = { style: { color } }; + switch (name) { + case "New": + return ; + case "Update": + return ; + case "Random": + return ; + case "Agreement": + return ; + default: + return null; + } }; diff --git a/src/view/pages/statement/components/settings/statementSettingsCont.ts b/src/view/pages/statement/components/settings/statementSettingsCont.ts index 7a01acad..c1693bdf 100644 --- a/src/view/pages/statement/components/settings/statementSettingsCont.ts +++ b/src/view/pages/statement/components/settings/statementSettingsCont.ts @@ -268,7 +268,6 @@ interface CreateStatementFromModalParams { description: string; isOptionSelected: boolean; parentStatement: Statement | "top"; - toggleAskNotifications?: VoidFunction; isSendToStoreTemp?: boolean; } @@ -276,7 +275,6 @@ export async function createStatementFromModal({ title, description, isOptionSelected, - toggleAskNotifications, parentStatement }: CreateStatementFromModalParams) { try { @@ -285,7 +283,6 @@ export async function createStatementFromModal({ const newStatement = createStatement({ ...defaultStatementSettings, hasChildren: true, - toggleAskNotifications, text: title, description, parentStatement, diff --git a/src/view/pages/statement/components/solutions/StatementSolutionsPage.tsx b/src/view/pages/statement/components/solutions/StatementSolutionsPage.tsx index cff91c7c..3d84e6ad 100644 --- a/src/view/pages/statement/components/solutions/StatementSolutionsPage.tsx +++ b/src/view/pages/statement/components/solutions/StatementSolutionsPage.tsx @@ -25,7 +25,6 @@ interface StatementEvaluationPageProps { handleShowTalker: (talker: User | null) => void; showNav?: boolean; questions?: boolean; - toggleAskNotifications: () => void; currentPage?: string; } @@ -33,7 +32,6 @@ const StatementEvaluationPage: FC = ({ statement, handleShowTalker, questions = false, - toggleAskNotifications, currentPage = `suggestion`, }) => { try { @@ -120,7 +118,6 @@ const StatementEvaluationPage: FC = ({ )} {showModal && ( void; @@ -20,70 +19,69 @@ interface Props { } const SolutionMenu: FC = ({ - statement, - statementSubscription, - isAuthorized, - isCardMenuOpen, - setIsCardMenuOpen, - isEdit, - setIsEdit, - handleSetOption, + statement, + isAuthorized, + isCardMenuOpen, + setIsCardMenuOpen, + isEdit, + setIsEdit, + handleSetOption, }) => { - const { t } = useLanguage(); + const { t } = useLanguage(); - if (!isAuthorized) return null; + if (!isAuthorized) return null; - useEffect(() => { - if (isCardMenuOpen) { - setTimeout(() => { - setIsCardMenuOpen(false); - }, 5000); - } - }, [isCardMenuOpen]); + useEffect(() => { + if (isCardMenuOpen) { + setTimeout(() => { + setIsCardMenuOpen(false); + }, 5000); + } + }, [isCardMenuOpen]); - return ( - - {isAuthorized && ( - } - onOptionClick={() => { - setIsEdit(!isEdit); - setIsCardMenuOpen(false); - }} - /> - )} - {isAuthorized && ( - } - label={ - isOptionFn(statement) - ? t("Unmark as a Solution") - : t("Mark as a Solution") - } - onOptionClick={() => { - handleSetOption(); - setIsCardMenuOpen(false); - }} - /> - )} - {isAuthorized && ( - } - onOptionClick={() => { - deleteStatementFromDB(statement, isAuthorized); - setIsCardMenuOpen(false); - }} - /> - )} - - ); + return ( + + {isAuthorized && ( + } + onOptionClick={() => { + setIsEdit(!isEdit); + setIsCardMenuOpen(false); + }} + /> + )} + {isAuthorized && ( + } + label={ + isOptionFn(statement) + ? t("Unmark as a Solution") + : t("Mark as a Solution") + } + onOptionClick={() => { + handleSetOption(); + setIsCardMenuOpen(false); + }} + /> + )} + {isAuthorized && ( + } + onOptionClick={() => { + deleteStatementFromDB(statement, isAuthorized); + setIsCardMenuOpen(false); + }} + /> + )} + + ); }; export default SolutionMenu; diff --git a/src/view/pages/statement/components/solutions/components/suggestionCards/suggestionCard/SuggestionCard.tsx b/src/view/pages/statement/components/solutions/components/suggestionCards/suggestionCard/SuggestionCard.tsx index 83c4f640..cf64cbcd 100644 --- a/src/view/pages/statement/components/solutions/components/suggestionCards/suggestionCard/SuggestionCard.tsx +++ b/src/view/pages/statement/components/solutions/components/suggestionCards/suggestionCard/SuggestionCard.tsx @@ -169,7 +169,6 @@ const SuggestionCard: FC = ({
void; + } let getVoteFromDB = false; const StatementVote: FC = ({ statement, subStatements, - toggleAskNotifications, + }) => { // * Hooks * // const dispatch = useAppDispatch(); @@ -115,7 +115,7 @@ const StatementVote: FC = ({ parentStatement={statement} isQuestion={false} setShowModal={setIsCreateStatementModalOpen} - toggleAskNotifications={toggleAskNotifications} + /> )} {isStatementInfoModalOpen && (