Skip to content

Commit

Permalink
lint fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbyk89 committed Jan 12, 2024
1 parent a843258 commit 268489b
Show file tree
Hide file tree
Showing 34 changed files with 545 additions and 570 deletions.
74 changes: 37 additions & 37 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export default function App() {

const [showSignAgreement, setShowSignAgreement] = useState(false);
const [agreement, setAgreement] = useState<string>("");
const [visualViewportHeight, setVisualViewportHeight] = useState(
window.visualViewport?.height || 0
);
const [visualViewportHeight] = useState(window.visualViewport?.height || 0);

function updateUserToStore(user: User | null) {
dispatch(setUser(user));
Expand Down Expand Up @@ -81,44 +79,40 @@ export default function App() {
updateUserToStore,
updateFonSize,
navigateToInitialLocationCB,
resetStoreCB
resetStoreCB,
);

return () => {
usub();
};
}, []);


useEffect(() => {

window.visualViewport?.addEventListener("resize", (event: any) => {

setVisualViewportHeight(event.target?.height || 0);
document.body.style.height = `${event.target?.height}px`;

//change html height to visualViewportHeight state
const html = document.querySelector("html");
if (html) {
const html = document.querySelector("html") as HTMLElement;
html.style.height = `${event.target?.height}px`;
}


//chage height of .page class to visualViewportHeight state
const page = document.querySelector(".page");
if (page) {
const page = document.querySelector(".page") as HTMLElement;
page.style.height = `${event.target?.height}px`;
}

});

return () => {
window.removeEventListener("resize", () => {});
window.visualViewport?.addEventListener("resize", () => {});
};
}, []);
// TODO: Check if this is needed. If not, remove it.
// useEffect(() => {
// window.visualViewport?.addEventListener("resize", (event: any) => {
// setVisualViewportHeight(event.target?.height || 0);
// document.body.style.height = `${event.target?.height}px`;

// //change html height to visualViewportHeight state
// const html = document.querySelector("html");
// if (html) {
// const html = document.querySelector("html") as HTMLElement;
// html.style.height = `${event.target?.height}px`;
// }

// //chage height of .page class to visualViewportHeight state
// const page = document.querySelector(".page");
// if (page) {
// const page = document.querySelector(".page") as HTMLElement;
// page.style.height = `${event.target?.height}px`;
// }
// });

// return () => {
// window.removeEventListener("resize", () => {console.log("window.removeEventListener");});
// window.visualViewport?.addEventListener("resize", () => {});
// };
// }, []);

useEffect(() => {
if (!user) {
Expand Down Expand Up @@ -157,7 +151,7 @@ return () => {
dispatch(updateAgreementToStore(agreement));

updateUserAgreement(agreement).then((isAgreed: boolean) =>
setShowSignAgreement(!isAgreed)
setShowSignAgreement(!isAgreed),
);
} else {
setShowSignAgreement(false);
Expand All @@ -169,9 +163,15 @@ return () => {
}

return (
<div style={{height:`${visualViewportHeight}px`, overflowY:"hidden", position:'fixed'}}>
<div
style={{
height: `${visualViewportHeight}px`,
overflowY: "hidden",
position: "fixed",
}}
>
<Accessiblity />

<Outlet />
{showSignAgreement && (
<Modal>
Expand Down
11 changes: 5 additions & 6 deletions src/functions/db/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export function googleLogin() {
});
}
export function listenToAuth(
cb: Function,
fontSizeCB: Function,
navigationCB: Function,
resetCB: Function
cb: (user: User | null) => void,
fontSizeCB: (fontSize: number) => void,
navigationCB: (path: string) => void,
resetCB: () => void,
): Unsubscribe {
return onAuthStateChanged(auth, async (userFB) => {
try {
Expand All @@ -70,11 +70,10 @@ export function listenToAuth(

const userDB = (await setUserToDB(_user)) as User;

const { fontSize } = userDB || { fontSize: 14 };
const fontSize = userDB.fontSize ? userDB.fontSize : 14;

fontSizeCB(fontSize);


document.body.style.fontSize = fontSize + "px";

if (!userDB) throw new Error("userDB is undefined");
Expand Down
86 changes: 49 additions & 37 deletions src/functions/db/evaluation/getEvaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { EvaluationSchema } from "../../../model/evaluations/evaluationModel";

export function listenToEvaluations(
parentId: string,
updateCallBack: Function
): Function {
updateCallBack: (evaluation: Evaluation) => void,
) {
try {
const evaluationsRef = collection(DB, Collections.evaluations);
const evaluatorId = getUserFromFirebase()?.uid;
Expand All @@ -24,16 +24,26 @@ export function listenToEvaluations(
const q = query(
evaluationsRef,
where("parentId", "==", parentId),
where("evaluatorId", "==", evaluatorId)
where("evaluatorId", "==", evaluatorId),
);
return onSnapshot(q, (evaluationsDB) => {

return onSnapshot(q, (evaluationsDB) => {
try {
evaluationsDB.forEach((evaluationDB) => {
try {
//set evaluation to store
EvaluationSchema.parse(evaluationDB.data());
updateCallBack(evaluationDB.data());
const { success } = EvaluationSchema.safeParse(
evaluationDB.data(),
);

if (!success)
throw new Error(
"evaluationDB is not valid in listenToEvaluations()",
);

const evaluation = evaluationDB.data() as Evaluation;

updateCallBack(evaluation);
} catch (error) {
console.error(error);
}
Expand All @@ -44,8 +54,6 @@ return onSnapshot(q, (evaluationsDB) => {
});
} catch (error) {
console.error(error);

return () => {};
}
}

Expand All @@ -56,46 +64,50 @@ export async function getEvaluations(parentId: string): Promise<Evaluation[]> {

const evaluationsDB = await getDocs(q);
const evauatorsIds = new Set<string>();
const evaluations = evaluationsDB.docs.map((evaluationDB: any) => {
const evaluation = evaluationDB.data() as Evaluation;
if (!evauatorsIds.has(evaluation.evaluatorId)) {
//prevent duplicate evaluators
evauatorsIds.add(evaluation.evaluatorId);

return evaluation;
}
}).filter((evaluation) => evaluation) as Evaluation[];
const evaluations = evaluationsDB.docs
.map((evaluationDB: any) => {
const evaluation = evaluationDB.data() as Evaluation;
if (!evauatorsIds.has(evaluation.evaluatorId)) {
//prevent duplicate evaluators
evauatorsIds.add(evaluation.evaluatorId);

return evaluation;
}
})
.filter((evaluation) => evaluation) as Evaluation[];

//get evaluators details if not allready in db
const evaluatorsPromise = evaluations.map((evaluation) => {
if (!evaluation.evaluator) {
const evaluatorRef = doc(
DB,
Collections.users,
evaluation.evaluatorId
);
const promise = getDoc(evaluatorRef);

return promise;
}
}).filter((promise) => promise) as Promise<any>[];
const evaluatorsPromise = evaluations
.map((evaluation) => {
if (!evaluation.evaluator) {
const evaluatorRef = doc(
DB,
Collections.users,
evaluation.evaluatorId,
);
const promise = getDoc(evaluatorRef);

return promise;
}
})
.filter((promise) => promise) as Promise<any>[];

const evaluatorsDB = await Promise.all(evaluatorsPromise);
const evaluators = evaluatorsDB.map((evaluatorDB) =>
evaluatorDB?.data()
const evaluators = evaluatorsDB.map(
(evaluatorDB) => evaluatorDB?.data(),
) as User[];

evaluations.forEach((evaluation) => {
const evaluator = evaluators.find(
(evaluator) => evaluator?.uid === evaluation.evaluatorId
(evaluator) => evaluator?.uid === evaluation.evaluatorId,
);
if (evaluator) evaluation.evaluator = evaluator;
});
return evaluations;

return evaluations;
} catch (error) {
console.error(error);
return [] as Evaluation[];

return [] as Evaluation[];
}
}
12 changes: 7 additions & 5 deletions src/functions/db/images/setImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { getDownloadURL, ref, uploadBytesResumable } from "@firebase/storage";
export function uploadImageToStorage(
file: File,
statement: Statement,
setProgress: Function
): Promise<string | undefined> {
setProgress: (progress: number) => void,
): Promise<string> {
return new Promise((resolve, reject) => {
const imageRef = ref(
storage,
`${Collections.statements}/${statement.statementId}/imgId-${Math.random()}`
`${Collections.statements}/${
statement.statementId
}/imgId-${Math.random()}`,
);

const uploadTask = uploadBytesResumable(imageRef, file);
Expand Down Expand Up @@ -38,14 +40,14 @@ export function uploadImageToStorage(
async () => {
try {
const downloadURL = await getDownloadURL(
uploadTask.snapshot.ref
uploadTask.snapshot.ref,
);
resolve(downloadURL);
} catch (error) {
console.error("Error retrieving download URL:", error);
reject(error);
}
}
},
);
});
}
Loading

0 comments on commit 268489b

Please sign in to comment.