Skip to content

Commit

Permalink
Add refreshing to charts
Browse files Browse the repository at this point in the history
  • Loading branch information
ronickg committed Nov 26, 2021
1 parent 2678b3f commit 00bc1ab
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 44 deletions.
6 changes: 3 additions & 3 deletions src/localization/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export default {
farmerSettings: 'Nastavené farmáře',
displayName: 'Zobrazené jméno',
farmName: 'Nastavte jméno',
totalChiaAccumulated: 'Total Paid',
noPayoutsRecieved: 'No payouts received yet. Pull down to refresh.',
overView: 'Overview',
totalChiaAccumulated: 'Vyplaceno celkem',
noPayoutsRecieved: 'Nebyla přijata žádná platba. Tahem dolu obnovte stránku',
overView: 'Přehled',
},
};
10 changes: 5 additions & 5 deletions src/localization/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import cs from './cs';
const LANGUAGES = {
en,
fr,
de,
es,
hu,
pl,
ru,
cs,
// de,
// es,
// hu,
// pl,
// ru,
};

const LANG_CODES = Object.keys(LANGUAGES);
Expand Down
12 changes: 6 additions & 6 deletions src/screens/LanguageSelectorScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import PressableCard from '../components/PressableCard';

export const LANGUAGES = [
{ code: 'en', label: 'English' },
{ code: 'de', label: 'Deutsch' },
{ code: 'fr', label: 'Français' },
{ code: 'es', label: 'Español' },
{ code: 'hu', label: 'Magyar' },
{ code: 'pl', label: 'Polski' },
{ code: 'ru', label: 'Русский' },
{ code: 'cs', label: 'Čeština' },
{ code: 'fr', label: 'Français' },
// { code: 'de', label: 'Deutsch' },
// { code: 'es', label: 'Español' },
// { code: 'hu', label: 'Magyar' },
// { code: 'pl', label: 'Polski' },
// { code: 'ru', label: 'Русский' },
];

const Item = ({ item, selected, onPress }) => {
Expand Down
50 changes: 24 additions & 26 deletions src/screens/charts/PoolspaceScreen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fromUnixTime, getUnixTime, isAfter } from 'date-fns';
import React, { useEffect, useState } from 'react';
import { SafeAreaView } from 'react-native';
import { RefreshControl, SafeAreaView, ScrollView } from 'react-native';
import { useSetRecoilState } from 'recoil';
import { getSpace } from '../../Api';
import { netSpaceRequestIDState } from '../../Atoms';
Expand All @@ -20,31 +20,11 @@ const filterData = (data, timePeriod) => {
return data.filter((item) => isAfter(fromUnixTime(item.x), date));
};

// const netspaceQuery = selectorFamily({
// key: 'netspaceSelector',
// get:
// () =>
// async ({ get }) => {
// get(netSpaceRequestIDState());
// const response = await getNetspace();
// const convertedData = response.map((item) => ({
// x: getUnixTime(new Date(item.date)),
// y: item.size,
// }));
// const data = NetspaceChartIntervals.map((item) => {
// if (item.time === -1) return convertedData;
// return filterData(convertedData, item.time);
// });
// if (response.error) {
// throw response.error;
// }
// return data;
// },
// });

const PoolSpaceScreen = ({ navigation }) => {
const [data, setData] = useState(null);
const [maxSize, setMaxSize] = useState('');
const [refreshing, setRefreshing] = useState(false);
const refresh = useRefresh();

useEffect(() => {
getSpace().then((netspace) => {
Expand All @@ -68,10 +48,15 @@ const PoolSpaceScreen = ({ navigation }) => {
});
setMaxSize(formatBytes(netspace[netspace.length - 1].size));
setData(data);
setRefreshing(false);
});
}, []);
}, [refreshing]);

useEffect(() => {
refresh();
}, [refreshing]);

if (data === null) {
if (!data && !refreshing) {
return <LoadingComponent />;
}

Expand All @@ -81,7 +66,20 @@ const PoolSpaceScreen = ({ navigation }) => {
flex: 1,
}}
>
<PoolspaceChart data={data} maxSize={maxSize} />
<ScrollView
style={{ flex: 1 }}
contentContainerStyle={{ paddingTop: 6, paddingBottom: 6, flexGrow: 1 }}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={() => {
setRefreshing(true);
}}
/>
}
>
<PoolspaceChart data={data} maxSize={maxSize} />
</ScrollView>
</SafeAreaView>
);
};
Expand Down
26 changes: 22 additions & 4 deletions src/screens/farmer/FarmerPartialScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { Dimensions, SafeAreaView, View } from 'react-native';
import { Dimensions, SafeAreaView, View, ScrollView, RefreshControl } from 'react-native';
import { selectorFamily, useRecoilValueLoadable, useSetRecoilState } from 'recoil';
import { getPartialsFromIDTest } from '../../Api';
import { partialRefreshState } from '../../Atoms';
Expand Down Expand Up @@ -34,6 +34,7 @@ const FarmerPartialScreen = ({ launcherId }) => {
const partialsLoadable = useRecoilValueLoadable(query(launcherId));
const [refreshing, setRefreshing] = useState(false);
const [data, setData] = useState(null);
const refresh = useRefresh();

useEffect(() => {
if (partialsLoadable.state === 'hasValue') {
Expand Down Expand Up @@ -89,15 +90,32 @@ const FarmerPartialScreen = ({ launcherId }) => {
}
}, [partialsLoadable]);

useEffect(() => {
refresh();
}, [refreshing]);

if (!data && !refreshing) {
return <LoadingComponent />;
}

return (
<SafeAreaView style={{ flex: 1 }}>
<View style={{ flex: 1, justifyContent: 'center' }}>
<PartialChartProvider data={data} />
</View>
<ScrollView
style={{ flex: 1 }}
contentContainerStyle={{ paddingTop: 6, paddingBottom: 6, flexGrow: 1 }}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={() => {
setRefreshing(true);
}}
/>
}
>
<View style={{ flex: 1, justifyContent: 'center' }}>
<PartialChartProvider data={data} />
</View>
</ScrollView>
</SafeAreaView>
);
};
Expand Down

0 comments on commit 00bc1ab

Please sign in to comment.