From e62ef8695b06593f2ccadc5530a7b88520e948e7 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Wed, 8 May 2024 16:50:25 +0200 Subject: [PATCH] Added biome for formatting, code formatted --- frontend/app.json | 60 +++--- frontend/app/(app)/_layout.js | 28 +-- frontend/app/(app)/index.js | 30 +-- frontend/app/_layout.js | 12 +- frontend/app/context/AuthContext.js | 218 ++++++++++---------- frontend/app/context/storage.js | 54 ++--- frontend/app/hooks/useIsAutheticated.js | 4 +- frontend/app/login.js | 198 +++++++++--------- frontend/app/signup.js | 258 ++++++++++++------------ frontend/babel.config.js | 10 +- frontend/biome.json | 15 ++ frontend/components/Button.js | 66 +++--- frontend/components/style.js | 14 +- frontend/package-lock.json | 158 ++++++++++++++- frontend/package.json | 63 +++--- 15 files changed, 678 insertions(+), 510 deletions(-) create mode 100644 frontend/biome.json diff --git a/frontend/app.json b/frontend/app.json index 1ace0dd..433b24a 100644 --- a/frontend/app.json +++ b/frontend/app.json @@ -1,34 +1,30 @@ { - "expo": { - "name": "deguapp", - "slug": "deguapp", - "scheme": "deguapp", - "version": "1.0.0", - "orientation": "portrait", - "icon": "./assets/icon.png", - "userInterfaceStyle": "light", - "splash": { - "image": "./assets/splash.png", - "resizeMode": "contain", - "backgroundColor": "#ffffff" - }, - "assetBundlePatterns": [ - "**/*" - ], - "ios": { - "supportsTablet": true - }, - "android": { - "adaptiveIcon": { - "foregroundImage": "./assets/adaptive-icon.png", - "backgroundColor": "#ffffff" - } - }, - "web": { - "favicon": "./assets/favicon.png" - }, - "plugins": [ - "expo-router" - ] - } + "expo": { + "name": "deguapp", + "slug": "deguapp", + "scheme": "deguapp", + "version": "1.0.0", + "orientation": "portrait", + "icon": "./assets/icon.png", + "userInterfaceStyle": "light", + "splash": { + "image": "./assets/splash.png", + "resizeMode": "contain", + "backgroundColor": "#ffffff" + }, + "assetBundlePatterns": ["**/*"], + "ios": { + "supportsTablet": true + }, + "android": { + "adaptiveIcon": { + "foregroundImage": "./assets/adaptive-icon.png", + "backgroundColor": "#ffffff" + } + }, + "web": { + "favicon": "./assets/favicon.png" + }, + "plugins": ["expo-router"] + } } diff --git a/frontend/app/(app)/_layout.js b/frontend/app/(app)/_layout.js index 672ca02..2e9b476 100644 --- a/frontend/app/(app)/_layout.js +++ b/frontend/app/(app)/_layout.js @@ -4,19 +4,19 @@ import { useAuth } from "../context/AuthContext"; import { View, Text } from "react-native"; export default function AppLayout() { - const { authState } = useAuth(); + const { authState } = useAuth(); - if (authState.authenticated === null) { - // micro loading co neni skoro videt ale get the fuck out se uz neloguje - return ( - - Loading... - - ); - } - if (!authState.authenticated) { - console.log("get the fuck out"); - return ; - } - return ; + if (authState.authenticated === null) { + // micro loading co neni skoro videt ale get the fuck out se uz neloguje + return ( + + Loading... + + ); + } + if (!authState.authenticated) { + console.log("get the fuck out"); + return ; + } + return ; } diff --git a/frontend/app/(app)/index.js b/frontend/app/(app)/index.js index 98fe6cc..d032440 100644 --- a/frontend/app/(app)/index.js +++ b/frontend/app/(app)/index.js @@ -3,21 +3,21 @@ import { Text, View } from "react-native"; import { useAuth } from "../context/AuthContext"; export default function Index() { - const { onLogout, authState } = useAuth(); + const { onLogout, authState } = useAuth(); - const user = authState.user; + const user = authState.user; - return ( - - Welcome {user.username} - { - // The `app/(app)/_layout.tsx` will redirect to the sign-in screen. - onLogout(); - }} - > - Sign Out - - - ); + return ( + + Welcome {user.username} + { + // The `app/(app)/_layout.tsx` will redirect to the sign-in screen. + onLogout(); + }} + > + Sign Out + + + ); } diff --git a/frontend/app/_layout.js b/frontend/app/_layout.js index 18f23a4..60387a1 100644 --- a/frontend/app/_layout.js +++ b/frontend/app/_layout.js @@ -3,10 +3,10 @@ import { StatusBar } from "expo-status-bar"; import { AuthProvider } from "./context/AuthContext"; export default function Root() { - return ( - - - - - ); + return ( + + + + + ); } diff --git a/frontend/app/context/AuthContext.js b/frontend/app/context/AuthContext.js index f5d202e..1a08b36 100644 --- a/frontend/app/context/AuthContext.js +++ b/frontend/app/context/AuthContext.js @@ -6,134 +6,134 @@ export const API_URL = "http://10.69.1.137:6060/api/v1"; const AuthContext = createContext(null); export function useAuth() { - const authContext = useContext(AuthContext); - if (authContext === undefined) { - throw new Error("Context is outside of provider"); - } - return authContext; + const authContext = useContext(AuthContext); + if (authContext === undefined) { + throw new Error("Context is outside of provider"); + } + return authContext; } export function AuthProvider({ children }) { - const [authState, setAuthState] = useState({ - token: null, - authenticated: null, - }); + const [authState, setAuthState] = useState({ + token: null, + authenticated: null, + }); - useEffect(() => { - // tohle se zavola jen poprve pri startu appky - async function loadToken() { - const token = await storageUtil.getItem(TOKEN_KEY); - console.log(`stored: ${token}`); + useEffect(() => { + // tohle se zavola jen poprve pri startu appky + async function loadToken() { + const token = await storageUtil.getItem(TOKEN_KEY); + console.log(`stored: ${token}`); - const resUser = await fetch(`${API_URL}/auth/status`, { - credentials: "include", - }); + const resUser = await fetch(`${API_URL}/auth/status`, { + credentials: "include", + }); - const userData = await resUser.json(); + const userData = await resUser.json(); - if (token && resUser.status == 200) { - setAuthState({ - token: token, - authenticated: true, - user: userData.data, - }); + if (token && resUser.status == 200) { + setAuthState({ + token: token, + authenticated: true, + user: userData.data, + }); - return; - } - setAuthState({ - authenticated: false, - token: null, - user: null, - }); - } - loadToken(); - }, []); + return; + } + setAuthState({ + authenticated: false, + token: null, + user: null, + }); + } + loadToken(); + }, []); - async function register(username, email, password) { - try { - const res = await fetch(`${API_URL}/auth/signup`, { - method: 'POST', - credentials: 'include', - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify({ - username, - email, - password - }) - }) - return res; - } catch (err) { - return { error: true, msg: err.response.data }; - } - } + async function register(username, email, password) { + try { + const res = await fetch(`${API_URL}/auth/signup`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + username, + email, + password, + }), + }); + return res; + } catch (err) { + return { error: true, msg: err.response.data }; + } + } - async function login(email, password) { - try { - const resLogin = await fetch(`${API_URL}/auth/signin`, { - method: "POST", - credentials: "include", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - email, - password, - }), - }); + async function login(email, password) { + try { + const resLogin = await fetch(`${API_URL}/auth/signin`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + email, + password, + }), + }); - const loginData = await resLogin.json(); + const loginData = await resLogin.json(); - const resUser = await fetch(`${API_URL}/auth/status`, { - credentials: "include", - }); + const resUser = await fetch(`${API_URL}/auth/status`, { + credentials: "include", + }); - if (resUser.status != 200) { - throw Error("user does not have user data"); - } + if (resUser.status != 200) { + throw Error("user does not have user data"); + } - const userData = await resUser.json(); + const userData = await resUser.json(); - setAuthState({ - token: loginData.data.jwt, - authenticated: true, - user: userData.data, - }); + setAuthState({ + token: loginData.data.jwt, + authenticated: true, + user: userData.data, + }); - await storageUtil.setItem(TOKEN_KEY, loginData.data.jwt); - } catch (err) { - console.error("Failed to log in", err) - return { error: true, msg: err.res }; - } - } + await storageUtil.setItem(TOKEN_KEY, loginData.data.jwt); + } catch (err) { + console.error("Failed to log in", err); + return { error: true, msg: err.res }; + } + } - async function logout() { - let res = await fetch(`${API_URL}/auth/logout`, { - method: "POST", - credentials: "include", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }); - res = await res.json(); + async function logout() { + let res = await fetch(`${API_URL}/auth/logout`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({}), + }); + res = await res.json(); - await storageUtil.delItem(TOKEN_KEY); + await storageUtil.delItem(TOKEN_KEY); - setAuthState({ - token: null, - authenticated: false, - user: null, - }); - } + setAuthState({ + token: null, + authenticated: false, + user: null, + }); + } - const value = { - onSignin: register, - onLogin: login, - onLogout: logout, - authState, - }; + const value = { + onSignin: register, + onLogin: login, + onLogout: logout, + authState, + }; - return {children}; + return {children}; } diff --git a/frontend/app/context/storage.js b/frontend/app/context/storage.js index a55e8d0..501ab6b 100644 --- a/frontend/app/context/storage.js +++ b/frontend/app/context/storage.js @@ -3,32 +3,32 @@ import { Platform } from "react-native"; import AsyncStorage from "@react-native-async-storage/async-storage"; const storageUtil = { - setItem: async (k, v) => { - if (Platform.OS === "web") { - // web - await AsyncStorage.setItem(k, v); - } else { - // mobile - await SecureStore.setItemAsync(k, v.toString()); // v must be string, - } - }, - getItem: async (k) => { - if (Platform.OS === "web") { - // web - return await AsyncStorage.getItem(k); - } else { - // mobile - return await SecureStore.getItemAsync(k); - } - }, - delItem: async (k) => { - if (Platform.OS === "web") { - // web - await AsyncStorage.removeItem(k); - } else { - // mobile - await SecureStore.deleteItemAsync(k); - } - }, + setItem: async (k, v) => { + if (Platform.OS === "web") { + // web + await AsyncStorage.setItem(k, v); + } else { + // mobile + await SecureStore.setItemAsync(k, v.toString()); // v must be string, + } + }, + getItem: async (k) => { + if (Platform.OS === "web") { + // web + return await AsyncStorage.getItem(k); + } else { + // mobile + return await SecureStore.getItemAsync(k); + } + }, + delItem: async (k) => { + if (Platform.OS === "web") { + // web + await AsyncStorage.removeItem(k); + } else { + // mobile + await SecureStore.deleteItemAsync(k); + } + }, }; export default storageUtil; diff --git a/frontend/app/hooks/useIsAutheticated.js b/frontend/app/hooks/useIsAutheticated.js index 99c8cec..760b1e5 100644 --- a/frontend/app/hooks/useIsAutheticated.js +++ b/frontend/app/hooks/useIsAutheticated.js @@ -1,6 +1,6 @@ import { useAuth } from "../context/AuthContext"; export function useIsAutheticated() { - const { authState } = useAuth(); - return authState.authenticated + const { authState } = useAuth(); + return authState.authenticated; } diff --git a/frontend/app/login.js b/frontend/app/login.js index 2f0622d..e8ac95e 100644 --- a/frontend/app/login.js +++ b/frontend/app/login.js @@ -7,111 +7,111 @@ import { colors } from "../components/style"; import { useAuth } from "./context/AuthContext"; function LoginPage() { - const [pass, setPass] = useState(""); - const [email, setEmail] = useState(""); - const { onLogin, authState } = useAuth(); + const [pass, setPass] = useState(""); + const [email, setEmail] = useState(""); + const { onLogin, authState } = useAuth(); - useEffect(() => { - if (authState.authenticated) { - router.replace("/"); - } - }, [authState.authenticated]); + useEffect(() => { + if (authState.authenticated) { + router.replace("/"); + } + }, [authState.authenticated]); - function login() { - onLogin(email, pass); - } + function login() { + onLogin(email, pass); + } - return ( - - - - Please Log In - - - setEmail(text)} - /> - setPass(text)} - /> - -