Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions packages/web/src/common/utils/shortcut/data/shortcuts.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,20 @@ import { type Shortcut } from "@web/common/types/global.shortcut.types";

interface ShortcutsConfig {
isHome?: boolean;
isAuthenticated?: boolean;
isToday?: boolean;
isNow?: boolean;
currentDate?: dayjs.Dayjs;
}

export const getShortcuts = (config: ShortcutsConfig = {}) => {
const {
isAuthenticated = false,
isHome = false,
isToday = true,
isNow = false,
currentDate,
} = config;
const { isHome = false, isToday = true, isNow = false, currentDate } = config;

const globalShortcuts: Shortcut[] = [
{ k: VIEW_SHORTCUTS.now.key, label: VIEW_SHORTCUTS.now.label },
{ k: VIEW_SHORTCUTS.day.key, label: VIEW_SHORTCUTS.day.label },
{ k: VIEW_SHORTCUTS.week.key, label: VIEW_SHORTCUTS.week.label },
{ k: "r", label: "Edit reminder" },
{ k: "[", label: "Toggle sidebar" },
{ k: "?", label: "Toggle shortcuts" },
{ k: "z", label: isAuthenticated ? "Logout" : "Log in" },
{ k: "[", label: "Close sidebar" },
{ k: "?", label: "Show shortcuts" },
{ k: "Mod+k", label: "Command Palette" },
];

Expand Down Expand Up @@ -73,7 +64,8 @@ export const getShortcuts = (config: ShortcutsConfig = {}) => {
}
if (isNow) {
nowShortcuts = [
{ k: "e", label: "Edit description" },
{ k: "e d", label: "Edit description" },
{ k: "e r", label: "Edit reminder" },
{ k: "Mod+Enter", label: "Save description" },
{ k: "j", label: "Previous task" },
{ k: "k", label: "Next task" },
Expand Down
3 changes: 0 additions & 3 deletions packages/web/src/views/Day/view/DayViewContent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { memo, useCallback, useMemo } from "react";
import dayjs from "@core/util/date/dayjs";
import { useSession } from "@web/auth/compass/session/useSession";
import { useCompassRefs } from "@web/common/hooks/useCompassRefs";
import { useEventDNDActions } from "@web/common/hooks/useEventDNDActions";
import { useGridOrganization } from "@web/common/hooks/useGridOrganization";
Expand Down Expand Up @@ -38,7 +37,6 @@ import { Styled, StyledCalendar } from "@web/views/Week/styled";
export const DayViewContent = memo(() => {
const dispatch = useAppDispatch();
const isSidebarOpen = useAppSelector(selectIsSidebarOpen);
const { authenticated } = useSession();

const selectionActions = useMainGridSelectionActions();
const { timedEventsGridRef } = useCompassRefs();
Expand All @@ -64,7 +62,6 @@ export const DayViewContent = memo(() => {
const dateInView = useDateInView();
const shortcuts = getShortcuts({
currentDate: dateInView,
isAuthenticated: authenticated,
});

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "@web/common/utils/dom/event-emitter.util";
import { Textarea } from "@web/components/Textarea";
import { TooltipWrapper } from "@web/components/Tooltip/TooltipWrapper";
import { ShortCutLabel } from "@web/common/utils/shortcut/shortcut.util";

const MAX_DESCRIPTION_LENGTH = 255;
const NEAR_LIMIT_THRESHOLD = Math.floor(MAX_DESCRIPTION_LENGTH * 0.9); // 90% of max
Expand Down Expand Up @@ -242,7 +243,16 @@ export const TaskDescription: React.FC<TaskDescriptionProps> = ({
<CharacterCount isNearLimit={isNearLimit}>
{value.length}/{MAX_DESCRIPTION_LENGTH}
</CharacterCount>
<TooltipWrapper description="Save description" shortcut="Mod+Enter">
<TooltipWrapper
description="Save description"
shortcut={
<span className="inline-flex items-center gap-1">
<ShortCutLabel k="Mod" size={12} />
<span>+</span>
<ShortCutLabel k="Enter" size={12} />
</span>
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz use the icons instead of just the text. Additionally, it should have a space between the elements so it looks more like this:

+ Enter (except instead of ⌘ it's the command icon)

This will help us give the user a consistent experience.

>
<SaveButton
aria-label="Save description"
onClick={saveDescription}
Expand Down
13 changes: 13 additions & 0 deletions packages/web/src/views/Now/context/NowViewProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { ensureStorageReady } from "@web/common/storage/adapter/adapter";
import { type Task } from "@web/common/types/task.types";
import { getDateKey } from "@web/common/utils/storage/storage.util";
import { getIncompleteTasksSorted } from "@web/common/utils/task/sort.task";
import { viewSlice } from "@web/ducks/events/slices/view.slice";
import { useAppDispatch } from "@web/store/store.hooks";
import { useAvailableTasks } from "../hooks/useAvailableTasks";
import { useFocusedTask } from "../hooks/useFocusedTask";
import { useNowShortcuts } from "../shortcuts/useNowShortcuts";
Expand Down Expand Up @@ -35,6 +37,7 @@ export function NowViewProvider({
children,
onToggleSidebar,
}: NowViewProviderProps) {
const dispatch = useAppDispatch();
const navigate = useNavigate();
const { availableTasks, allTasks, hasCompletedTasks } = useAvailableTasks();
const { focusedTask, setFocusedTask } = useFocusedTask({ availableTasks });
Expand Down Expand Up @@ -135,13 +138,23 @@ export function NowViewProvider({
setFocusedTask,
]);

const handleEscape = useCallback(() => {
navigate(ROOT_ROUTES.DAY);
}, [navigate]);

const handleEditReminder = useCallback(() => {
dispatch(viewSlice.actions.updateReminder(true));
}, [dispatch]);

useNowShortcuts({
focusedTask,
availableTasks,
onPreviousTask: handlePreviousTask,
onNextTask: handleNextTask,
onCompleteTask: handleCompleteTask,
onToggleSidebar,
onEscape: handleEscape,
onEditReminder: handleEditReminder,
});

const value: NowViewContextValue = {
Expand Down
28 changes: 26 additions & 2 deletions packages/web/src/views/Now/shortcuts/useNowShortcuts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("useNowShortcuts", () => {
);
});

it("uses E to focus the task description", async () => {
it("uses E D sequence to focus the task description", async () => {
const onFocusDescription = mock();
compassEventEmitter.on(
CompassDOMEvents.FOCUS_TASK_DESCRIPTION,
Expand All @@ -39,13 +39,14 @@ describe("useNowShortcuts", () => {
renderHook(() => useNowShortcuts(), { wrapper });

pressKey("e");
pressKey("d");

await waitFor(() => {
expect(onFocusDescription).toHaveBeenCalledTimes(1);
});
});

it("does not use D for the task description shortcut", async () => {
it("does not focus description when pressing D alone", async () => {
const onFocusDescription = mock();
compassEventEmitter.on(
CompassDOMEvents.FOCUS_TASK_DESCRIPTION,
Expand All @@ -70,4 +71,27 @@ describe("useNowShortcuts", () => {
expect(onToggleSidebar).toHaveBeenCalledTimes(1);
});
});

it("navigates to day view when Escape is pressed", async () => {
const onEscape = mock();
renderHook(() => useNowShortcuts({ onEscape }), { wrapper });

pressKey("Escape");

await waitFor(() => {
expect(onEscape).toHaveBeenCalledTimes(1);
});
});

it("uses E R sequence to edit reminder", async () => {
const onEditReminder = mock();
renderHook(() => useNowShortcuts({ onEditReminder }), { wrapper });

pressKey("e");
pressKey("r");

await waitFor(() => {
expect(onEditReminder).toHaveBeenCalledTimes(1);
});
});
});
15 changes: 14 additions & 1 deletion packages/web/src/views/Now/shortcuts/useNowShortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback } from "react";
import { useHotkeySequence } from "@tanstack/react-hotkeys";
import { ID_REMINDER_INPUT } from "@web/common/constants/web.constants";
import { useAppHotkey, useAppHotkeyUp } from "@web/common/hooks/useAppHotkey";
import { type Task } from "@web/common/types/task.types";
Expand All @@ -14,6 +15,8 @@ interface Props {
onNextTask?: () => void;
onCompleteTask?: () => void;
onToggleSidebar?: () => void;
onEscape?: () => void;
onEditReminder?: () => void;
}

export function useNowShortcuts(props?: Props) {
Expand All @@ -24,6 +27,8 @@ export function useNowShortcuts(props?: Props) {
onNextTask,
onCompleteTask,
onToggleSidebar,
onEscape,
onEditReminder,
} = props || {};

const handleTaskNavigation = useCallback(
Expand All @@ -35,7 +40,7 @@ export function useNowShortcuts(props?: Props) {
[focusedTask, availableTasks.length],
);

useAppHotkeyUp("E", () => {
useHotkeySequence(["E", "D"], () => {
compassEventEmitter.emit(CompassDOMEvents.FOCUS_TASK_DESCRIPTION);
});

Expand Down Expand Up @@ -71,4 +76,12 @@ export function useNowShortcuts(props?: Props) {
useAppHotkeyUp("[", () => {
onToggleSidebar?.();
});

useAppHotkeyUp("Escape", () => {
onEscape?.();
});

useHotkeySequence(["E", "R"], () => {
onEditReminder?.();
});
}
3 changes: 0 additions & 3 deletions packages/web/src/views/Now/view/NowView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect } from "react";
import { useSession } from "@web/auth/compass/session/useSession";
import { usePointerPosition } from "@web/common/hooks/usePointerPosition";
import { useSidebarState } from "@web/common/hooks/useSidebarState";
import { getShortcuts } from "@web/common/utils/shortcut/data/shortcuts.data";
Expand All @@ -11,11 +10,9 @@ import { NowViewContent } from "@web/views/Now/view/NowViewContent";
import { StyledCalendar } from "@web/views/Week/styled";

export const NowView = () => {
const { authenticated } = useSession();
const { togglePointerMovementTracking } = usePointerPosition();
const { isSidebarOpen, toggleSidebar } = useSidebarState();
const { globalShortcuts, nowShortcuts } = getShortcuts({
isAuthenticated: authenticated,
isNow: true,
});

Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/views/Week/WeekView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export const WeekView = () => {
{ k: "d", label: "Day" },
{ k: "w", label: "Week" },
{ k: "n", label: "Now" },
{ k: "[", label: "Toggle sidebar" },
{ k: "?", label: "Toggle shortcuts" },
{ k: "[", label: "Close sidebar" },
{ k: "?", label: "Show shortcuts" },
{ k: "Mod+k", label: "Command Palette" },
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ROOT_ROUTES } from "@web/common/constants/routes";
import { VIEW_SHORTCUTS } from "@web/common/constants/shortcuts.constants";
import { useAppHotkey, useAppHotkeyUp } from "@web/common/hooks/useAppHotkey";
import { useAuthModal } from "@web/components/AuthModal/hooks/useAuthModal";
import { viewSlice } from "@web/ducks/events/slices/view.slice";
import { settingsSlice } from "@web/ducks/settings/slices/settings.slice";
import { useAppDispatch } from "@web/store/store.hooks";

Expand Down Expand Up @@ -51,10 +50,6 @@ export function useGlobalShortcuts() {
openModal("login");
});

useAppHotkeyUp("R", () => {
dispatch(viewSlice.actions.updateReminder(true));
});

useAppHotkey(
"Mod+K",
() => {
Expand Down