From fc8a66aecdeef36bbf0766beb4df442881cc8eeb Mon Sep 17 00:00:00 2001 From: Tal Yaron Date: Thu, 18 Jan 2024 15:23:44 +0200 Subject: [PATCH] ready --- functions/src/helpers.ts | 2 + public/i18n/ar.json | 1 + public/i18n/de.json | 1 + public/i18n/en.json | 1 + public/i18n/es.json | 1 + public/i18n/he.json | 1 + public/i18n/nl.json | 1 + src/App.tsx | 64 ++++++++++--------- src/functions/db/auth.ts | 17 +++-- src/functions/db/statements/setStatments.ts | 2 - src/functions/general/helpers.ts | 1 + src/router.tsx | 12 ++++ src/view/components/icons/ShareIcon.tsx | 2 +- src/view/pages/statement/Statement.tsx | 2 + .../statement/components/admin/AdminPage.tsx | 1 + .../settings/StatementSettings.module.scss | 6 ++ .../components/settings/StatementSettings.tsx | 25 +++++++- .../components/settings/settingsStyle.scss | 1 + 18 files changed, 100 insertions(+), 41 deletions(-) create mode 100644 src/view/pages/statement/components/settings/StatementSettings.module.scss diff --git a/functions/src/helpers.ts b/functions/src/helpers.ts index 3679506f..21fe3c7e 100644 --- a/functions/src/helpers.ts +++ b/functions/src/helpers.ts @@ -1,3 +1,5 @@ + + export function logBase(x: number, b: number) { return Math.log(x) / Math.log(b); } diff --git a/public/i18n/ar.json b/public/i18n/ar.json index fdd5c45b..a111abd3 100644 --- a/public/i18n/ar.json +++ b/public/i18n/ar.json @@ -78,6 +78,7 @@ "Room": "غرفة", "Rooms": "الغرف", "Room Allocation": "تخصيص الغرف", + "Send a link to anonymous users": "إرسال رابط للمستخدمين المجهولين", "Settings": "الإعدادات", "Show division into rooms": "إظهار التقسيم إلى الغرف", "So you can communicate": "حتى تتمكن من التواصل", diff --git a/public/i18n/de.json b/public/i18n/de.json index 38b22098..36edac14 100644 --- a/public/i18n/de.json +++ b/public/i18n/de.json @@ -78,6 +78,7 @@ "Room": "Raum", "Rooms": "Räume", "Room Allocation": "Raumzuweisung", + "Send a link to anonymous users": "Link an anonyme Benutzer senden", "Settings": "Einstellungen", "Show": "Anzeigen", "Show division into rooms": "Raumaufteilung anzeigen", diff --git a/public/i18n/en.json b/public/i18n/en.json index 459beec8..d7e319ef 100644 --- a/public/i18n/en.json +++ b/public/i18n/en.json @@ -78,6 +78,7 @@ "Room": "Room", "Rooms": "Rooms", "Room Allocation": "Room Allocation", + "Send a link to anonymous users": "Send a link to anonymous users", "Settings": "Settings", "Show": "Show", "Show division into rooms": "Show division into rooms", diff --git a/public/i18n/es.json b/public/i18n/es.json index 68f5a7e5..9608e4f4 100644 --- a/public/i18n/es.json +++ b/public/i18n/es.json @@ -77,6 +77,7 @@ "Room": "Sala", "Rooms": "Salas", "Room Allocation": "Asignación de Sala", + "Send a link to anonymous users": "Enviar un enlace a usuarios anónimos", "Settings": "Configuraciones", "Show": "Mostrar", "Show division into rooms": "Mostrar división en salas", diff --git a/public/i18n/he.json b/public/i18n/he.json index df3fdb49..c15aee73 100644 --- a/public/i18n/he.json +++ b/public/i18n/he.json @@ -78,6 +78,7 @@ "Room": "חדר", "Rooms": "חדרים", "Room Allocation": "חלוקה לחדרים", + "Send a link to anonymous users": "שליחת קישור למשתמשים אנונימיים", "Settings": "הגדרות", "Show division into rooms": "הציג/י חלוקה לחדרים", "Show": "הצג ", diff --git a/public/i18n/nl.json b/public/i18n/nl.json index c5c1f635..0efa52fc 100644 --- a/public/i18n/nl.json +++ b/public/i18n/nl.json @@ -77,6 +77,7 @@ "Room": "Kamer", "Rooms": "Kamers", "Room Allocation": "Kamerindeling", + "Send a link to anonymous users": "Stuur een link naar anonieme gebruikers", "Settings": "Instellingen", "Show": "Weergeven", "Show division into rooms": "Toon verdeling in kamers", diff --git a/src/App.tsx b/src/App.tsx index a02253bf..a8bbe446 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from "react"; // Third party imports import { useTranslation } from "react-i18next"; -import { Outlet, useNavigate } from "react-router-dom"; +import { Outlet, useNavigate, useParams } from "react-router-dom"; import { t } from "i18next"; // Firebase functions @@ -38,10 +38,13 @@ export default function App() { const dispatch = useDispatch(); const { i18n } = useTranslation(); const user = useAppSelector(userSelector); + const {anonymous} = useParams(); + + const [showSignAgreement, setShowSignAgreement] = useState(false); const [agreement, setAgreement] = useState(""); - const [visualViewportHeight] = useState(window.visualViewport?.height || 0); + const [visualViewportHeight, setVisualViewportHeight] = useState(window.visualViewport?.height || 0); function updateUserToStore(user: User | null) { dispatch(setUser(user)); @@ -51,9 +54,7 @@ export default function App() { dispatch(setFontSize(fontSize)); } - function navigateToInitialLocationCB(pathname: string) { - navigate(pathname); - } + function resetStoreCB() { dispatch(resetStatements()); @@ -76,9 +77,10 @@ export default function App() { useEffect(() => { const usub: Unsubscribe = listenToAuth( + anonymous === "true" ? true : false, updateUserToStore, updateFonSize, - navigateToInitialLocationCB, + navigate, resetStoreCB, ); @@ -88,31 +90,31 @@ export default function App() { }, []); // 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(() => { + 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", () => {}); + }; + }, []); useEffect(() => { if (!user) { diff --git a/src/functions/db/auth.ts b/src/functions/db/auth.ts index df5a3179..9d920a1f 100644 --- a/src/functions/db/auth.ts +++ b/src/functions/db/auth.ts @@ -14,6 +14,7 @@ import { getIntialLocationSessionStorage, setIntialLocationSessionStorage, } from "../general/helpers"; +import { NavigateFunction } from "react-router-dom"; const provider = new GoogleAuthProvider(); @@ -49,21 +50,29 @@ export function googleLogin() { }); } export function listenToAuth( + isAnonymous: boolean, cb: (user: User | null) => void, fontSizeCB: (fontSize: number) => void, - navigationCB: (path: string) => void, + navigate: NavigateFunction, resetCB: () => void, ): Unsubscribe { return onAuthStateChanged(auth, async (userFB) => { try { - if (!userFB) navigationCB("/"); + if (!userFB && isAnonymous !== true) { + navigate("/"); + } + if (isAnonymous && !userFB){ + + signAnonymously(); + } if (userFB) { // User is signed in const user = { ...userFB }; if (!user.displayName) user.displayName = - localStorage.getItem("displayName") || "anonymous"; + localStorage.getItem("displayName") || `Anonymous ${Math.floor(Math.random() * 10000)}`; const _user = parseUserFromFirebase(user); + // console.info("User is signed in") if (!_user) throw new Error("user is undefined"); @@ -82,7 +91,7 @@ export function listenToAuth( const initialLocation = getIntialLocationSessionStorage(); //navigate to initial location - if (initialLocation) navigationCB(initialLocation); + if (initialLocation) navigate(initialLocation); } else { // User is signed out console.info("User is signed out"); diff --git a/src/functions/db/statements/setStatments.ts b/src/functions/db/statements/setStatments.ts index 48a3f939..7d1677a3 100644 --- a/src/functions/db/statements/setStatments.ts +++ b/src/functions/db/statements/setStatments.ts @@ -112,8 +112,6 @@ export const setStatmentToDB = async ({ ), ); - // statementPromises.push(getUserPermissionToNotifications()); - // const [, , canGetNotifications] = await Promise.all(statementPromises); diff --git a/src/functions/general/helpers.ts b/src/functions/general/helpers.ts index a108e8fc..7f28dd86 100644 --- a/src/functions/general/helpers.ts +++ b/src/functions/general/helpers.ts @@ -289,3 +289,4 @@ export function parseScreensCheckBoxes(dataObj: dataObj): Screen[] { return [Screen.CHAT, Screen.OPTIONS, Screen.VOTE]; } } + diff --git a/src/router.tsx b/src/router.tsx index 59342442..8b807df6 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -59,6 +59,18 @@ export const router = createBrowserRouter([ }, ], }, + { + path: "statement-an/:anonymous/:statementId/:page", + element: , + errorElement: , + children: [ + { + path: ":sort", + element: , + errorElement: , + }, + ], + } ], }, { diff --git a/src/view/components/icons/ShareIcon.tsx b/src/view/components/icons/ShareIcon.tsx index 0ead59d5..4457f32e 100644 --- a/src/view/components/icons/ShareIcon.tsx +++ b/src/view/components/icons/ShareIcon.tsx @@ -1,4 +1,4 @@ -export default function ShareIcon({ color }: { color: string }) { +export default function ShareIcon({ color = "blue" }: { color?: string}) { return ( { // Hooks const { statementId } = useParams(); + const page = useParams().page as Screen; const navigate = useNavigate(); @@ -126,6 +127,7 @@ const Statement: FC = () => { useEffect(() => { if (statement) { + const { shortVersion } = statementTitleToDisplay( statement.statement, 100, diff --git a/src/view/pages/statement/components/admin/AdminPage.tsx b/src/view/pages/statement/components/admin/AdminPage.tsx index b696b7a9..dc32870d 100644 --- a/src/view/pages/statement/components/admin/AdminPage.tsx +++ b/src/view/pages/statement/components/admin/AdminPage.tsx @@ -15,6 +15,7 @@ const AdminPage = () => {
+

dfsdf dssdf sdf sdf

= () => { } } + function handleShare( ) { + const baseUrl = window.location.origin; + + const shareData = { + title: t ("Delib: We create agreements together"), + text: t("Invited:") + statement?.statement, + url: `${baseUrl}/statement-an/true/${statement?.statementId}/options`, + }; + navigator.share(shareData); + } + + const arrayOfStatementParagrphs = statement?.statement.split("\n") || []; //get all elements of the array except the first one @@ -230,7 +242,14 @@ const StatementSettings: FC = () => { {membership && statementId && ( <> +

{t("Members in Group")}

+ +
+ {t("Send a link to anonymous users")} + +
+
{membership.map((member) => (