From 9ca6487183a54a6d7337e00345d635eb47de4ece Mon Sep 17 00:00:00 2001 From: NamH Date: Sun, 7 Jan 2024 13:16:56 +0700 Subject: [PATCH] chore: clean up use os hook (#1418) Signed-off-by: James Co-authored-by: James --- extensions/model-extension/src/index.ts | 1 + web/containers/Layout/BottomBar/index.tsx | 70 +++++++++++------------ web/containers/Shortcut/index.tsx | 15 +---- web/hooks/useOs.ts | 57 ------------------ 4 files changed, 37 insertions(+), 106 deletions(-) delete mode 100644 web/hooks/useOs.ts diff --git a/extensions/model-extension/src/index.ts b/extensions/model-extension/src/index.ts index 90ebbe62be..5062096e66 100644 --- a/extensions/model-extension/src/index.ts +++ b/extensions/model-extension/src/index.ts @@ -200,6 +200,7 @@ export default class JanModelExtension implements ModelExtension { const allDirectories: string[] = [] for (const file of files) { if (file === '.DS_Store') continue + if (file === 'config') continue allDirectories.push(file) } diff --git a/web/containers/Layout/BottomBar/index.tsx b/web/containers/Layout/BottomBar/index.tsx index 209d1d95cf..74844a0004 100644 --- a/web/containers/Layout/BottomBar/index.tsx +++ b/web/containers/Layout/BottomBar/index.tsx @@ -28,6 +28,19 @@ import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels' import useGetSystemResources from '@/hooks/useGetSystemResources' import { useMainViewState } from '@/hooks/useMainViewState' +const menuLinks = [ + { + name: 'Discord', + icon: , + link: 'https://discord.gg/FTk2MvZwJH', + }, + { + name: 'Github', + icon: , + link: 'https://github.com/janhq/jan', + }, +] + const BottomBar = () => { const { activeModel, stateModel } = useActiveModel() const { ram, cpu } = useGetSystemResources() @@ -36,19 +49,6 @@ const BottomBar = () => { const { setMainViewState } = useMainViewState() const { downloadStates } = useDownloadState() - const linksMenu = [ - { - name: 'Discord', - icon: , - link: 'https://discord.gg/FTk2MvZwJH', - }, - { - name: 'Github', - icon: , - link: 'https://github.com/janhq/jan', - }, - ] - return (
@@ -99,30 +99,28 @@ const BottomBar = () => { {/* VERSION is defined by webpack, please see next.config.js */} Jan v{VERSION ?? ''}
- {linksMenu + {menuLinks .filter((link) => !!link) - .map((link, i) => { - return ( -
- - - - {link.icon} - - - - {link.name} - - - -
- ) - })} + .map((link, i) => ( +
+ + + + {link.icon} + + + + {link.name} + + + +
+ ))}
diff --git a/web/containers/Shortcut/index.tsx b/web/containers/Shortcut/index.tsx index ae93a827e2..1e6d7a81a9 100644 --- a/web/containers/Shortcut/index.tsx +++ b/web/containers/Shortcut/index.tsx @@ -1,21 +1,10 @@ -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' - } - } + const symbol = isMac ? '⌘' : 'Ctrl' return (
-

{getSymbol(os) + ' + ' + menu}

+

{symbol + ' + ' + menu}

) } diff --git a/web/hooks/useOs.ts b/web/hooks/useOs.ts deleted file mode 100644 index c4472d54f8..0000000000 --- a/web/hooks/useOs.ts +++ /dev/null @@ -1,57 +0,0 @@ -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( - options.getValueInEffect ? 'undetermined' : getOS() - ) - - useEffect(() => { - if (options.getValueInEffect) { - setValue(getOS) - } - }, []) - - return value -}