Skip to content

Commit

Permalink
Merge pull request #202 from kilowatts-io/197-eas-update-does-not-run…
Browse files Browse the repository at this point in the history
…-on-production-branch

Eas Update Revision
  • Loading branch information
BenjaminWatts authored Feb 22, 2024
2 parents f9be2aa + 1bc70c0 commit 07eabb3
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 56 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/expo-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: update

on:
push:
branches:
- preview # This specifies that the workflow should only run on pushes to the production branch.

jobs:
update:
name: EAS Update
runs-on: ubuntu-latest
steps:
- name: Check for EXPO_TOKEN
run: |
if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then
echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets. Learn more: https://docs.expo.dev/eas-update/github-actions"
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: yarn

- name: Setup EAS
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}

- name: Install dependencies
run: yarn install

- name: Publish update
run: eas update --auto --channel preview
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const styles = StyleSheet.create({
display: "flex",
flexDirection: "row",
gap: 10,
height: 35,
height: 40,
justifyContent: "flex-start",
padding: 5
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,45 @@ import { Text } from "@rneui/themed";

import { useGbSummaryOutputQuery } from "../../../../../state/apis/cloudfront/api";
import { londonTimeHHMMSS } from "../../../../../utils/dateTime";
import VersionInfo from "../../../version-info";
import { GbLiveListItemBalancingTotal } from "../../live-list-item/live-list-item";

export const GbBalancingTotals = () => {
const { data } = useGbSummaryOutputQuery(undefined, {
pollingInterval: 1000 * 15
});

if (!data) return null;

return (
<>
<View style={styles.totals}>
{data && (
<>
<GbLiveListItemBalancingTotal
name="Total Bid Acceptances"
balancingVolume={data && -data.balancing_totals.bids}
/>
<GbLiveListItemBalancingTotal
name="Total Offer Acceptances"
balancingVolume={data && data.balancing_totals.offers}
/>
<View style={styles.totals}>
<>
<GbLiveListItemBalancingTotal
name="Total Bid Acceptances"
balancingVolume={data && -data.balancing_totals.bids}
/>
<GbLiveListItemBalancingTotal
name="Total Offer Acceptances"
balancingVolume={data && data.balancing_totals.offers}
/>
</>
</View>
<View style={styles.center}>
<Text>
{data && `Valid for ${londonTimeHHMMSS(new Date(data.dt))}`}
</Text>
</View>
</>
</View>
<View style={styles.center}>
<Text>
{data && `Valid for ${londonTimeHHMMSS(new Date(data.dt))}`}
</Text>
</View>
)}
<VersionInfo />
</>
);
};

const styles = StyleSheet.create({
center: {
alignItems: "center",
paddingTop: 15
paddingTop: 50
},
totals: {
paddingTop: 15
Expand Down
19 changes: 14 additions & 5 deletions components/gb-live/bottom-sheet-tabs/totals-list/totals-list.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import React from "react";
import { FlatList } from "react-native";
import { FlatList, StyleSheet, View } from "react-native";
import { Button, Card, Icon, Text } from "@rneui/themed";

import { useGbSummaryOutputQuery } from "../../../../state/apis/cloudfront/api";
import {
calculateBalancingDirection,
calculateCapacityFactor,
calculateCycleSeconds
} from "../../../../state/utils";
import { ErrorDataRetryCard } from "../../error-data-retry-card";
import { GbLiveListItem } from "../live-list-item/live-list-item";

import { GbBalancingTotals } from "./balancing-totals/balancing-totals";

const capitalise = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);

export const GbTotalsList: React.FC = () => {
const { data, isLoading, refetch } = useGbSummaryOutputQuery(undefined, {
pollingInterval: 1000 * 15,
refetchOnReconnect: true
});
const { data, isLoading, refetch, isError } = useGbSummaryOutputQuery(
undefined,
{
pollingInterval: 1000 * 15,
refetchOnReconnect: true
}
);

if (isError && !data) {
return <ErrorDataRetryCard refetch={refetch} />;
}

return (
<FlatList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ import {
calculateCapacityFactor,
calculateCycleSeconds
} from "../../../../state/utils";
import { ErrorDataRetryCard } from "../../error-data-retry-card";
import { GbLiveListItem } from "../live-list-item/live-list-item";

import Pagination from "./pagination";

const WEB_PAGE_SIZE = 15;

export const GbUnitGroupsList: React.FC = () => {
const { data, isLoading, refetch } = useGbSummaryOutputQuery(undefined, {
pollingInterval: 1000 * 15,
refetchOnReconnect: true
});
const { data, isLoading, refetch, isError } = useGbSummaryOutputQuery(
undefined,
{
pollingInterval: 1000 * 15,
refetchOnReconnect: true
}
);
const [webPage, setWebPage] = React.useState(0);
const list = React.useRef<FlashList<{ GbSummaryOutputGenerator }>>(null);

Expand All @@ -49,6 +53,10 @@ export const GbUnitGroupsList: React.FC = () => {
}
}, [data, webPage]);

if (isError && !data) {
return <ErrorDataRetryCard refetch={refetch} />;
}

return (
<FlashList
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
41 changes: 41 additions & 0 deletions components/gb-live/error-data-retry-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";
import { View } from "react-native";
import { StyleSheet } from "react-native";
import { Button, Card, Icon, Text } from "@rneui/themed";

interface ErrorDataRetryCardProps {
refetch: () => void;
}
export const ErrorDataRetryCard: React.FC<ErrorDataRetryCardProps> = (p) => {
return (
<Card>
<Card.Title>Error</Card.Title>
<View style={styles.spaced}>
<Text>
Failed to load data from the internet. Check your internet connection
and try again.
</Text>
</View>
<Button
// title="Retry"
onPress={() => p.refetch()}
iconPosition="right"
icon={
<Icon
name="refresh"
type="material"
size={15}
color="white"
/>
}
/>
</Card>
);
};

const styles = StyleSheet.create({
spaced: {
paddingBottom: 20,
paddingTop: 20
}
});
31 changes: 31 additions & 0 deletions components/gb-live/version-info.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// text compoment which renders version information from expo-updates
import React from "react";
import { StyleSheet, View } from "react-native";
import { Text } from "@rneui/themed";
import * as Updates from "expo-updates";

const VersionInfo: React.FC = () => {
if (__DEV__) {
return (
<View style={styles.view}>
<Text>Development Mode</Text>
</View>
);
}

return (
<View style={styles.view}>
<Text>
{`Release ${Updates.releaseChannel} v${Updates.runtimeVersion} ${Updates.isEmbeddedLaunch ? "Original" : `Updated ${Updates.createdAt.toLocaleString()}`} `}
</Text>
</View>
);
};

const styles = StyleSheet.create({
view: {
paddingTop: 20
}
});

export default VersionInfo;
59 changes: 32 additions & 27 deletions root.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import React from "react";
import {
ActivityIndicator,
Alert,
AppState,
Platform,
StyleSheet,
View
} from "react-native";
import { Alert, AppState, Platform, StyleSheet } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { Provider } from "react-redux";
import { captureException } from "@sentry/react-native";
import * as Updates from "expo-updates";

import { ErrorBoundaryWithRecovery } from "./components/gb-live/error-boundary";
import GbLive from "./components/gb-live/live";
Expand All @@ -18,6 +12,28 @@ import { store } from "./state/reducer";
import { initSentry } from "./utils/sentry";
// import { checkUpdatesRequireStateRefresh } from "./utils/version";

const checkUpdates = () => {
if (__DEV__) return;

Updates.checkForUpdateAsync().then((update) => {
if (update.isAvailable) {
Alert.alert(
"App update",
"A new version of the app is available. App must reload.",
[
{
text: "OK",
onPress: () =>
Updates.fetchUpdateAsync().then(() => {
Updates.reloadAsync();
})
}
]
);
}
});
};

export default function RootApp() {
React.useEffect(() => {
if (__DEV__) {
Expand All @@ -26,12 +42,12 @@ export default function RootApp() {
}
}, []);

// React.useEffect(() => {
// checkUpdatesRequireStateRefresh();
// }, []);
React.useEffect(() => {
// check for updates on launch
checkUpdates();
}, []);

// watch app state and set background

React.useEffect(() => {
if (Platform.OS == "ios" || Platform.OS == "android") {
initSentry();
Expand All @@ -50,24 +66,25 @@ export default function RootApp() {
}

const WithFromBackgroundRefresh = () => {
const [reloading, setReloading] = React.useState(false);
// const [reloading, setReloading] = React.useState(false);
const { refetch } = useGbSummaryOutputQuery();
const [background, setBackground] = React.useState(false);

React.useEffect(() => {
if (Platform.OS !== "ios" && Platform.OS !== "android") return;
const handleAppStateChange = async (nextAppState: string) => {
if (nextAppState === "active" && background) {
checkUpdates();
// console.log("App has come to the foreground - refetching data");
try {
setReloading(true);
// setReloading(true);
await refetch();
// console.log("Data refetched");
} catch (e) {
captureException(e);
} finally {
// console.log("Done refetching data");
setReloading(false);
// setReloading(false);
}
setBackground(false);
} else {
Expand All @@ -79,22 +96,10 @@ const WithFromBackgroundRefresh = () => {
listener.remove();
};
}, [refetch, background]);
if (reloading) {
return (
<View style={styles.container}>
<ActivityIndicator size="large" />
</View>
);
}
return <GbLive />;
};

const styles = StyleSheet.create({
container: {
alignItems: "center",
flex: 1,
justifyContent: "center"
},
gestureRootView: {
flex: 1
}
Expand Down

0 comments on commit 07eabb3

Please sign in to comment.