Skip to content

Commit

Permalink
Merge branch 'rename-title-flow' into 'dev'
Browse files Browse the repository at this point in the history
Fixed usememo issue by using null checks

See merge request hpc-team/scalable-ai/chat-ai!58
  • Loading branch information
Ali Doost Hosseini committed Dec 18, 2024
2 parents 1c64d08 + dfebd26 commit ec13337
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions front/src/Redux/reducers/conversationsSlice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const conversationsSlice = createSlice({
},
updateConversation: (state, action) => {
const { id, updates } = action.payload;
const conversation = state.conversations.find((conv) => conv.id === id);
const conversation = state.conversations?.find((conv) => conv.id === id);
if (conversation) {
// Ensure system message remains at the start when updating conversation array
if (updates.conversation) {
Expand Down Expand Up @@ -134,7 +134,7 @@ export const selectConversations = (state) => state.conversations.conversations;
export const selectCurrentConversationId = (state) =>
state.conversations.currentConversationId;
export const selectCurrentConversation = (state) =>
state.conversations.conversations.find(
state?.conversations?.conversations?.find(
(conv) => conv.id === state.conversations.currentConversationId
);

Expand Down
6 changes: 3 additions & 3 deletions front/src/components/Layout/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ function Header({
const dropdownRef = useRef(null);

// Computed properties using useMemo

const currentModel = useMemo(
() => modelList.find((m) => m.name === modelSettings.model),
[modelList, modelSettings.model]
() => modelList?.find((m) => m.name === modelSettings?.model),
[modelList, modelSettings?.model]
);

const isImageSupported = useMemo(
() => currentModel?.input.includes("image") || false,
[currentModel]
Expand Down
4 changes: 2 additions & 2 deletions front/src/components/Layout/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function Layout() {
}, [currentConversation]);

useEffect(() => {
const currentModel = modelList.find(
const currentModel = modelList?.find(
(modelX) => modelX.name === modelSettings.model
);
if (currentModel?.status === "offline") {
Expand Down Expand Up @@ -346,7 +346,7 @@ function Layout() {
showModel={setShowRenameModal}
conversationId={renamingConversationId}
currentTitle={
conversations.find((conv) => conv.id === renamingConversationId)
conversations?.find((conv) => conv.id === renamingConversationId)
?.title || ""
}
onClose={() => {
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/Layout/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Sidebar({
<div className="flex-1 overflow-y-auto p-2">
<div className="space-y-2">
{conversationIds.map((id) => {
const conv = conversations.find((c) => c.id === id);
const conv = conversations?.find((c) => c.id === id);
if (!conv) return null;

return (
Expand Down
14 changes: 7 additions & 7 deletions front/src/components/Prompt.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function Prompt({ modelSettings, modelList, onModelChange }) {
(state) => state.conversations.currentConversationId
);
const currentConversation = useSelector((state) =>
state.conversations.conversations.find((conv) => conv.id === conversationId)
state.conversations?.conversations?.find((conv) => conv.id === conversationId)
);

const [localState, setLocalState] = useState({
Expand Down Expand Up @@ -229,11 +229,11 @@ function Prompt({ modelSettings, modelList, onModelChange }) {
const [shareSettingsModel, setShareSettingsModel] = useState(false);
const [systemPromptError, setSystemPromptError] = useState("");
// Computed properties using useMemo

const currentModel = useMemo(
() => modelList.find((m) => m.name === modelSettings.model),
[modelList, modelSettings.model]
() => modelList?.find((m) => m.name === modelSettings?.model),
[modelList, modelSettings?.model]
);

const isImageSupported = useMemo(
() => currentModel?.input.includes("image") || false,
[currentModel]
Expand Down Expand Up @@ -1920,7 +1920,7 @@ function Prompt({ modelSettings, modelList, onModelChange }) {
}
}

const systemMessage = parsedData.messages.find(
const systemMessage = parsedData?.messages?.find(
(message) => message.role === "system"
);

Expand Down Expand Up @@ -1967,7 +1967,7 @@ function Prompt({ modelSettings, modelList, onModelChange }) {
}
}

const systemMessage = parsedData.find(
const systemMessage = parsedData?.find(
(message) => message.role === "system"
);

Expand Down Expand Up @@ -2051,7 +2051,7 @@ function Prompt({ modelSettings, modelList, onModelChange }) {
top_p: 0.05,
},
}));
const currentConversation = conversations.find(
const currentConversation = conversations?.find(
(conv) => conv.id === currentConversationId
);
dispatch(
Expand Down

0 comments on commit ec13337

Please sign in to comment.