From a79b311ee48d2f84e2545ffe64caf6f7d8c68ddd Mon Sep 17 00:00:00 2001 From: Sverre <59171289+sverben@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:11:27 +0200 Subject: [PATCH] fix: random demo mode entry (#11) --- app.json | 6 +++--- package.json | 2 +- src/auth.tsx | 3 +++ src/components/feed/feed.tsx | 32 +++++------------------------ src/components/register/listing.tsx | 31 +++------------------------- src/screens/feed/feed.tsx | 21 +++++++++++++++---- 6 files changed, 32 insertions(+), 63 deletions(-) diff --git a/app.json b/app.json index 750c82d..96e664d 100644 --- a/app.json +++ b/app.json @@ -3,7 +3,7 @@ "name": "djo", "slug": "djo", "scheme": "djo", - "version": "1.4.0", + "version": "1.4.1", "orientation": "portrait", "icon": "./assets/icon.png", "userInterfaceStyle": "automatic", @@ -16,7 +16,7 @@ "**/*" ], "ios": { - "buildNumber": "3", + "buildNumber": "1", "userInterfaceStyle": "automatic", "supportsTablet": false, "bundleIdentifier": "nl.djoamersfoort.djo", @@ -44,7 +44,7 @@ } }, "googleServicesFile": "./google-services.json", - "versionCode": 11 + "versionCode": 12 }, "web": { "favicon": "./assets/favicon.png" diff --git a/package.json b/package.json index a434dff..7e4fca1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "djo", - "version": "1.4.0", + "version": "1.4.1", "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", diff --git a/src/auth.tsx b/src/auth.tsx index e40f49d..1f09555 100644 --- a/src/auth.tsx +++ b/src/auth.tsx @@ -10,6 +10,7 @@ import * as Device from "expo-device"; import * as Notifications from "expo-notifications"; import Constants from "expo-constants"; import { CLIENT_ID, LEDEN_ADMIN, SCOPES } from "./env"; +import logging from "./logging"; const redirectUri = AuthSession.makeRedirectUri({ path: "redirect" }); WebBrowser.maybeCompleteAuthSession(); @@ -131,6 +132,7 @@ function createAuthState( return new Promise(async (resolve) => { if (expiry > Date.now()) return resolve(token); + logging.log("AUTH", "Refreshing tokens"); const tokens: TokenResponse = await fetch(discovery?.tokenEndpoint!, { method: "post", headers: { @@ -153,6 +155,7 @@ function createAuthState( await SecureStore.setItemAsync("refresh_token", refresh); } + logging.log("AUTH", "Finished refreshing tokens"); resolve(token); }); }, diff --git a/src/components/feed/feed.tsx b/src/components/feed/feed.tsx index 5242c76..305578e 100644 --- a/src/components/feed/feed.tsx +++ b/src/components/feed/feed.tsx @@ -1,34 +1,12 @@ -import { useContext, useEffect } from "react"; -import AuthContext, { Authed } from "../../auth"; -import { useAtom } from "jotai"; -import { - feedAtom, - getAnnouncements, - getRSSFeed, - sortFeeds, -} from "../../stores/feed"; +import { useContext } from "react"; +import AuthContext from "../../auth"; +import { useAtomValue } from "jotai"; +import { feedAtom } from "../../stores/feed"; import { ActivityIndicator, Card } from "react-native-paper"; import Item from "./item"; export default function Feed() { - const authState = useContext(AuthContext); - const [feed, setFeed] = useAtom(feedAtom); - - useEffect(() => { - async function getFeeds() { - const feeds = await Promise.all([ - getRSSFeed(), - getAnnouncements( - authState.authenticated === Authed.AUTHENTICATED - ? await authState.token - : null, - ), - ]); - setFeed(sortFeeds(...feeds)); - } - - getFeeds().then(); - }, [authState]); + const feed = useAtomValue(feedAtom); return ( diff --git a/src/components/register/listing.tsx b/src/components/register/listing.tsx index d6872c9..b1ed5ad 100644 --- a/src/components/register/listing.tsx +++ b/src/components/register/listing.tsx @@ -1,7 +1,5 @@ -import { useContext, useEffect } from "react"; -import AuthContext, { Authed } from "../../auth"; -import { useAtom } from "jotai"; -import { getSlots, membersAtom, Slot, slotsAtom } from "../../stores/register"; +import { useAtomValue } from "jotai"; +import { Slot, slotsAtom } from "../../stores/register"; import { ActivityIndicator, Avatar, @@ -12,7 +10,6 @@ import { StyleSheet, TouchableOpacity } from "react-native"; import { useNavigation } from "@react-navigation/native"; import { NativeStackNavigationProp } from "react-native-screens/native-stack"; import { StackParamList } from "../../../App"; -import logging from "../../logging"; type SlotNavigationProps = NativeStackNavigationProp; @@ -38,29 +35,7 @@ function SlotListing({ slot, index }: { slot: Slot; index: number }) { } export default function Listing() { - const authState = useContext(AuthContext); - const [slots, setSlots] = useAtom(slotsAtom); - const [_members, setMembers] = useAtom(membersAtom); - - useEffect(() => { - async function fetchDays() { - const token = - authState.authenticated === Authed.AUTHENTICATED - ? await authState.token - : null; - - logging.log( - "REGISTER", - `Fetching initial register data with auth state ${authState.authenticated}, token is ${token ? "defined" : "undefined"}`, - ); - const { slots, members } = await getSlots(token); - - setSlots(slots); - setMembers(members || []); - } - - fetchDays().then(); - }, [authState]); + const slots = useAtomValue(slotsAtom); return ( diff --git a/src/screens/feed/feed.tsx b/src/screens/feed/feed.tsx index 01475ab..2c59a46 100644 --- a/src/screens/feed/feed.tsx +++ b/src/screens/feed/feed.tsx @@ -2,7 +2,7 @@ import { Appbar } from "react-native-paper"; import { RefreshControl, ScrollView, StyleSheet, View } from "react-native"; import Listing from "../../components/register/listing"; import Feed from "../../components/feed/feed"; -import { useContext, useState } from "react"; +import { useContext, useEffect, useState } from "react"; import { useAtom } from "jotai"; import { feedAtom, @@ -28,20 +28,20 @@ export default function FeedScreen() { const [_slots, setSlots] = useAtom(slotsAtom); const [_members, setMembers] = useAtom(membersAtom); - async function refresh() { - setRefreshing(true); + async function loadData() { const token = authState.authenticated === Authed.AUTHENTICATED ? await authState.token : null; logging.log( "FEED", - `Refreshing feed with auth state ${authState.authenticated}, token is ${token ? "defined" : "undefined"}`, + `Auth state ${authState.authenticated}, token is ${token ? "defined" : "undefined"}`, ); await Promise.all([ new Promise(async (resolve) => { setSlots(null); + const { slots, members } = await getSlots(token); setSlots(slots); setMembers(members || []); @@ -58,6 +58,19 @@ export default function FeedScreen() { resolve(); }), ]); + } + + useEffect(() => { + logging.log("FEED", "Loading initial data"); + + loadData().then(); + }, []); + + async function refresh() { + logging.log("FEED", "Refreshing feed"); + + setRefreshing(true); + await loadData(); setRefreshing(false); }