Skip to content

Commit

Permalink
fix: moving through View's after clearing history
Browse files Browse the repository at this point in the history
  • Loading branch information
reyzitwo committed Nov 26, 2023
1 parent 8973fa8 commit 5ee31dc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kokateam/router-vkminiapps",
"version": "0.2.2",
"version": "0.2.3",
"description": "Routing library for VK Mini Apps",
"main": "lib/index.js",
"repository": "https://github.com/kokateam/router-vkminiapps",
Expand Down
8 changes: 4 additions & 4 deletions src/components/View.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useEffect } from "react";
import React, { ReactNode, FC, useEffect } from "react";

import { View as VKView } from "@vkontakte/vkui";
import { useRouterPanel, useRouterSettings } from "../hooks/hooks";
Expand All @@ -7,12 +7,12 @@ import bridge from "@vkontakte/vk-bridge";

export interface ViewProps {
id: string;
popout?: React.ReactNode;
modal?: React.ReactNode;
popout?: ReactNode;
modal?: ReactNode;
onTransition?(params: { isBack: boolean; from: string; to: string }): void;
onSwipeBackStart?(): void;
onSwipeBackCancel?(): void;
children: React.ReactNode;
children: ReactNode;
}

const View: FC<ViewProps> = (props) => {
Expand Down
13 changes: 12 additions & 1 deletion src/hooks/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,18 @@ export const useRouterClearHistory = (): [
RouterClearHistory["clearHistory"]
] => {
const [canUsed, setState] = useRecoilState(useClearHistory);
const clearHistory = () => setState(true);
const [{ isBack }, setSettings] = useRouterSettings();

const clearHistory = () => {
const initBack = isBack;
setSettings({ isBack: false });

setState(true);

setTimeout(() => {
setSettings({ isBack: initBack });
}, 100);
};

return [canUsed, clearHistory];
};
Expand Down
5 changes: 3 additions & 2 deletions src/storage/selectors/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,11 @@ export const useClearHistory = selector<boolean>({

const viewsPanels = { ...old.views.panels };
for (let view in viewsPanels) {
viewsPanels[view] = viewsPanels[view][0];
viewsPanels[view] = [viewsPanels[view][viewsPanels[view].length - 1]];
}

for (let item of old.history) {
for (let i = 0; i < old.history.length - 1; i++) {
let item = old.history[i];
if (item.type === "panel" || item.type === "modal") {
window.history.go(-1);
}
Expand Down

0 comments on commit 5ee31dc

Please sign in to comment.