Skip to content

Commit

Permalink
♻️ refactor: Use hook to check PWA env
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Sep 27, 2023
1 parent a35c379 commit b4234db
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"@emoji-mart/data": "^1",
"@emoji-mart/react": "^1",
"@icons-pack/react-simple-icons": "^9",
"@lobehub/chat-plugin-sdk": "^1.17.7",
"@lobehub/chat-plugins-gateway": "^1.5.3",
"@lobehub/chat-plugin-sdk": "latest",
"@lobehub/chat-plugins-gateway": "latest",
"@lobehub/ui": "latest",
"@vercel/analytics": "^1",
"ahooks": "^3",
Expand All @@ -88,16 +88,16 @@
"lucide-react": "latest",
"nanoid": "^5",
"next": "^13.5.3",
"openai": "^4.10.0",
"openai": "^4",
"polished": "^4",
"react": "^18",
"react-dom": "^18",
"react-hotkeys-hook": "^4",
"react-i18next": "^13",
"react-intersection-observer": "^9",
"react-layout-kit": "^1.7.4",
"react-layout-kit": "^1",
"swr": "^2",
"systemjs": "^6.14.2",
"systemjs": "^6",
"ts-md5": "^1",
"url-join": "^5",
"use-merge-value": "^1",
Expand All @@ -118,7 +118,7 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/systemjs": "^6.13.3",
"@types/systemjs": "^6",
"@types/uuid": "^9",
"@umijs/lint": "^4",
"@vitest/coverage-v8": "latest",
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const RootLayout = ({ children }: PropsWithChildren) => {
const primaryColor = cookieStore.get(LOBE_THEME_PRIMARY_COLOR);

return (
<html lang="en">
<html lang="en-US">
<body>
<StyleRegistry>
<Layout
Expand Down
2 changes: 1 addition & 1 deletion src/app/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const metadata: Metadata = {
width: 960,
},
],
locale: 'en_US',
locale: 'en-US',
siteName: title,
title: title,
type: 'website',
Expand Down
15 changes: 15 additions & 0 deletions src/hooks/useIsPWA.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useEffect, useState } from 'react';

export const useIsPWA = () => {
const [isPWA, setIsPWA] = useState(false);

useEffect(() => {
const isInStandaloneMode = () =>
'standalone' in window.navigator && window.navigator['standalone'];
if (isInStandaloneMode()) {
setIsPWA(true);
}
}, []);

return isPWA;
};
6 changes: 3 additions & 3 deletions src/layout/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { PropsWithChildren, memo } from 'react';
import { Flexbox } from 'react-layout-kit';

import SideBar from '@/features/SideBar';

const isPwa = window.matchMedia('(display-mode: standalone)').matches;
import { useIsPWA } from '@/hooks/useIsPWA';

const AppLayout = memo<PropsWithChildren>(({ children }) => {
const isPWA = useIsPWA();
const theme = useTheme();
return (
<Flexbox
horizontal
style={isPwa ? { borderTop: `1px solid ${theme.colorBorder}` } : {}}
style={isPWA ? { borderTop: `1px solid ${theme.colorBorder}` } : {}}
width={'100%'}
>
<SideBar />
Expand Down

0 comments on commit b4234db

Please sign in to comment.