From aa28a1b1f13113583e335f9db5213cd1f293dfdf Mon Sep 17 00:00:00 2001 From: Soy Zhou Date: Mon, 25 Sep 2023 14:08:40 +0800 Subject: [PATCH 1/2] fix: type error --- pages/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.tsx b/pages/index.tsx index e87cabb..a34fc19 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -107,7 +107,7 @@ const Index: React.FC = () => {
{ - options && options.map(option => ( + options && options.map((option: { label: string, custom: string }) => ( ]; return [ + , - - - - ) + + {useMainLayout ? + MainLayout( + <> + + + + ) : ( + <> + + + + ) + } + ); } diff --git a/pages/index.tsx b/pages/index.tsx index a34fc19..f9df0e6 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,183 +1,29 @@ -import React, { useState } from "react"; -import { Input, Button, List, Image, Typography, Skeleton } from "antd"; -import { SendOutlined } from "@ant-design/icons"; -import { Imagine, Custom } from "../request"; -import { MJMessage } from "midjourney"; -import { Message } from "../interfaces/message"; - -const { TextArea } = Input; -const { Text } = Typography; +import React, { useContext, useEffect } from "react"; +import { Divider, Typography } from "antd"; +import AuthContext from "../stores/authContext"; +import { useRouter } from 'next/router'; const Index: React.FC = () => { - const [inputValue, setInputValue] = useState(""); - const [inputDisable, setInputDisable] = useState(false); - const [messages, setMessages] = useState([]); - - const handleMessageSend = async () => { - let newMessage: Message = { - text: inputValue.trim(), - prompt: inputValue.trim(), - progress: "waiting start", - img: "", - }; - - if (newMessage.text) { - const oldMessages = messages; - setInputDisable(true); - setMessages([...oldMessages, newMessage]); - await Imagine( - JSON.stringify({ prompt: newMessage.text }), - (data: MJMessage) => { - console.log(data); - newMessage.img = data.uri; - newMessage.msgHash = data.hash; - newMessage.msgID = data.id; - newMessage.progress = data.progress; - newMessage.content = data.content; - newMessage.flags = data.flags; - newMessage.options = data.options; - setMessages([...oldMessages, newMessage]); - } - ); - setInputValue(""); - setInputDisable(false); - } - }; + const router = useRouter(); + const { user, login, authReady } = useContext(AuthContext); - const clickLabel = async (content: string, msgId: string, flags: string, customId: string, label: string, prompt?: string) => { - let newMessage: Message = { - text: `${content} ${label}`, - prompt, - progress: "waiting start", - img: "", - }; - - const oldMessages = messages; - setInputDisable(true); - setMessages([...oldMessages, newMessage]); - await Custom( - JSON.stringify({ content, msgId, flags, customId, label }), - (data: MJMessage) => { - newMessage.img = data.uri; - newMessage.msgHash = data.hash; - newMessage.msgID = data.id; - newMessage.content = data.content; - newMessage.progress = data.progress; - newMessage.flags = data.flags; - newMessage.options = data.options; - setMessages([...oldMessages, newMessage]); - } - ); - setInputDisable(false); - } - const renderMessage = ({ - text, - img, - flags, - msgID, - progress, - content, - options, - prompt, - }: Message) => { - if (process.env.NEXT_PUBLIC_IMAGE_PREFIX) { - img = img.replace( - "https://cdn.discordapp.com/", - process.env.NEXT_PUBLIC_IMAGE_PREFIX - ); + useEffect(() => { + if (authReady && user) { + router.push('/midjourney'); } - return ( - - - {text} {`(${progress})`} - - - { - img ? ( - - ) : ( - - ) - } - -
- { - options && options.map((option: { label: string, custom: string }) => ( - - )) - } -
-
- ); - }; + }, [authReady, login, router, user]); return ( -
- -
-