Skip to content

Commit

Permalink
Remove timeout logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-nikitin-2022 committed Jan 13, 2025
1 parent aef9b48 commit 33eab2f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v1.7.2
-
- Устранены проблемы, связанные с работой runSync при использовании большого количества переходов в одной транзакции.
- Изменили пример с использование компонента Popout.

v1.7.1
-
- Обновили peer зависимости
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
import { useCallback, useRef } from 'react';
import { useRouteNavigator } from '@vkontakte/vk-mini-apps-router';
import { Alert } from '@vkontakte/vkui';

export function OffencePersikPopout() {
const routeNavigator = useRouteNavigator();
return <Alert
actions={[
{
title: 'Отмена',
mode: 'cancel',
},
{
title: 'Забрать',
mode: 'destructive',
action: () => setTimeout(() => routeNavigator.replace('/persik/sad/persik_modal/sad', { keepSearchParams: true }), 100),
},
]}
actionsLayout="horizontal"
onClose={() => routeNavigator.hidePopout()}
title="Еда персика"
description="Вы уверены, что хотите забрать у персика еду?"
/>;
const closeWithAction = useRef(false);

const handleTakeFood = useCallback(() => {
closeWithAction.current = true;

routeNavigator.runSync([
() => routeNavigator.hidePopout(),
() => routeNavigator.replace('/persik/sad/persik_modal/sad', { keepSearchParams: true }),
]);
}, [routeNavigator]);

const handleClose = useCallback(() => {
if (!closeWithAction.current) {
routeNavigator.hidePopout();
}

closeWithAction.current = false;
}, [closeWithAction, routeNavigator]);

return (
<Alert
actions={[
{
title: 'Отмена',
mode: 'cancel',
},
{
title: 'Забрать',
mode: 'destructive',
action: handleTakeFood,
},
]}
actionsLayout="horizontal"
onClose={handleClose}
title="Еда персика"
description="Вы уверены, что хотите забрать у персика еду?"
/>
);
}
6 changes: 4 additions & 2 deletions src/entities/NavigationTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export class NavigationTransaction {

doNext(): void {
if (!this.finished) {
this.actions[this.pointer]();
this.pointer += 1;
const action = this.actions[this.pointer];
this.pointer++;
action();
}

// this.finished изменился при выполнении предыдущего условия - нельзя объединить в if-else.
if (this.finished) {
this.resolve();
Expand Down
13 changes: 5 additions & 8 deletions src/services/TransactionExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,11 @@ export class TransactionExecutor {
public static async doNext(): Promise<void> {
const transactionExecutor = TransactionExecutor.getInstance();
const transactions = transactionExecutor.transactions;
// Нужно делать асинхронно, иначе будет бесконечный цикл навигация-изменение стейта-навигация...
setTimeout(() => {
if (transactions.length) {
transactions[0].doNext();
if (transactions[0].finished) {
transactions.shift();
}
if (transactions.length) {
transactions[0].doNext();
if (transactions[0]?.finished) {
transactions.shift();
}
});
}
}
}

0 comments on commit 33eab2f

Please sign in to comment.