-
-
Notifications
You must be signed in to change notification settings - Fork 119
feat: support "None" option for keyboard shortcuts #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
peaske7
wants to merge
7
commits into
amicalhq:main
Choose a base branch
from
peaske7:feat/support-none-for-shortcuts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d53969c
apply "none" for shortcuts
peaske7 3388b88
fix loading "flash"
peaske7 b9a2f7a
extract hooks
peaske7 f6b2d39
address code rabbit comments
peaske7 0e2be77
fix ui drift
peaske7 c92ec21
safe local storage access
peaske7 0e73ea4
address coderabbit pr comments
peaske7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { useState, useEffect } from "react"; | ||
|
|
||
| // Safe localStorage utilities that never throw | ||
| export const safeStorage = { | ||
| getItem(key: string): string | null { | ||
| try { | ||
| return localStorage.getItem(key); | ||
| } catch { | ||
| return null; | ||
| } | ||
| }, | ||
| setItem(key: string, value: string): boolean { | ||
| try { | ||
| localStorage.setItem(key, value); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| }, | ||
| removeItem(key: string): boolean { | ||
| try { | ||
| localStorage.removeItem(key); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| }, | ||
| }; | ||
|
|
||
| export function useLocalStorage<T>( | ||
| key: string, | ||
| initialValue: T, | ||
| ): [T, React.Dispatch<React.SetStateAction<T>>] { | ||
| const [value, setValue] = useState<T>(() => { | ||
| const item = safeStorage.getItem(key); | ||
| if (item === null) return initialValue; | ||
| try { | ||
| return JSON.parse(item); | ||
| } catch { | ||
| safeStorage.removeItem(key); | ||
| return initialValue; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| safeStorage.setItem(key, JSON.stringify(value)); | ||
| }, [key, value]); | ||
|
|
||
| return [value, setValue]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { useCallback } from "react"; | ||
| import { useLocalStorage } from "./useLocalStorage"; | ||
|
|
||
| export function usePreviousShortcut(shortcutId: string) { | ||
| const storageKey = `previous-shortcut-${shortcutId}`; | ||
| const [previousKeys, setPreviousKeys] = useLocalStorage<number[]>( | ||
| storageKey, | ||
| [], | ||
| ); | ||
|
|
||
| const savePrevious = useCallback( | ||
| (keys: number[]) => { | ||
| if (keys.length > 0) { | ||
| setPreviousKeys(keys); | ||
| } | ||
| }, | ||
| [setPreviousKeys], | ||
| ); | ||
|
|
||
| const restorePrevious = useCallback(() => { | ||
| const keys = previousKeys; | ||
| setPreviousKeys([]); | ||
| return keys; | ||
| }, [previousKeys, setPreviousKeys]); | ||
|
|
||
| const clearPrevious = useCallback(() => { | ||
| setPreviousKeys([]); | ||
| }, [setPreviousKeys]); | ||
|
|
||
| return { | ||
| previousKeys, | ||
| savePrevious, | ||
| restorePrevious, | ||
| clearPrevious, | ||
| hasPrevious: previousKeys.length > 0, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: amicalhq/amical
Length of output: 86
🏁 Script executed:
Repository: amicalhq/amical
Length of output: 2450
🏁 Script executed:
Repository: amicalhq/amical
Length of output: 3348
🏁 Script executed:
Repository: amicalhq/amical
Length of output: 679
🏁 Script executed:
Repository: amicalhq/amical
Length of output: 6660
🏁 Script executed:
Repository: amicalhq/amical
Length of output: 2441
Components render nothing during shortcut data load.
ShortcutsSettingsPageinitializes shortcuts asundefinedand relies on async data loading, causing ShortcutInput to return null until the query completes. This leaves blank space in the UI during load. Consider:[]) instead ofundefinedNote:
OnboardingShortcutInputalready defaults to[], so this is primarily an issue in the settings page.🤖 Prompt for AI Agents