Navigate function

This commit is contained in:
koalasat
2025-07-17 16:33:45 +02:00
parent 017a008dcb
commit 0d21aa9996
3 changed files with 21 additions and 10 deletions

View File

@ -41,7 +41,8 @@ const RobotProfile = ({
setView,
width,
}: RobotProfileProps): React.JSX.Element => {
const { windowSize, client, setOpen, open } = useContext<UseAppStoreType>(AppContext);
const { windowSize, client, setOpen, open, navigateToPage } =
useContext<UseAppStoreType>(AppContext);
const { garage, slotUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
const { federation } = useContext<UseFederationStoreType>(FederationContext);
@ -190,8 +191,9 @@ const RobotProfile = ({
<Grid item>
<Button
onClick={() => {
navigate(
`/order/${String(slot?.activeOrder?.shortAlias)}/${String(slot?.activeOrder?.id)}`,
navigateToPage(
`order/${String(slot?.activeOrder?.shortAlias)}/${String(slot?.activeOrder?.id)}`,
navigate,
);
}}
>
@ -205,8 +207,9 @@ const RobotProfile = ({
<Grid item>
<Button
onClick={() => {
navigate(
`/order/${String(slot?.lastOrder?.shortAlias)}/${String(slot?.lastOrder?.id)}`,
navigateToPage(
`order/${String(slot?.lastOrder?.shortAlias)}/${String(slot?.lastOrder?.id)}`,
navigate,
);
}}
>

View File

@ -1,4 +1,4 @@
import React from 'react';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { Key, Add } from '@mui/icons-material';
import {
@ -10,6 +10,7 @@ import {
Button,
} from '@mui/material';
import { useNavigate } from 'react-router-dom';
import { UseAppStoreType, AppContext } from '../../contexts/AppContext';
interface Props {
open: boolean;
@ -24,6 +25,7 @@ const NoRobotDialog = ({
}: Props): React.JSX.Element => {
const { t } = useTranslation();
const navigate = useNavigate();
const { navigateToPage } = useContext<UseAppStoreType>(AppContext);
return (
<Dialog open={open} onClose={onClose}>
@ -36,7 +38,7 @@ const NoRobotDialog = ({
<DialogActions>
<Button
onClick={() => {
navigate('garage');
navigateToPage('garage', navigate);
}}
>
<Key /> <div style={{ width: '0.5em' }} />

View File

@ -32,6 +32,7 @@ import { getWebln } from '../../utils';
import { signCleartextMessage } from '../../pgp';
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
import { UseAppStoreType, AppContext } from '../../contexts/AppContext';
interface Props {
coordinator: Coordinator;
@ -41,6 +42,7 @@ interface Props {
const RobotInfo: React.FC<Props> = ({ coordinator, onClose, disabled }: Props) => {
const { garage } = useContext<UseGarageStoreType>(GarageContext);
const { navigateToPage } = useContext<UseAppStoreType>(AppContext);
const { federation } = useContext<UseFederationStoreType>(FederationContext);
const navigate = useNavigate();
const { t } = useTranslation();
@ -128,8 +130,9 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose, disabled }: Props) =
{robot?.activeOrderId ? (
<ListItemButton
onClick={() => {
navigate(
`/order/${String(coordinator.shortAlias)}/${String(robot?.activeOrderId)}`,
navigateToPage(
`order/${String(coordinator.shortAlias)}/${String(robot?.activeOrderId)}`,
navigate,
);
onClose();
}}
@ -149,7 +152,10 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose, disabled }: Props) =
) : robot?.lastOrderId ? (
<ListItemButton
onClick={() => {
navigate(`order/${String(coordinator.shortAlias)}/${String(robot?.lastOrderId)}`);
navigateToPage(
`order/${String(coordinator.shortAlias)}/${String(robot?.lastOrderId)}`,
navigate,
);
onClose();
}}
>