Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
talyaron committed Sep 10, 2024
1 parent b9aa23a commit fbd9692
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 219 deletions.
43 changes: 22 additions & 21 deletions src/controllers/db/statements/deleteStatements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
}
1 change: 1 addition & 0 deletions src/model/statements/statementsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions src/view/pages/statement/StatementMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -252,7 +241,6 @@ const StatementMain: FC = () => {
subStatements={subStatements}
handleShowTalker={handleShowTalker}
setShowAskPermission={setShowAskPermission}
toggleAskNotifications={toggleAskNotifications}
/>
</MapProvider>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default function SimilarStatementsSuggestion({
isQuestion,
parentStatement,
isSendToStoreTemp,
toggleAskNotifications,
getSubStatements,
}: Readonly<SimilarStatementsSuggestionProps>) {
const { dir } = useLanguage();
Expand All @@ -64,7 +63,6 @@ export default function SimilarStatementsSuggestion({
title: newStatementInput.title,
description: newStatementInput.description,
isOptionSelected: !isQuestion,
toggleAskNotifications,
parentStatement,
isSendToStoreTemp,
});
Expand Down
12 changes: 5 additions & 7 deletions src/view/pages/statement/components/SwitchScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface SwitchScreensProps {
statementSubscription:StatementSubscription | undefined;
handleShowTalker: (statement: User | null) => void;
setShowAskPermission: React.Dispatch<React.SetStateAction<boolean>>;
toggleAskNotifications: () => void;

}

export default function SwitchScreens({
Expand All @@ -31,7 +31,7 @@ export default function SwitchScreens({
statementSubscription,
handleShowTalker,
setShowAskPermission,
toggleAskNotifications,

}: Readonly<SwitchScreensProps>) {
if (!statement) return null;

Expand All @@ -46,23 +46,23 @@ export default function SwitchScreens({
subStatements={subStatements}
handleShowTalker={handleShowTalker}
setShowAskPermission={setShowAskPermission}
toggleAskNotifications={toggleAskNotifications}

/>
);
case Screen.OPTIONS:
return (
<StatementEvaluationPage
statement={statement}
handleShowTalker={handleShowTalker}
toggleAskNotifications={toggleAskNotifications}

/>
);
case Screen.VOTE:
return (
<StatementVote
statement={statement}
subStatements={subStatements}
toggleAskNotifications={toggleAskNotifications}

/>
);
case Screen.MASS_QUESTIONS:
Expand All @@ -84,7 +84,6 @@ export default function SwitchScreens({
statement={statement}
handleShowTalker={handleShowTalker}
questions={true}
toggleAskNotifications={toggleAskNotifications}
/>
);
case Screen.INFO:
Expand All @@ -97,7 +96,6 @@ export default function SwitchScreens({
subStatements={subStatements}
handleShowTalker={handleShowTalker}
setShowAskPermission={setShowAskPermission}
toggleAskNotifications={toggleAskNotifications}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/view/pages/statement/components/chat/StatementChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Props {
subStatements: Statement[];
handleShowTalker: (statement: User | null) => void;
setShowAskPermission: React.Dispatch<React.SetStateAction<boolean>>;
toggleAskNotifications: () => void;

}

let firstTime = true;
Expand All @@ -28,7 +28,7 @@ const StatementChat: FC<Props> = ({
statement,
subStatements,
handleShowTalker,
toggleAskNotifications,

}) => {
const user = useAppSelector(userSelector);
const messagesEndRef = useRef(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const CreateStatementModal: FC<CreateStatementModalProps> = ({
isOption,
setShowModal,
getSubStatements,
toggleAskNotifications,
isSendToStoreTemp,
}) => {
const [isOptionSelected, setIsOptionSelected] = useState(isOption);
Expand All @@ -44,7 +43,6 @@ const CreateStatementModal: FC<CreateStatementModalProps> = ({
title,
description,
isOptionSelected,
toggleAskNotifications,
parentStatement,
isSendToStoreTemp,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface CreateStatementModalSwitchProps {
isQuestion: boolean;
isMultiStage: boolean;
parentStatement: Statement;
toggleAskNotifications: () => void;

}

export default function CreateStatementModalSwitch({
Expand All @@ -18,22 +18,20 @@ export default function CreateStatementModalSwitch({
isQuestion,
isMultiStage,
parentStatement,
toggleAskNotifications,

}: CreateStatementModalSwitchProps) {
return useSimilarStatements ? (
<SimilarStatementsSuggestion
setShowModal={setShowModal}
isQuestion={isQuestion}
parentStatement={parentStatement}
toggleAskNotifications={toggleAskNotifications}
isSendToStoreTemp={isMultiStage}
/>
) : (
<CreateStatementModal
parentStatement={parentStatement}
isOption={!isQuestion}
setShowModal={setShowModal}
toggleAskNotifications={toggleAskNotifications}
isSendToStoreTemp={isMultiStage}
/>
);
Expand Down
Loading

0 comments on commit fbd9692

Please sign in to comment.