-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug filter the list menu from command and make a symbol base on OS
- Loading branch information
Showing
8 changed files
with
113 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,21 @@ | ||
import { useOs, type OS } from '@/hooks/useOs' | ||
|
||
export default function ShortCut(props: { menu: string }) { | ||
const os = useOs() | ||
const { menu } = props | ||
const getSymbol = (os: OS) => { | ||
switch (os) { | ||
case 'macos': | ||
return '⌘' | ||
|
||
default: | ||
return 'Ctrl' | ||
} | ||
} | ||
|
||
return ( | ||
<div className="inline-flex items-center justify-center rounded-md bg-secondary px-1 py-0.5 text-xs font-bold text-muted-foreground"> | ||
<p>{getSymbol(os) + ' + ' + menu}</p> | ||
</div> | ||
) | ||
} |
This file contains 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,57 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
export type OS = | ||
| 'undetermined' | ||
| 'macos' | ||
| 'ios' | ||
| 'windows' | ||
| 'android' | ||
| 'linux' | ||
|
||
function getOS(): OS { | ||
if (typeof window === 'undefined') { | ||
return 'undetermined' | ||
} | ||
|
||
const { userAgent } = window.navigator | ||
const macosPlatforms = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i | ||
const windowsPlatforms = /(Win32)|(Win64)|(Windows)|(WinCE)/i | ||
const iosPlatforms = /(iPhone)|(iPad)|(iPod)/i | ||
|
||
if (iosPlatforms.test(userAgent)) { | ||
return 'ios' | ||
} | ||
if (/Android/i.test(userAgent)) { | ||
return 'android' | ||
} | ||
|
||
if (macosPlatforms.test(userAgent)) { | ||
return 'macos' | ||
} | ||
if (windowsPlatforms.test(userAgent)) { | ||
return 'windows' | ||
} | ||
if (/Linux/i.test(userAgent)) { | ||
return 'linux' | ||
} | ||
|
||
return 'undetermined' | ||
} | ||
|
||
interface UseOsOptions { | ||
getValueInEffect: boolean | ||
} | ||
|
||
export function useOs(options: UseOsOptions = { getValueInEffect: true }): OS { | ||
const [value, setValue] = useState<OS>( | ||
options.getValueInEffect ? 'undetermined' : getOS() | ||
) | ||
|
||
useEffect(() => { | ||
if (options.getValueInEffect) { | ||
setValue(getOS) | ||
} | ||
}, []) | ||
|
||
return value | ||
} |
This file contains 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 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