Skip to content

Commit ebf9512

Browse files
committed
Next 14
1 parent f44c7f6 commit ebf9512

File tree

12 files changed

+187
-135
lines changed

12 files changed

+187
-135
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [2.0.0] 2024-02-06
4+
5+
### Next 14
6+
7+
Updated Next
8+
39
## [1.0.0] 2023-06-20
410

511
### Official Release

app/AppWrappers.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use client';
2+
import React, { ReactNode } from 'react';
3+
import '@/styles/App.css';
4+
import '@/styles/Contact.css';
5+
import '@/styles/Plugins.css';
6+
import '@/styles/MiniCalendar.css';
7+
import { ChakraProvider } from '@chakra-ui/react';
8+
9+
// import dynamic from 'next/dynamic';
10+
import theme from '@/theme/theme';
11+
12+
const _NoSSR = ({ children }: any) => (
13+
<React.Fragment>{children}</React.Fragment>
14+
);
15+
16+
// const NoSSR = dynamic(() => Promise.resolve(_NoSSR), {
17+
// ssr: false,
18+
// });
19+
20+
export default function AppWrappers({ children }: { children: ReactNode }) {
21+
return (
22+
// <NoSSR>
23+
<ChakraProvider theme={theme}>{children}</ChakraProvider>
24+
// </NoSSR>
25+
);
26+
}

app/api/chatAPI/route.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { ChatBody } from '@/types/types';
2+
import { OpenAIStream } from '@/utils/chatStream';
3+
4+
export const runtime = 'edge';
5+
6+
export async function GET(req: Request): Promise<Response> {
7+
try {
8+
const { inputCode, model, apiKey } = (await req.json()) as ChatBody;
9+
10+
let apiKeyFinal;
11+
if (apiKey) {
12+
apiKeyFinal = apiKey;
13+
} else {
14+
apiKeyFinal = process.env.NEXT_PUBLIC_OPENAI_API_KEY;
15+
}
16+
17+
const stream = await OpenAIStream(inputCode, model, apiKeyFinal);
18+
19+
return new Response(stream);
20+
} catch (error) {
21+
console.error(error);
22+
return new Response('Error', { status: 500 });
23+
}
24+
}
25+
26+
export async function POST(req: Request): Promise<Response> {
27+
try {
28+
const { inputCode, model, apiKey } = (await req.json()) as ChatBody;
29+
30+
let apiKeyFinal;
31+
if (apiKey) {
32+
apiKeyFinal = apiKey;
33+
} else {
34+
apiKeyFinal = process.env.NEXT_PUBLIC_OPENAI_API_KEY;
35+
}
36+
37+
const stream = await OpenAIStream(inputCode, model, apiKeyFinal);
38+
39+
return new Response(stream);
40+
} catch (error) {
41+
console.error(error);
42+
return new Response('Error', { status: 500 });
43+
}
44+
}

app/head.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
export default function RootHead() {
4+
return (
5+
<>
6+
<title>Horizon AI Template Free</title>
7+
</>
8+
);
9+
}

app/layout.tsx

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
'use client';
2+
import React, { ReactNode } from 'react';
3+
import type { AppProps } from 'next/app';
4+
import { ChakraProvider, Box, Portal, useDisclosure } from '@chakra-ui/react';
5+
import theme from '@/theme/theme';
6+
import routes from '@/routes';
7+
import Sidebar from '@/components/sidebar/Sidebar';
8+
import Footer from '@/components/footer/FooterAdmin';
9+
import Navbar from '@/components/navbar/NavbarAdmin';
10+
import { getActiveRoute, getActiveNavbar } from '@/utils/navigation';
11+
import { usePathname } from 'next/navigation';
12+
import { useEffect, useState } from 'react';
13+
import '@/styles/App.css';
14+
import '@/styles/Contact.css';
15+
import '@/styles/Plugins.css';
16+
import '@/styles/MiniCalendar.css';
17+
import AppWrappers from './AppWrappers';
18+
19+
export default function RootLayout({ children }: { children: ReactNode }) {
20+
const pathname = usePathname();
21+
const [apiKey, setApiKey] = useState('');
22+
const { isOpen, onOpen, onClose } = useDisclosure();
23+
useEffect(() => {
24+
const initialKey = localStorage.getItem('apiKey');
25+
console.log(initialKey);
26+
if (initialKey?.includes('sk-') && apiKey !== initialKey) {
27+
setApiKey(initialKey);
28+
}
29+
}, [apiKey]);
30+
31+
return (
32+
<html lang="en">
33+
<body id={'root'}>
34+
<AppWrappers>
35+
{/* <ChakraProvider theme={theme}> */}
36+
{pathname?.includes('register') || pathname?.includes('sign-in') ? (
37+
children
38+
) : (
39+
<Box>
40+
<Sidebar setApiKey={setApiKey} routes={routes} />
41+
<Box
42+
pt={{ base: '60px', md: '100px' }}
43+
float="right"
44+
minHeight="100vh"
45+
height="100%"
46+
overflow="auto"
47+
position="relative"
48+
maxHeight="100%"
49+
w={{ base: '100%', xl: 'calc( 100% - 290px )' }}
50+
maxWidth={{ base: '100%', xl: 'calc( 100% - 290px )' }}
51+
transition="all 0.33s cubic-bezier(0.685, 0.0473, 0.346, 1)"
52+
transitionDuration=".2s, .2s, .35s"
53+
transitionProperty="top, bottom, width"
54+
transitionTimingFunction="linear, linear, ease"
55+
>
56+
<Portal>
57+
<Box>
58+
<Navbar
59+
setApiKey={setApiKey}
60+
onOpen={onOpen}
61+
logoText={'Horizon UI Dashboard PRO'}
62+
brandText={getActiveRoute(routes, pathname)}
63+
secondary={getActiveNavbar(routes, pathname)}
64+
/>
65+
</Box>
66+
</Portal>
67+
<Box
68+
mx="auto"
69+
p={{ base: '20px', md: '30px' }}
70+
pe="20px"
71+
minH="100vh"
72+
pt="50px"
73+
>
74+
{children}
75+
{/* <Component apiKeyApp={apiKey} {...pageProps} /> */}
76+
</Box>
77+
<Box>
78+
<Footer />
79+
</Box>
80+
</Box>
81+
</Box>
82+
)}
83+
{/* </ChakraProvider> */}
84+
</AppWrappers>
85+
</body>
86+
</html>
87+
);
88+
}

pages/index.tsx renamed to app/page.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
Button,
1515
Flex,
1616
Icon,
17-
Image,
1817
Img,
1918
Input,
2019
Text,
@@ -25,8 +24,6 @@ import { MdAutoAwesome, MdBolt, MdEdit, MdPerson } from 'react-icons/md';
2524
import Bg from '../public/img/chat/bg-image.png';
2625

2726
export default function Chat(props: { apiKeyApp: string }) {
28-
// *** If you use .env.local variable for your API key, method which we recommend, use the apiKey variable commented below
29-
const { apiKeyApp } = props;
3027
// Input States
3128
const [inputOnSubmit, setInputOnSubmit] = useState<string>('');
3229
const [inputCode, setInputCode] = useState<string>('');
@@ -59,13 +56,13 @@ export default function Chat(props: { apiKeyApp: string }) {
5956
{ color: 'whiteAlpha.600' },
6057
);
6158
const handleTranslate = async () => {
62-
const apiKey = apiKeyApp;
59+
let apiKey = localStorage.getItem('apiKey');
6360
setInputOnSubmit(inputCode);
6461

6562
// Chat post conditions(maximum number of characters, valid message etc.)
6663
const maxCodeLength = model === 'gpt-3.5-turbo' ? 700 : 700;
6764

68-
if (!apiKeyApp?.includes('sk-') && !apiKey?.includes('sk-')) {
65+
if (!apiKey?.includes('sk-')) {
6966
alert('Please enter an API key.');
7067
return;
7168
}
@@ -91,7 +88,7 @@ export default function Chat(props: { apiKeyApp: string }) {
9188
};
9289

9390
// -------------- Fetch --------------
94-
const response = await fetch('/api/chatAPI', {
91+
const response = await fetch('./api/chatAPI', {
9592
method: 'POST',
9693
headers: {
9794
'Content-Type': 'application/json',
@@ -392,8 +389,7 @@ export default function Chat(props: { apiKeyApp: string }) {
392389
_hover={{
393390
boxShadow:
394391
'0px 21px 27px -10px rgba(96, 60, 255, 0.48) !important',
395-
bg:
396-
'linear-gradient(15.46deg, #4A25E1 26.3%, #7B5AFF 86.4%) !important',
392+
bg: 'linear-gradient(15.46deg, #4A25E1 26.3%, #7B5AFF 86.4%) !important',
397393
_disabled: {
398394
bg: 'linear-gradient(15.46deg, #4A25E1 26.3%, #7B5AFF 86.4%)',
399395
},

next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const nextConfig = {
55
swcMinify: true,
66
basePath: process.env.NEXT_PUBLIC_BASE_PATH,
77
assetPrefix: process.env.NEXT_PUBLIC_BASE_PATH,
8+
reactStrictMode: false, // changed this to false
89
images: {
910
domains: [
1011
'images.unsplash.com',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"endent": "^2.1.0",
3232
"eventsource-parser": "^1.0.0",
3333
"framer-motion": "^4.1.17",
34-
"next": "13.2.4",
34+
"next": "14.0.2",
3535
"react": "18.2.0",
3636
"react-build-sitemap": "^0.2.2",
3737
"react-custom-scrollbars-2": "^4.2.1",

pages/_app.tsx

Lines changed: 0 additions & 76 deletions
This file was deleted.

pages/_document.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)