Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
fix: no loader when refreshing sessions after revoking
Browse files Browse the repository at this point in the history
  • Loading branch information
antsgar committed Feb 25, 2021
1 parent 6b834ad commit 38f9b8b
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/screens/ManageSessions/ManageSessions.tsx
Expand Up @@ -16,6 +16,7 @@ import { SessionCell } from './SessionCell';
const useSessions = (): [
RemoteSession[],
() => void,
() => void,
boolean,
(uuid: UuidString) => Promise<void>,
string
Expand All @@ -25,11 +26,10 @@ const useSessions = (): [

// State
const [sessions, setSessions] = useState<RemoteSession[]>([]);
const [refreshing, setRefreshing] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const [errorMessage, setErrorMessage] = useState('');

const getSessions = useCallback(async () => {
setRefreshing(true);
const response = await application?.getSessions();
if (response && 'error' in response) {
if (response.error?.message) {
Expand All @@ -42,12 +42,17 @@ const useSessions = (): [
setSessions(newSessions);
setErrorMessage('');
}
setRefreshing(false);
}, [application]);

const refreshSessions = useCallback(async () => {
setRefreshing(true);
await getSessions();
setRefreshing(false);
}, [getSessions]);

useEffect(() => {
getSessions();
}, [application, getSessions]);
refreshSessions();
}, [application, refreshSessions]);

async function revokeSession(uuid: UuidString) {
let sessionsBeforeRevoke = sessions;
Expand All @@ -63,7 +68,14 @@ const useSessions = (): [
}
}

return [sessions, getSessions, refreshing, revokeSession, errorMessage];
return [
sessions,
getSessions,
refreshSessions,
refreshing,
revokeSession,
errorMessage,
];
};

export const ManageSessions: React.FC = () => {
Expand All @@ -76,6 +88,7 @@ export const ManageSessions: React.FC = () => {
const [
sessions,
getSessions,
refreshSessions,
refreshing,
revokeSession,
errorMessage,
Expand Down Expand Up @@ -145,7 +158,7 @@ export const ManageSessions: React.FC = () => {
<RefreshControl
tintColor={theme.stylekitContrastForegroundColor}
refreshing={refreshing}
onRefresh={getSessions}
onRefresh={refreshSessions}
/>
}
renderItem={RenderItem}
Expand Down

0 comments on commit 38f9b8b

Please sign in to comment.