From 92e439892d8e58f4bcc5d60c6cde9d334edd5853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Sun, 9 Apr 2023 00:13:50 +0200 Subject: [PATCH] fix various style issues and implemented the mechanics to allow guest creation --- front/views/StartPageView.tsx | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/front/views/StartPageView.tsx b/front/views/StartPageView.tsx index 827bb21..23420e4 100644 --- a/front/views/StartPageView.tsx +++ b/front/views/StartPageView.tsx @@ -5,7 +5,7 @@ import { Text, Stack, Box, - Button, + useToast, AspectRatio, Column, useBreakpointValue, @@ -18,6 +18,18 @@ import { } from "native-base"; import { FontAwesome5 } from "@expo/vector-icons"; import BigActionButton from "../components/BigActionButton"; +import API, { APIError } from "../API"; +import { setAccessToken } from "../state/UserSlice"; +import { useDispatch } from "../state/Store"; +import { translate } from "../i18n/i18n"; + +const handleGuestLogin = async ( + apiSetter: (accessToken: string) => void +): Promise => { + const apiAccess = await API.createAndGetGuestAccount(); + apiSetter(apiAccess); + return translate("loggedIn"); +}; const imgLogin = "https://imgs.search.brave.com/xX-jA3Rspi-ptSFABle5hpVNdOyKDHdVYNr320buGyQ/rs:fit:1200:800:1/g:ce/aHR0cDovL3d3dy5z/dHJhdGVnaWMtYnVy/ZWF1LmNvbS93cC1j/b250ZW50L3VwbG9h/ZHMvMjAxNC8wNy9B/TVgtMTBSQ1ItMTAw/LVNCSS1EUy5qcGc"; @@ -36,6 +48,9 @@ const StartPageView = () => { const navigate = useNavigation(); const screenSize = useBreakpointValue({ base: "small", md: "big" }); const isSmallScreen = screenSize === "small"; + const dispatch = useDispatch(); + const toast = useToast(); + return ( { image={imgGuest} iconName="user-clock" iconProvider={FontAwesome5} - onPress={() => navigation.navigate("Guest")} + onPress={() => { + try { + handleGuestLogin((accessToken: string) => { + dispatch(setAccessToken(accessToken)); + }); + } catch (error) { + if (error instanceof APIError) { + toast.show({ description: translate(error.userMessage) }); + return; + } + toast.show({ description: error as string }); + } + }} style={{ width: isSmallScreen ? "90%" : "clamp(100px, 33.3%, 600px)", height: "300px", @@ -160,10 +187,7 @@ const StartPageView = () => { borderRadius: 10, }} > - +