- Add logo click handler to navigate to current week view from any view (month, day, or week) - Update MainTitle component to accept calendarRef and view change callbacks - Implement handleLogoClick that changes view to week and navigates to current week - Add comprehensive test cases for logo click behavior from all view types Co-authored-by: Lê Nhân Phụng <lenhanphung@Phung-Mac-M4.local>
This commit is contained in:
@@ -160,7 +160,12 @@ export function Menubar({
|
||||
<header className="menubar">
|
||||
<div className="left-menu">
|
||||
<div className="menu-items">
|
||||
<MainTitle />
|
||||
<MainTitle
|
||||
calendarRef={calendarRef}
|
||||
currentView={currentView}
|
||||
onViewChange={onViewChange}
|
||||
onDateChange={onDateChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="menu-items">
|
||||
<div className="navigation-controls">
|
||||
@@ -365,16 +370,49 @@ export function Menubar({
|
||||
);
|
||||
}
|
||||
|
||||
export function MainTitle() {
|
||||
export type MainTitleProps = {
|
||||
calendarRef: React.RefObject<CalendarApi | null>;
|
||||
currentView: string;
|
||||
onViewChange?: (view: string) => void;
|
||||
onDateChange?: (date: Date) => void;
|
||||
};
|
||||
|
||||
export function MainTitle({
|
||||
calendarRef,
|
||||
currentView,
|
||||
onViewChange,
|
||||
onDateChange,
|
||||
}: MainTitleProps) {
|
||||
const { t } = useI18n();
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const handleLogoClick = async () => {
|
||||
if (!calendarRef.current) return;
|
||||
|
||||
await dispatch(setView("calendar"));
|
||||
|
||||
if (currentView !== "timeGridWeek") {
|
||||
calendarRef.current.changeView("timeGridWeek");
|
||||
if (onViewChange) {
|
||||
onViewChange("timeGridWeek");
|
||||
}
|
||||
}
|
||||
|
||||
calendarRef.current.today();
|
||||
|
||||
if (onDateChange) {
|
||||
const newDate = calendarRef.current.getDate();
|
||||
onDateChange(newDate);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="menubar-item tc-home">
|
||||
<img
|
||||
className="logo"
|
||||
src={logo}
|
||||
alt={t("menubar.logoAlt")}
|
||||
onClick={() => dispatch(setView("calendar"))}
|
||||
onClick={handleLogoClick}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user