pl-fe: make it partially work
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { useNavigate, type LinkProps } from '@tanstack/react-router';
|
||||
import clsx from 'clsx';
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import Counter from 'pl-fe/components/ui/counter';
|
||||
import Icon from 'pl-fe/components/ui/icon';
|
||||
import Toggle from 'pl-fe/components/ui/toggle';
|
||||
import { userTouching } from 'pl-fe/is-mobile';
|
||||
|
||||
interface MenuItem {
|
||||
type MenuItem = {
|
||||
action?: React.EventHandler<React.KeyboardEvent | React.MouseEvent>;
|
||||
active?: boolean;
|
||||
checked?: boolean;
|
||||
@@ -20,12 +20,15 @@ interface MenuItem {
|
||||
onChange?: (value: boolean) => void;
|
||||
target?: React.HTMLAttributeAnchorTarget;
|
||||
text: string;
|
||||
to?: string;
|
||||
type?: 'toggle' | 'radio';
|
||||
items?: Array<Omit<MenuItem, 'items'>>;
|
||||
onSelectFile?: (files: FileList) => void;
|
||||
accept?: string;
|
||||
}
|
||||
} & ({
|
||||
to: LinkProps['to'];
|
||||
params?: LinkProps['params'];
|
||||
search?: LinkProps['search'];
|
||||
} | { to?: undefined });
|
||||
|
||||
interface IDropdownMenuItem {
|
||||
index: number;
|
||||
@@ -36,7 +39,7 @@ interface IDropdownMenuItem {
|
||||
}
|
||||
|
||||
const DropdownMenuItem = ({ index, item, onClick, autoFocus, onSetTab }: IDropdownMenuItem) => {
|
||||
const history = useHistory();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const itemRef = useRef<HTMLAnchorElement>(null);
|
||||
const fileElement = useRef<HTMLInputElement>(null);
|
||||
@@ -62,8 +65,8 @@ const DropdownMenuItem = ({ index, item, onClick, autoFocus, onSetTab }: IDropdo
|
||||
if (item.to) {
|
||||
event.preventDefault();
|
||||
if (userTouching.matches) {
|
||||
history.replace(item.to);
|
||||
} else history.push(item.to);
|
||||
navigate({ to: item.to, params: item.params, search: item.search, replace: true });
|
||||
} else navigate({ to: item.to, params: item.params, search: item.search });
|
||||
} else if (typeof item.action === 'function') {
|
||||
const action = item.action;
|
||||
event.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user