- {typeof icon === 'string' && icon.match(/[^\u0000-\u007F]+/) ? (
+ {typeof icon === 'string' && icon.match(/[^\\x00-\\x7F]+/) ? (
{icon}
) : (
icon
@@ -153,6 +151,13 @@ export default function Message({
+ {searchResult && (
+
{`${message.title} | ${message.sender}`}
+ )}
{error ? (
@@ -207,15 +212,13 @@ export default function Message({
visible={!error && isCreatedByUser && !edit && !searchResult}
onClick={() => enterEdit()}
/>
-
+
+
+
diff --git a/client/src/components/Messages/MessageBar.jsx b/client/src/components/Messages/MessageBar.jsx
new file mode 100644
index 0000000000..76611e52a3
--- /dev/null
+++ b/client/src/components/Messages/MessageBar.jsx
@@ -0,0 +1,38 @@
+import React, { useRef, useEffect, useState } from 'react';
+
+const MessageBar = ({ children, dynamicProps, handleWheel, clickSearchResult }) => {
+ const ref = useRef(null);
+ const [isVisible, setIsVisible] = useState(false);
+
+ useEffect(() => {
+ const observer = new IntersectionObserver(
+ ([entry]) => {
+ if (entry.isIntersecting) {
+ setIsVisible(true);
+ observer.unobserve(ref.current);
+ }
+ },
+ { threshold: 0.1 }
+ );
+
+ observer.observe(ref.current);
+
+ return () => {
+ observer.unobserve(ref.current);
+ };
+ }, []);
+
+ return (
+
+ {isVisible ? children : null}
+
+ );
+};
+
+export default MessageBar;
diff --git a/client/src/components/Messages/index.jsx b/client/src/components/Messages/index.jsx
index e38daa679a..030e607941 100644
--- a/client/src/components/Messages/index.jsx
+++ b/client/src/components/Messages/index.jsx
@@ -75,7 +75,7 @@ export default function Messages({ messages, messageTree }) {
Model: {modelName} {customModel ? `(${customModel})` : null}
- {(messageTree.length === 0) ? (
+ {(messageTree.length === 0 || messages.length === 0 || !messages) ? (
) : (
<>
diff --git a/client/src/components/Nav/NewChat.jsx b/client/src/components/Nav/NewChat.jsx
index 90fb88b869..fae7c35ec2 100644
--- a/client/src/components/Nav/NewChat.jsx
+++ b/client/src/components/Nav/NewChat.jsx
@@ -1,9 +1,10 @@
import React from 'react';
import { useDispatch } from 'react-redux';
-import { setNewConvo } from '~/store/convoSlice';
+import { setNewConvo, refreshConversation } from '~/store/convoSlice';
import { setMessages } from '~/store/messageSlice';
-import { setSubmission } from '~/store/submitSlice';
+import { setSubmission, setDisabled } from '~/store/submitSlice';
import { setText } from '~/store/textSlice';
+import { setInputValue, setQuery } from '~/store/searchSlice';
export default function NewChat() {
const dispatch = useDispatch();
@@ -12,7 +13,11 @@ export default function NewChat() {
dispatch(setText(''));
dispatch(setMessages([]));
dispatch(setNewConvo());
+ dispatch(refreshConversation());
dispatch(setSubmission({}));
+ dispatch(setDisabled(false));
+ dispatch(setInputValue(''));
+ dispatch(setQuery(''));
};
return (
diff --git a/client/src/components/Nav/SearchBar.jsx b/client/src/components/Nav/SearchBar.jsx
index ddbe74ee2c..7aac29b5d1 100644
--- a/client/src/components/Nav/SearchBar.jsx
+++ b/client/src/components/Nav/SearchBar.jsx
@@ -1,12 +1,13 @@
-import React, { useState, useCallback } from 'react';
+import React, { useCallback } from 'react';
import { debounce } from 'lodash';
-import { useDispatch } from 'react-redux';
+import { useSelector, useDispatch } from 'react-redux';
import { Search } from 'lucide-react';
-import { setQuery } from '~/store/searchSlice';
+import { setInputValue, setQuery } from '~/store/searchSlice';
export default function SearchBar({ fetch, clearSearch }) {
const dispatch = useDispatch();
- const [inputValue, setInputValue] = useState('');
+ const { inputValue } = useSelector((state) => state.search);
+ // const [inputValue, setInputValue] = useState('');
const debouncedChangeHandler = useCallback(
debounce((q) => {
@@ -28,10 +29,9 @@ export default function SearchBar({ fetch, clearSearch }) {
}
};
-
const changeHandler = (e) => {
let q = e.target.value;
- setInputValue(q);
+ dispatch(setInputValue(q));
q = q.trim();
if (q === '') {
diff --git a/client/src/components/Nav/index.jsx b/client/src/components/Nav/index.jsx
index 4e59cc8661..97ee1b1b32 100644
--- a/client/src/components/Nav/index.jsx
+++ b/client/src/components/Nav/index.jsx
@@ -54,8 +54,10 @@ export default function Nav({ navVisible, setNavVisible }) {
const clearSearch = () => {
setPage(1);
dispatch(refreshConversation());
- dispatch(setNewConvo());
- dispatch(setMessages([]));
+ if (!conversationId) {
+ dispatch(setNewConvo());
+ dispatch(setMessages([]));
+ }
dispatch(setDisabled(false));
};
diff --git a/client/src/mobile.css b/client/src/mobile.css
index fff8d5a91d..65a1db35ed 100644
--- a/client/src/mobile.css
+++ b/client/src/mobile.css
@@ -22,11 +22,17 @@
}
@media (min-width: 1024px) {
- .sibling-switch-container {
+ .switch-container {
display: none;
}
}
+
+ .switch-result {
+ display: block !important;
+ visibility: visible;
+ }
+
@media (max-width: 1024px) {
/* .sibling-switch {
left: 114px;
diff --git a/client/src/store/convoSlice.js b/client/src/store/convoSlice.js
index f0c5de2042..e8da18bb3b 100644
--- a/client/src/store/convoSlice.js
+++ b/client/src/store/convoSlice.js
@@ -17,14 +17,15 @@ const initialState = {
refreshConvoHint: 0,
search: false,
latestMessage: null,
- convos: []
+ convos: [],
+ convoMap: {},
};
const currentSlice = createSlice({
name: 'convo',
initialState,
reducers: {
- refreshConversation: (state, action) => {
+ refreshConversation: (state) => {
state.refreshConvoHint = state.refreshConvoHint + 1;
},
setConversation: (state, action) => {
@@ -69,6 +70,13 @@ const currentSlice = createSlice({
} else {
state.convos = convos.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
}
+
+ // state.convoMap = convos.reduce((acc, curr) => {
+ // acc[curr.conversationId] = { ...curr };
+ // delete acc[curr.conversationId].conversationId;
+ // return acc;
+ // }, {});
+
},
setPages: (state, action) => {
state.pages = action.payload;
diff --git a/client/src/store/searchSlice.js b/client/src/store/searchSlice.js
index ef95a926a7..d53c0eea62 100644
--- a/client/src/store/searchSlice.js
+++ b/client/src/store/searchSlice.js
@@ -4,12 +4,16 @@ const initialState = {
searchEnabled: false,
search: false,
query: '',
+ inputValue: '',
};
const currentSlice = createSlice({
name: 'search',
initialState,
reducers: {
+ setInputValue: (state, action) => {
+ state.inputValue = action.payload;
+ },
setSearchState: (state, action) => {
state.searchEnabled = action.payload;
},
@@ -26,6 +30,6 @@ const currentSlice = createSlice({
}
});
-export const { setSearchState, setQuery } = currentSlice.actions;
+export const { setInputValue, setSearchState, setQuery } = currentSlice.actions;
export default currentSlice.reducer;
diff --git a/client/src/utils/buildTree.js b/client/src/utils/buildTree.js
index 00fe2b134d..fd85c9d078 100644
--- a/client/src/utils/buildTree.js
+++ b/client/src/utils/buildTree.js
@@ -21,31 +21,32 @@ export default function buildTree(messages, groupAll = false) {
}
// Group all messages into one tree
- // let parentId = null;
- // messages.forEach((message, i) => {
- // messageMap[message.messageId] = { ...message, bg: i % 2 === 0 ? even : odd, children: [] };
- // const currentMessage = messageMap[message.messageId];
- // const parentMessage = messageMap[parentId];
- // if (parentMessage) parentMessage.children.push(currentMessage);
- // else rootMessages.push(currentMessage);
- // parentId = message.messageId;
- // });
-
- // return rootMessages;
-
- // Group all messages by conversation
- // Traverse the messages array and store each element in messageMap.
- rootMessages = {};
- let parents = 0;
- messages.forEach(message => {
- if (message.conversationId in messageMap) {
- messageMap[message.conversationId].children.push(message);
- } else {
- messageMap[message.conversationId] = { ...message, bg: parents % 2 === 0 ? even : odd, children: [] };
- rootMessages[message.conversationId] = messageMap[message.conversationId];
- parents++;
- }
+ let parentId = null;
+ messages.forEach((message, i) => {
+ messageMap[message.messageId] = { ...message, bg: i % 2 === 0 ? even : odd, children: [] };
+ const currentMessage = messageMap[message.messageId];
+ const parentMessage = messageMap[parentId];
+ if (parentMessage) parentMessage.children.push(currentMessage);
+ else rootMessages.push(currentMessage);
+ parentId = message.messageId;
});
- return Object.values(rootMessages);
+ return rootMessages;
+
+ // Group all messages by conversation, doesn't look great
+ // Traverse the messages array and store each element in messageMap.
+ // rootMessages = {};
+ // let parents = 0;
+ // messages.forEach(message => {
+ // if (message.conversationId in messageMap) {
+ // messageMap[message.conversationId].children.push(message);
+ // } else {
+ // messageMap[message.conversationId] = { ...message, bg: parents % 2 === 0 ? even : odd, children: [] };
+ // rootMessages.push(messageMap[message.conversationId]);
+ // parents++;
+ // }
+ // });
+
+ // // return Object.values(rootMessages);
+ // return rootMessages;
}