Skip to content

Commit

Permalink
corrections pour ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
luclu7 committed Jul 28, 2024
1 parent e2318ab commit af40d18
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 42 deletions.
1 change: 1 addition & 0 deletions web/src/components/MapLibreMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const MapLibreMap: FC<{ onStandClick: (standId: string) => void }> = ({
console.log(map);
return () => map.remove();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [onStandClick]);

return (
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import clsx from "clsx";
import { useTranslation } from "react-i18next";
import { FC, MouseEventHandler, ReactNode } from "react";
import { Dices, Home, Map, QrCode, QrCodeIcon, UsersRound } from "lucide-react";
import { useQRDrawerContext } from "@/context/QRDrawerContext.tsx";
import { useQRDrawerContext } from "@/context/useQRDrawerContext";
import { useUser } from "@/lib/hooks/useUser.ts";

const Navbar = ({ children }: { children: ReactNode }) => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/QRCodeDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { retrieveHashFromQRCode } from "@/lib/StampQRCodes.ts";
import QrReader from "@/components/QrReader.tsx";
import { useNavigate } from "@tanstack/react-router";
import { useQRDrawerContext } from "@/context/QRDrawerContext.tsx";
import { useQRDrawerContext } from "@/context/useQRDrawerContext";
import { useTranslation } from "react-i18next";

export const QRCodeDrawer = () => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/QRCodeLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ButtonLink } from "./ButtonLink.tsx";
import { useTranslation } from "react-i18next";
import { useQRDrawerContext } from "@/context/QRDrawerContext.tsx";
import { useQRDrawerContext } from "@/context/useQRDrawerContext";

const QRCodeLink = () => {
const [, setQRCodeDrawerOpen] = useQRDrawerContext();
Expand Down
15 changes: 6 additions & 9 deletions web/src/components/QrReader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const QrReader = ({ onScanSuccess, onCameraAccessFail }: QrReaderProps) => {
};

useEffect(() => {
if (videoEl?.current && !scanner.current) {
const currentVideoEl = videoEl.current;
if (currentVideoEl && !scanner.current) {
scanner.current = new QrScanner(
videoEl?.current,
(result) => {
Expand All @@ -46,20 +47,16 @@ const QrReader = ({ onScanSuccess, onCameraAccessFail }: QrReaderProps) => {
}

return () => {
if (!videoEl?.current) {
if (!currentVideoEl) {
scanner?.current?.stop();
}
};
}, []);
}, [onScanSuccess]);

// ❌ If "camera" is not allowed in browser permissions, show an alert.
useEffect(() => {
if (!qrOn)
alert(
"Camera is blocked or not accessible. Please allow camera in your browser permissions and Reload.",
);
onCameraAccessFail();
}, [qrOn]);
if (!qrOn) onCameraAccessFail();
}, [qrOn, onCameraAccessFail]);

return (
<div className="h-[450px] w-[450px] max-w-full max-h-[50svh] flex-grow">
Expand Down
4 changes: 1 addition & 3 deletions web/src/context/QRDrawerContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { createContext, Dispatch, SetStateAction, useContext } from "react";
import { createContext, Dispatch, SetStateAction } from "react";

export const QRDrawerContext = createContext<
[boolean, Dispatch<SetStateAction<boolean>>]
>([false, () => {}] as const);

export const useQRDrawerContext = () => useContext(QRDrawerContext);
4 changes: 4 additions & 0 deletions web/src/context/useQRDrawerContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { useContext } from "react";
import { QRDrawerContext } from "@/context/QRDrawerContext.tsx";

export const useQRDrawerContext = () => useContext(QRDrawerContext);
56 changes: 29 additions & 27 deletions web/src/lib/userContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,6 @@ export function UserProvider({
Models.User<Models.Preferences> | null | undefined
>(NOT_INITIALIZED);

async function init() {
console.log("registerAutoAnonymous", registerAutoAnonymous);
try {
const loggedIn = await account.get();
console.log("logged in", loggedIn);
setUser(loggedIn);
} catch (err) {
if (err instanceof AppwriteException) {
console.log(err.code, err.type, err.response, err.message);

// si l'erreur est de type "general_unauthorized_scope" et que registerAutoAnonymous est true
// cela signifie qu'on est pas connecté et qu'on doit se connecter en tant qu'utilisateur anonyme
if (err.type == "general_unauthorized_scope" && registerAutoAnonymous) {
// register anonymous user
await loginAnonymous();
const user = await account.get();
setUser(user);
return;
}
}

console.error(err);
setUser(null);
}
}

const loginUser = async (email: string, password: string) => {
try {
const session = await login(email, password);
Expand Down Expand Up @@ -159,8 +133,36 @@ export function UserProvider({
} satisfies UserContextType;

useEffect(() => {
async function init() {
try {
const loggedIn = await account.get();
console.log("logged in", loggedIn);
setUser(loggedIn);
} catch (err) {
if (err instanceof AppwriteException) {
console.log(err.code, err.type, err.response, err.message);

// si l'erreur est de type "general_unauthorized_scope" et que registerAutoAnonymous est true
// cela signifie qu'on est pas connecté et qu'on doit se connecter en tant qu'utilisateur anonyme
if (
err.type == "general_unauthorized_scope" &&
registerAutoAnonymous
) {
// register anonymous user
await loginAnonymous();
const user = await account.get();
setUser(user);
return;
}
}

console.error(err);
setUser(null);
}
}

init();
}, []);
}, [registerAutoAnonymous]);

return (
<UserContext.Provider value={contextData}>
Expand Down

0 comments on commit af40d18

Please sign in to comment.