Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract shell state into separate context #1824

Merged

Conversation

estrattonbailey
Copy link
Member

Pulls out drawer handling and minimal shell mode into its own React context provider and methods.

Couple notes:

  • closing currently active elements will be easier once they're on on React context — for now I'll manually co-locate these calls to replicate existing functionality

Comment on lines 34 to 39
minimalShellMode,
setMinimalShellMode: _setMinimalShellMode,
isDrawerOpen,
setIsDrawerOpen: _setIsDrawerOpen,
isDrawerSwipeDisabled,
setIsDrawerSwipeDisabled: _setIsDrawerSwipeDisabled,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could create callbacks for each of these too

@@ -38,7 +38,7 @@ export const FeedPage = observer(function FeedPageImpl({
const store = useStores()
const pal = usePalette('default')
const {isDesktop} = useWebMediaQueries()
const [onMainScroll, isScrolledDown, resetMainScroll] = useOnMainScroll(store)
const [onMainScroll, isScrolledDown, resetMainScroll] = useOnMainScroll()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer need to pass in the root store

Comment on lines +53 to 62
let listener = {remove() {}}
if (isAndroid) {
listener = BackHandler.addEventListener('hardwareBackPress', () => {
setIsDrawerOpen(false)
return store.shell.closeAnyActiveElement()
})
}
return () => {
listener()
listener.remove()
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to use useShellState, so refactored this logic up a level into the component 👍

Comment on lines 31 to 32
setIsDrawerOpen(false)
store.shell.closeAnyActiveElement()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to do this here instead of in a centralized closeAnyActiveElement. We will migrate this later on.

Copy link
Collaborator

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah looks great

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the last comment — we need to separate setters from the state. Two contexts.

@@ -38,7 +39,7 @@ export function useMinimalShellMode() {

React.useEffect(() => {
return autorun(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The autorun here doesn't make sense anymore.

src/lib/hooks/useMinimalShellMode.tsx Show resolved Hide resolved
src/view/com/auth/LoggedOut.tsx Outdated Show resolved Hide resolved
src/state/shell/index.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets go

@pfrazee pfrazee merged commit bfe196b into main Nov 7, 2023
4 checks passed
@pfrazee pfrazee deleted the eric/app-906-extract-shell-state-into-separate-statecontext branch November 7, 2023 19:37
estrattonbailey added a commit that referenced this pull request Nov 7, 2023
* origin:
  Extract shell state into separate context (#1824)
  Correct meta tag attributes (#1829)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants