Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into generating-password
Browse files Browse the repository at this point in the history
  • Loading branch information
Reshex committed Sep 8, 2024
2 parents 58dd2b4 + 95114fa commit 32335cf
Show file tree
Hide file tree
Showing 26 changed files with 970 additions and 785 deletions.
9 changes: 9 additions & 0 deletions .firebasesrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"projects": {
"default": "delib-v3-dev",
"dev": "delib-v3-dev",
"prod": "synthesistalyaron"
},
"targets": {},
"etags": {}
}
4 changes: 3 additions & 1 deletion src/assets/Languages/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,7 @@
"Abstention": "الامتناع",
"Support": "الدعم",
"Against": "ضد",
"Voters": "الناخبين"
"Voters": "الناخبين",
"Did Not Vote": "لم يصوت",
"Get Non Voters": "الحصول على الناخبين غير المصوتين"
}
14 changes: 8 additions & 6 deletions src/assets/Languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"terms of use": "Nutzungsbedingungen",
"Dont agree": "Nicht zustimmen",
"Blocked": "Gesperrt",
"Couldn't find the invitation. Please check the PIN and try again." : "Einladung nicht gefunden. Bitte überprüfen Sie die PIN und versuchen Sie es erneut.",
"Couldn't find the invitation. Please check the PIN and try again.": "Einladung nicht gefunden. Bitte überprüfen Sie die PIN und versuchen Sie es erneut.",
"Cancel": "Abbrechen",
"Cancellation of division": "Aufteilung stornieren",
"Chat": "Chat",
Expand Down Expand Up @@ -62,7 +62,7 @@
"Invited:": "Eingeladen:",
"It is necessary to receive notifications": "Es ist notwendig, Benachrichtigungen zu erhalten",
"Invite with PIN number": "Mit PIN-Nummer einladen",
"Join with PIN number":"Mit PIN-Nummer beitreten",
"Join with PIN number": "Mit PIN-Nummer beitreten",
"Login with a temporary name": "Mit einem temporären Namen anmelden",
"Join": "Beitreten",
"Map": "Karte",
Expand Down Expand Up @@ -139,10 +139,10 @@
"Click on": "Klicke auf",
"Add suggestion button": "Schaltfläche „Vorschlag hinzufügen“",
"to add your suggestion": "um Ihren Vorschlag hinzuzufügen",
"Add suggestion":"Vorschlag hinzufügen",
"Add suggestion": "Vorschlag hinzufügen",
"Add question button": "Schaltfläche „Frage hinzufügen“.",
"to add your question": "um Ihre Frage hinzuzufügen",
"Add question":"Frage hinzufügen",
"Add question": "Frage hinzufügen",
"Sort questions": "Fragen sortieren",
"Sort suggestions": "Vorschläge sortieren",
"Allow similarity search": "Ähnlichkeitssuche erlauben",
Expand All @@ -152,5 +152,7 @@
"Abstention": "Enthaltung",
"Support": "Unterstützung",
"Against": "Gegen",
"Voters": "Wähler"
}
"Voters": "Wähler",
"Did Not Vote": "Hat nicht gewählt",
"Get Non Voters": "Nichtwähler erhalten"
}
5 changes: 3 additions & 2 deletions src/assets/Languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"Abstention": "Abstention",
"Support": "Support",
"Against": "Against",
"Voters": "Voters"

"Voters": "Voters",
"Did Not Vote": "Did Not Vote",
"Get Non Voters": "Get Non Voters"
}
14 changes: 8 additions & 6 deletions src/assets/Languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"terms of use": "términos de uso",
"Dont agree": "No estoy de acuerdo",
"Blocked": "Bloqueado",
"Couldn't find the invitation. Please check the PIN and try again." : "No se pudo encontrar la invitación. Por favor, comprueba el PIN e inténtalo de nuevo.",
"Couldn't find the invitation. Please check the PIN and try again.": "No se pudo encontrar la invitación. Por favor, comprueba el PIN e inténtalo de nuevo.",
"Cancel": "Cancelar",
"Cancellation of division": "Cancelación de la división",
"Chat": "Chat",
Expand Down Expand Up @@ -135,14 +135,14 @@
"Welcome to room": "Bienvenido a la sala",
"single-step": "Un solo paso",
"multiple-steps": "Múltiples pasos",
"There are no rooms yet":"Aún no hay habitaciones",
"There are no rooms yet": "Aún no hay habitaciones",
"Click on": "Haga clic en",
"Add suggestion button": "Añadir botón de sugerencia",
"to add your suggestion": "para agregar tu sugerencia",
"Add suggestion":"Agregar sugerencia",
"Add suggestion": "Agregar sugerencia",
"Add question button": "Añadir botón de pregunta",
"to add your question": "para agregar tu pregunta",
"Add question":"Agregar pregunta",
"Add question": "Agregar pregunta",
"Sort questions": "Ordenar preguntas",
"Sort suggestions": "Ordenar sugerencias",
"Allow similarity search": "Permitir búsqueda de similitudes",
Expand All @@ -152,5 +152,7 @@
"Abstention": "Abstención",
"Support": "Soporte",
"Against": "En contra",
"Voters": "Votantes"
}
"Voters": "Votantes",
"Did Not Vote": "No Votó",
"Get Non Voters": "Obtener No Votantes"
}
352 changes: 177 additions & 175 deletions src/assets/Languages/he.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/assets/Languages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,7 @@
"Abstention": "Onthouding",
"Support": "Ondersteuning",
"Against": "Tegen",
"Voters": "Stemmers"
"Voters": "Stemmers",
"Did Not Vote": "Heeft niet gestemd",
"Get Non Voters": "Krijg niet-stemmers"
}
3 changes: 1 addition & 2 deletions src/controllers/db/configKey.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mode = import.meta.env.VITE_APP_ENV as 'development' | 'production';


console.log("mode", mode);

Check failure on line 3 in src/controllers/db/configKey.ts

View workflow job for this annotation

GitHub Actions / basic-checks (18.x)

Unexpected console statement
const firebaseConfig = {
development: {
apiKey: import.meta.env.VITE_FIREBASE_API_KEY_DEV,
Expand All @@ -24,7 +24,6 @@ const firebaseConfig = {
},
};


const vapidKeys = {
development: import.meta.env.VITE_FIREBASE_VAPID_KEY_DEV,
production: import.meta.env.VITE_FIREBASE_VAPID_KEY_PROD,
Expand Down
89 changes: 44 additions & 45 deletions src/controllers/db/multiStageQuestion/getMultiStageStatements.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
import { QuestionStage, Statement } from "delib-npm";
import { Dispatch } from "react";
import { Statement, StatementSchema } from "delib-npm";
import { z } from "zod";
import { isProduction } from "@/controllers/general/helpers";
import { setTempStatementsForPresentation } from "@/model/statements/statementsSlice";
import { setCurrentMultiStepOptions } from "@/model/statements/statementsSlice";
import { store } from "@/model/store";

export async function getMultiStageOptions(

export async function getFirstEvaluationOptions(
statement: Statement,

): Promise<void> {
const dispatch: Dispatch<unknown> = store.dispatch;

try {

const dispatch = store.dispatch;
const urlBase = isProduction() ? "qeesi7aziq-uc.a.run.app" : "http://localhost:5001/synthesistalyaron/us-central1";

const url = isProduction() ? `https://getRandomStatements-${urlBase}` : "http://localhost:5001/synthesistalyaron/us-central1/getRandomStatements";

const response = await fetch(
`${url}?parentId=${statement.statementId}&limit=6`
);
const { randomStatements, error } = await response.json();
if (error) throw new Error(error);
z.array(StatementSchema).parse(randomStatements);


dispatch(setCurrentMultiStepOptions(randomStatements));


} catch (error) {
console.error(error);


}
}

export async function getSecondEvaluationOptions(statement: Statement): Promise<void> {

try {
const dispatch = store.dispatch;
const urlBase = isProduction() ? "qeesi7aziq-uc.a.run.app" : "http://localhost:5001/synthesistalyaron/us-central1";

if (statement.questionSettings?.currentStage === QuestionStage.suggestion) {
const userId = store.getState().user.user?.uid;
if (!userId) throw new Error("User not found");

const url = isProduction() ? `https://getUserOptions-${urlBase}` : "http://localhost:5001/synthesistalyaron/us-central1/getUserOptions";

const response = await fetch(
`${url}?parentId=${statement.statementId}&userId=${userId}`
);
const { statements, error } = await response.json();
if (error) throw new Error(error);

dispatch(setTempStatementsForPresentation(statements));
} else if (
statement.questionSettings?.currentStage === QuestionStage.firstEvaluation
) {
const url = isProduction() ? `https://getRandomStatements-${urlBase}` : "http://localhost:5001/synthesistalyaron/us-central1/getRandomStatements";

const response = await fetch(
`${url}?parentId=${statement.statementId}&limit=6`
);
const { randomStatements, error } = await response.json();
if (error) throw new Error(error);
dispatch(setTempStatementsForPresentation(randomStatements));
} else if (
statement.questionSettings?.currentStage ===
QuestionStage.secondEvaluation
) {
const url = isProduction() ? `https://getTopStatements-${urlBase}` : "http://localhost:5001/synthesistalyaron/us-central1/getTopStatements";
const response = await fetch(
`${url}?parentId=${statement.statementId}&limit=6`
);
const { topSolutions, error } = await response.json();
if (error) throw new Error(error);
dispatch(setTempStatementsForPresentation(topSolutions));
} else {
dispatch(setTempStatementsForPresentation([]));
}
const url = isProduction() ? `https://getTopStatements-${urlBase}` : "http://localhost:5001/synthesistalyaron/us-central1/getTopStatements";
const response = await fetch(
`${url}?parentId=${statement.statementId}&limit=10`
);
const { topSolutions, error } = await response.json();
if (error) throw new Error(error);

z.array(StatementSchema).parse(topSolutions);
dispatch(setCurrentMultiStepOptions(topSolutions));
} catch (error) {
console.error(error);
dispatch(setTempStatementsForPresentation([]));

}
}
86 changes: 41 additions & 45 deletions src/controllers/db/vote/getVotes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
collection,
doc,
getDoc,
getDocs,
query,
where,
collection,
doc,
getDoc,
getDocs,
query,
where,
} from "firebase/firestore";
import { Collections, Statement, StatementSchema, Vote } from "delib-npm";
import { DB } from "../config";
Expand All @@ -14,56 +14,52 @@ import { store } from "@/model/store";

// Why get user from firebase when we can pass it as a parameter?
export async function getToVoteOnParent(
parentId: string,
updateStoreWithVoteCB: (statement: Statement) => void,
parentId: string,
updateStoreWithVoteCB: (statement: Statement) => void
): Promise<void> {
try {
const user = getUserFromFirebase();
if (!user) throw new Error("User not logged in");
if(!parentId) throw new Error("ParentId not provided");
const voteId = getVoteId(user.uid, parentId);
if (!voteId) throw new Error("VoteId not found");
try {
const user = getUserFromFirebase();
if (!user) throw new Error("User not logged in");
if (!parentId) throw new Error("ParentId not provided");
const voteId = getVoteId(user.uid, parentId);
if (!voteId) throw new Error("VoteId not found");

const parentVoteRef = doc(
DB,
Collections.votes,
voteId
);
const parentVoteRef = doc(DB, Collections.votes, voteId);

const voteDB = await getDoc(parentVoteRef);
const voteDB = await getDoc(parentVoteRef);

const vote = voteDB.data();
if (!vote) return; // the user has not voted on this statement
VoteSchema.parse(vote);
const vote = voteDB.data();
if (!vote) return;
VoteSchema.parse(vote);

//get statemtn to update to store
const statementRef = doc(DB, Collections.statements, vote.statementId);
const statementDB = await getDoc(statementRef);
//get statemtn to update to store
const statementRef = doc(DB, Collections.statements, vote.statementId);
const statementDB = await getDoc(statementRef);

const statement = statementDB.data() as Statement;
if (!statement) throw new Error("Parent not found");
StatementSchema.parse(statement);
const statement = statementDB.data() as Statement;
if (!statement) throw new Error("Parent not found");
StatementSchema.parse(statement);

updateStoreWithVoteCB(statement);
} catch (error) {
console.error(error);
}
updateStoreWithVoteCB(statement);
} catch (error) {
console.error(error);
}
}

export async function getVoters(parentId: string): Promise<Vote[]> {
try {
const user = store.getState().user.user;
if (!user) throw new Error("User not logged in");
const votesRef = collection(DB, Collections.votes);
const q = query(votesRef, where("parentId", "==", parentId));
try {
const user = store.getState().user.user;
if (!user) throw new Error("User not logged in");
const votesRef = collection(DB, Collections.votes);
const q = query(votesRef, where("parentId", "==", parentId));

const votersDB = await getDocs(q);
const voters = votersDB.docs.map((vote) => vote.data()) as Vote[];
const votersDB = await getDocs(q);
const voters = votersDB.docs.map((vote) => vote.data()) as Vote[];

return voters;
} catch (error) {
console.error(error);
return voters;
} catch (error) {
console.error(error);

return [] as Vote[];
}
return [] as Vote[];
}
}
Loading

0 comments on commit 32335cf

Please sign in to comment.