Skip to content

Commit 9baf0d7

Browse files
Allow filecontext to open page at new url pathname
1 parent f8b48a0 commit 9baf0d7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/misc/fileContext.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export interface TabState {
5353
export function addPage(
5454
pageState: PageState,
5555
location: string,
56-
desc: FileDescription
56+
desc: FileDescription,
57+
pathname?: string
5758
): PageState {
5859
const pagesCopy = { ...pageState };
5960
pagesCopy[location] = desc;
@@ -171,7 +172,11 @@ export function selectTab(
171172
export type FileContextType = {
172173
pageState: PageState;
173174
tabState: TabState;
174-
addPage: (location: string, fileDesc: FileDescription) => void;
175+
addPage: (
176+
location: string,
177+
fileDesc: FileDescription,
178+
pathname?: string
179+
) => void;
175180
removePage: (location: string, fileDesc?: FileDescription) => void;
176181
addTab: (
177182
location: string,
@@ -238,9 +243,13 @@ export const FileProvider: React.FC<FileProviderProps> = (
238243
const fileContext = {
239244
pageState,
240245
tabState,
241-
addPage: (location: string, fileDesc: FileDescription): void => {
246+
addPage: (
247+
location: string,
248+
fileDesc: FileDescription,
249+
pathname?: string
250+
): void => {
242251
const newPageState = addPage(pageState, location, fileDesc);
243-
history.push(history.location.pathname, {
252+
history.push(pathname ? pathname : history.location.pathname, {
244253
pageState: newPageState,
245254
tabState: history.location.state?.tabState ?? tabState
246255
});

0 commit comments

Comments
 (0)