Skip to content

Commit

Permalink
fix search
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil307 committed Aug 24, 2023
1 parent e3cff6a commit 0acd073
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/features/Search/ui/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,10 +29,17 @@ const Input = styled.input`

export const SearchInput: React.FC = () => {
const dataRef = useRef<HTMLInputElement>(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");
}

Expand Down
16 changes: 10 additions & 6 deletions src/widgets/RoomsList.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -64,18 +64,22 @@ 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;
setSearchedRooms(JSON.parse(response as any));
console.log(searchedRooms);
};

useEffect(() => {
setSearchedRooms([]);
}, [navbarState.state])

return (
<Container>
<Header>
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/layout/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 10 in src/widgets/layout/Navbar.tsx

View workflow job for this annotation

GitHub Actions / deploy

'socket' is declared but its value is never read.
import { useAuth0 } from "@auth0/auth0-react";

Check failure on line 11 in src/widgets/layout/Navbar.tsx

View workflow job for this annotation

GitHub Actions / deploy

'useAuth0' is declared but its value is never read.

const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -70,6 +72,7 @@ const Navbar: React.FC = observer(() => {
}

function addRoom() {
navbarState.openMy();
if (roomsFormState.state === '' && navbarState.state === 'my') {
roomsFormState.openCreateForm();
return 0;
Expand All @@ -81,6 +84,7 @@ const Navbar: React.FC = observer(() => {
}

function editRooms() {
navbarState.openMy();
if (navbarState.state === 'my') {
if (roomsState.state === '') {
roomsState.openEditForm();
Expand Down

0 comments on commit 0acd073

Please sign in to comment.