From 070fee2ece682f6f7649380bb68dece376b4c041 Mon Sep 17 00:00:00 2001
From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech>
Date: Sun, 12 Mar 2023 00:32:03 +0800
Subject: [PATCH] feat: basic support in mobile mode. including: navbar show
and hide, similar fade animation, auto close when select new convo, mobile
title will change with convo, new chat button.
---
client/index.js | 1 +
client/src/App.jsx | 8 +-
client/src/components/Nav/MobileNav.jsx | 25 +++++-
client/src/components/Nav/index.jsx | 104 +++++++++++++++++-------
client/src/mobile.css | 55 +++++++++++++
5 files changed, 160 insertions(+), 33 deletions(-)
create mode 100644 client/src/mobile.css
diff --git a/client/index.js b/client/index.js
index 6b09d493e2..6e1b2c1620 100644
--- a/client/index.js
+++ b/client/index.js
@@ -5,6 +5,7 @@ import { store } from './src/store';
import { ThemeProvider } from './src/hooks/ThemeContext';
import App from './src/App';
import './src/style.css';
+import './src/mobile.css'
const container = document.getElementById('root');
const root = createRoot(container);
diff --git a/client/src/App.jsx b/client/src/App.jsx
index f0d9dd62c6..9bab1f5939 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useEffect, useState } from 'react';
import Messages from './components/Messages';
import Landing from './components/Main/Landing';
import TextChat from './components/Main/TextChat';
@@ -10,14 +10,16 @@ import { useSelector } from 'react-redux';
const App = () => {
const { messages } = useSelector((state) => state.messages);
const { title } = useSelector((state) => state.convo);
+ const { conversationId } = useSelector((state) => state.convo);
+ const [ navVisible, setNavVisible ]= useState(false)
useDocumentTitle(title);
return (
-
+
-
+
{messages.length === 0 ? (
) : (
diff --git a/client/src/components/Nav/MobileNav.jsx b/client/src/components/Nav/MobileNav.jsx
index 79f3c416bc..502850a80e 100644
--- a/client/src/components/Nav/MobileNav.jsx
+++ b/client/src/components/Nav/MobileNav.jsx
@@ -1,11 +1,33 @@
import React from 'react';
+import { useSelector, useDispatch } from 'react-redux';
+import { setNewConvo } from '~/store/convoSlice';
+import { setMessages } from '~/store/messageSlice';
+import { setText } from '~/store/textSlice';
+
+export default function MobileNav({ setNavVisible }) {
+ const dispatch = useDispatch();
+ const { conversationId, convos } = useSelector((state) => state.convo);
+
+ const toggleNavVisible = () => {
+ setNavVisible((prev) => {
+ return !prev
+ })
+ }
+
+ const newConvo = () => {
+ dispatch(setText(''));
+ dispatch(setMessages([]));
+ dispatch(setNewConvo());
+ }
+
+ const title = convos?.find(element => element?.conversationId == conversationId)?.title || 'New Chat';
-export default function MobileNav({ title = 'New Chat' }) {
return (