Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: random demo mode entry #11

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -16,7 +16,7 @@
"**/*"
],
"ios": {
"buildNumber": "3",
"buildNumber": "1",
"userInterfaceStyle": "automatic",
"supportsTablet": false,
"bundleIdentifier": "nl.djoamersfoort.djo",
Expand Down Expand Up @@ -44,7 +44,7 @@
}
},
"googleServicesFile": "./google-services.json",
"versionCode": 11
"versionCode": 12
},
"web": {
"favicon": "./assets/favicon.png"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "djo",
"version": "1.4.0",
"version": "1.4.1",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
Expand Down
3 changes: 3 additions & 0 deletions src/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -131,6 +132,7 @@ function createAuthState(
return new Promise<string>(async (resolve) => {
if (expiry > Date.now()) return resolve(token);

logging.log("AUTH", "Refreshing tokens");
const tokens: TokenResponse = await fetch(discovery?.tokenEndpoint!, {
method: "post",
headers: {
Expand All @@ -153,6 +155,7 @@ function createAuthState(
await SecureStore.setItemAsync("refresh_token", refresh);
}

logging.log("AUTH", "Finished refreshing tokens");
resolve(token);
});
},
Expand Down
32 changes: 5 additions & 27 deletions src/components/feed/feed.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Card>
Expand Down
31 changes: 3 additions & 28 deletions src/components/register/listing.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<StackParamList>;

Expand All @@ -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 (
<Card>
Expand Down
21 changes: 17 additions & 4 deletions src/screens/feed/feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<void>(async (resolve) => {
setSlots(null);

const { slots, members } = await getSlots(token);
setSlots(slots);
setMembers(members || []);
Expand All @@ -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);
}

Expand Down
Loading