-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into kalvis/organizations-settings
- Loading branch information
Showing
9 changed files
with
235 additions
and
63 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import sessionStore from './session'; | ||
import {useEffect, useState} from 'react'; | ||
import {reaction} from 'mobx'; | ||
import type {AccountResponse} from '../dataInterface'; | ||
|
||
/** | ||
* Hook to use the session store in functional components. | ||
* This hook provides a way to access teh current logged account, information | ||
* regarding the anonymous state of the login and session methods. | ||
* | ||
* This hook uses MobX reactions to track the current account and update the | ||
* state accordingly. | ||
* In the future we should update this hook to use react-query and drop the usage of mob-x | ||
*/ | ||
export const useSession = () => { | ||
const [currentLoggedAccount, setCurrentLoggedAccount] = | ||
useState<AccountResponse>(); | ||
const [isAnonymous, setIsAnonymous] = useState<boolean>(true); | ||
const [isPending, setIsPending] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
// We need to setup a reaction for every observable we want to track | ||
// Generic reaction to sessionStore won't fire the re-rendering of the hook | ||
const currentAccountReactionDisposer = reaction( | ||
() => sessionStore.currentAccount, | ||
(currentAccount) => { | ||
if (sessionStore.isLoggedIn) { | ||
setCurrentLoggedAccount(currentAccount as AccountResponse); | ||
setIsAnonymous(false); | ||
setIsPending(sessionStore.isPending); | ||
} | ||
}, | ||
{fireImmediately: true} | ||
); | ||
|
||
return () => { | ||
currentAccountReactionDisposer(); | ||
}; | ||
}, []); | ||
|
||
return { | ||
currentLoggedAccount, | ||
isAnonymous, | ||
isPending, | ||
logOut: sessionStore.logOut.bind(sessionStore), | ||
logOutAll: sessionStore.logOutAll.bind(sessionStore), | ||
refreshAccount: sessionStore.refreshAccount.bind(sessionStore), | ||
}; | ||
}; |
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,2 @@ | ||
|
||
SUBMISSIONS_SUSPENDED_HEARTBEAT_KEY = 'kobo:update_attachment_storage_bytes:heartbeat' |
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
Oops, something went wrong.