-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #437 from VKCOM/pavelnikitin/feature/modal-close-n…
…o-history/MA-19935 MA-19935: Implement history-less modal close
- Loading branch information
Showing
13 changed files
with
143 additions
and
50 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
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,20 @@ | ||
import { useContext, useEffect, useState } from 'react'; | ||
import { RouterContext } from '../contexts'; | ||
import { invariant } from '../utils/utils'; | ||
import { HistoryManager } from '../services'; | ||
|
||
export function useGetHistoryManager(): HistoryManager { | ||
const { viewHistory, router } = useContext(RouterContext); | ||
const [historyManager, setHistoryManager] = useState(new HistoryManager(viewHistory, router)); | ||
|
||
invariant( | ||
viewHistory, | ||
'You can not use useGetHistoryManager hook outside of RouteContext. Make sure calling it inside RouterProvider.', | ||
); | ||
|
||
useEffect(() => { | ||
setHistoryManager(new HistoryManager(viewHistory, router)); | ||
}, [viewHistory, router]); | ||
|
||
return historyManager; | ||
} |
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,14 @@ | ||
import { Router } from '@remix-run/router'; | ||
import { ViewHistory } from '.'; | ||
|
||
export class HistoryManager { | ||
public constructor(private readonly viewHistory: ViewHistory, private readonly router: Router) {} | ||
|
||
public getCurrentPosition() { | ||
return this.viewHistory.position; | ||
} | ||
|
||
public getHistory() { | ||
return this.viewHistory.historyStack; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
export type ViewNavigationRecord = { | ||
export interface ViewNavigationRecord { | ||
position: number; | ||
locationKey: string; | ||
path: string; | ||
state: Record<string, unknown> | null; | ||
view: string; | ||
panel: string; | ||
locationKey: string; | ||
root?: string; | ||
tab?: string; | ||
modal?: string; | ||
popout?: string; | ||
}; | ||
} |
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