LibreChat/src/App.jsx

52 lines
1.7 KiB
React
Raw Normal View History

2023-02-05 15:29:35 -05:00
import React, { useState } from 'react';
import Messages from './components/Messages';
2023-02-04 20:48:33 -05:00
import TextChat from './components/TextChat';
2023-02-06 13:27:28 -05:00
import Nav from './components/Nav';
import MobileNav from './components/MobileNav';
import useSWR from 'swr';
2023-02-06 16:28:50 -05:00
import useSWRMutation from 'swr/mutation';
import axios from 'axios';
const fetcher = (url) => fetch(url).then((res) => res.json());
2023-02-04 19:19:53 -05:00
const App = () => {
2023-02-05 15:29:35 -05:00
const [messages, setMessages] = useState([]);
2023-02-06 16:28:50 -05:00
const [convo, setConvo] = useState({ conversationId: null, parentMessageId: null });
const { data, error, isLoading, mutate } = useSWR('http://localhost:3050/convos', fetcher);
2023-02-06 16:28:50 -05:00
const { trigger, isMutating } = useSWRMutation('http://localhost:3050/messages', fetcher, {
onSuccess: function (res) {
console.log('success', res);
// setMessages(res);
}
});
const onConvoClick = (conversationId, parentMessageId) => {
setConvo({ conversationId, parentMessageId });
trigger();
// console.log(e, e.target);
};
2023-02-04 19:19:53 -05:00
return (
<div className="flex h-screen">
2023-02-06 13:27:28 -05:00
{/* <div className="w-80 bg-slate-800"></div> */}
2023-02-06 16:28:50 -05:00
<Nav conversations={data} convoHandler={onConvoClick}/>
2023-02-06 13:27:28 -05:00
{/* <div className="flex h-full flex-1 flex-col md:pl-[260px]"> */}
<div className="flex h-full w-full flex-1 flex-col bg-gray-50 md:pl-[260px]">
{/* <main className="relative h-full w-full transition-width flex flex-col overflow-hidden items-stretch flex-1"> */}
2023-02-06 15:17:54 -05:00
<MobileNav />
<Messages messages={messages} />
2023-02-06 13:27:28 -05:00
<TextChat
messages={messages}
setMessages={setMessages}
reloadConvos={mutate}
2023-02-06 16:28:50 -05:00
convo={convo}
setConvo={setConvo}
2023-02-06 13:27:28 -05:00
/>
{/* </main> */}
2023-02-04 19:19:53 -05:00
</div>
</div>
);
};
export default App;