-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f00dd68
commit 03a449c
Showing
5 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { atomEffect } from 'jotai-effect'; | ||
|
||
import { serverConnectedState, serverErrorState } from '@/state-mgmt/atoms'; | ||
|
||
import { fetchAPI } from './fetch'; | ||
|
||
// otherwise get the default schedule | ||
export const fetchHealth = atomEffect( | ||
(get, set) => { | ||
const serverError = get(serverErrorState); | ||
if (serverError) { | ||
return; | ||
} | ||
|
||
// Fetch event list from api | ||
fetchAPI('health').then((res: { status: string } | ServerErrorResponse) => { | ||
const error = res as ServerErrorResponse; | ||
|
||
if ('status' in res) { | ||
set(serverConnectedState, true); | ||
return; | ||
} | ||
|
||
// *** If errors specific prop, detail, update serverErrorState | ||
if (error.detail) { | ||
set(serverErrorState, error.detail[0].msg); | ||
return; | ||
} | ||
|
||
set(serverErrorState, 'No connection'); | ||
}); | ||
}, | ||
// Dependencies: | ||
// serverErrorState | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters