twa add
This commit is contained in:
parent
4a910fc576
commit
8c152a47bd
@ -1,16 +1,16 @@
|
||||
{
|
||||
"pages": {
|
||||
"/page": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/page.js"
|
||||
],
|
||||
"/layout": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/css/app/layout.css",
|
||||
"static/chunks/app/layout.js"
|
||||
],
|
||||
"/page": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/page.js"
|
||||
],
|
||||
"/not-found": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
|
BIN
.next/cache/webpack/client-development/1.pack.gz
vendored
BIN
.next/cache/webpack/client-development/1.pack.gz
vendored
Binary file not shown.
BIN
.next/cache/webpack/client-development/index.pack.gz
vendored
BIN
.next/cache/webpack/client-development/index.pack.gz
vendored
Binary file not shown.
Binary file not shown.
BIN
.next/cache/webpack/server-development/0.pack.gz
vendored
BIN
.next/cache/webpack/server-development/0.pack.gz
vendored
Binary file not shown.
BIN
.next/cache/webpack/server-development/index.pack.gz
vendored
BIN
.next/cache/webpack/server-development/index.pack.gz
vendored
Binary file not shown.
17
app/components/ClientOnly.tsx
Normal file
17
app/components/ClientOnly.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export default function ClientOnly({ children }: { children: React.ReactNode }) {
|
||||
const [hasMounted, setHasMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setHasMounted(true);
|
||||
}, []);
|
||||
|
||||
if (!hasMounted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
@ -9,6 +9,7 @@ import { auth, getProfile, getShopItems, purchaseItem, transferBalance } from '.
|
||||
import { IUser } from '../../backend/models/User';
|
||||
import { IShopItem } from '../../backend/models/ShopItem';
|
||||
import { isDemoMode, getDemoWebApp } from '../utils/demo';
|
||||
import WebApp from '@twa-dev/sdk';
|
||||
|
||||
type SafeUser = Omit<IUser, keyof Document>;
|
||||
|
||||
@ -25,9 +26,10 @@ export default function MainApp() {
|
||||
let webApp;
|
||||
if (isDemoMode()) {
|
||||
webApp = getDemoWebApp();
|
||||
} else {
|
||||
const WebApp = (await import('@twa-dev/sdk')).default;
|
||||
} else if (typeof window !== 'undefined') {
|
||||
webApp = WebApp;
|
||||
} else {
|
||||
throw new Error('Приложение должно быть открыто в браузере');
|
||||
}
|
||||
|
||||
// Авторизация пользователя
|
||||
|
13
app/page.tsx
13
app/page.tsx
@ -1,5 +1,14 @@
|
||||
import MainApp from './components/MainApp';
|
||||
import dynamic from 'next/dynamic';
|
||||
import ClientOnly from './components/ClientOnly';
|
||||
|
||||
const MainApp = dynamic(() => import('./components/MainApp'), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
export default function Home() {
|
||||
return <MainApp />;
|
||||
return (
|
||||
<ClientOnly>
|
||||
<MainApp />
|
||||
</ClientOnly>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user