From 0acd073abd72177c6530941f6b65d20d5230e1e3 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 24 Aug 2023 19:30:23 +0600 Subject: [PATCH] fix search --- src/features/Search/ui/SearchInput.tsx | 11 ++++++++++- src/widgets/RoomsList.tsx | 16 ++++++++++------ src/widgets/layout/Navbar.tsx | 4 ++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/features/Search/ui/SearchInput.tsx b/src/features/Search/ui/SearchInput.tsx index 178cb9e..016a724 100644 --- a/src/features/Search/ui/SearchInput.tsx +++ b/src/features/Search/ui/SearchInput.tsx @@ -2,6 +2,8 @@ import React, { useRef } from 'react'; import styled from 'styled-components'; import searchIcon from '../../../../public/icons/search.svg'; import socket from '../../../pages/Lobby/store/socket'; +import navbarState from '../../../pages/Lobby/store/navbarState'; +import { useAuth0 } from "@auth0/auth0-react"; const Container = styled.div` display: flex; @@ -27,10 +29,17 @@ const Input = styled.input` export const SearchInput: React.FC = () => { const dataRef = useRef(null); + const { user } = useAuth0(); const st = socket.state; function inputData(data: any) { - st.send(data); + const message = { + filter: navbarState.state, + search_string: data, + user_email: user?.email + } + console.log(message); + st.send(JSON.stringify(message)); st.close(1, "closed"); } diff --git a/src/widgets/RoomsList.tsx b/src/widgets/RoomsList.tsx index 799071e..fc20a22 100644 --- a/src/widgets/RoomsList.tsx +++ b/src/widgets/RoomsList.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import { IRoom } from '../entities/room/api/models'; import { useRoomsList } from '../entities/room/api/useRoomsList'; import { useMyRooms } from '../entities/room/api/useMyRooms'; @@ -64,11 +64,11 @@ const RoomsList: React.FC = observer(() => { const st = socket.state; - useEffect(() => { - st.onopen = function() { - st.send('connected'); - }; - }, []); + // useEffect(() => { + // st.onopen = function() { + // st.send('connected'); + // }; + // }, []); st.onmessage = function(event) { const response = event.data; @@ -76,6 +76,10 @@ const RoomsList: React.FC = observer(() => { console.log(searchedRooms); }; + useEffect(() => { + setSearchedRooms([]); + }, [navbarState.state]) + return (
diff --git a/src/widgets/layout/Navbar.tsx b/src/widgets/layout/Navbar.tsx index c7d9036..4ce7e97 100644 --- a/src/widgets/layout/Navbar.tsx +++ b/src/widgets/layout/Navbar.tsx @@ -7,6 +7,8 @@ import roomsFormState from '../../pages/Lobby/store/roomsFormState.ts'; import roomsState from '../../pages/Lobby/store/roomsState.ts'; import editIcon from '../../../public/icons/edit.svg'; import navbarState from '../../pages/Lobby/store/navbarState.ts'; +import socket from '../../pages/Lobby/store/socket.ts'; +import { useAuth0 } from "@auth0/auth0-react"; const Container = styled.div` display: flex; @@ -70,6 +72,7 @@ const Navbar: React.FC = observer(() => { } function addRoom() { + navbarState.openMy(); if (roomsFormState.state === '' && navbarState.state === 'my') { roomsFormState.openCreateForm(); return 0; @@ -81,6 +84,7 @@ const Navbar: React.FC = observer(() => { } function editRooms() { + navbarState.openMy(); if (navbarState.state === 'my') { if (roomsState.state === '') { roomsState.openEditForm();