diff --git a/src/backend/api.js b/src/backend/api.js
index 6e34813..48a7ae3 100644
--- a/src/backend/api.js
+++ b/src/backend/api.js
@@ -5,7 +5,7 @@ const LOCAL = "http://localhost:8099";
const DEV = "https://dev.bro-js.ru";
const SERVER = "";
-export const BASE_API_URL = LOCAL + getConfigValue("enterfront.api") + "/enterfront";
+export const BASE_API_URL = DEV + getConfigValue("enterfront.api") + "/enterfront";
// fetch(`${BASE_API_URL}/books/list`)
diff --git a/src/components/home/Search.jsx b/src/components/home/Search.jsx
new file mode 100644
index 0000000..01fdbe0
--- /dev/null
+++ b/src/components/home/Search.jsx
@@ -0,0 +1,11 @@
+import React from 'react';
+
+const Search = (props) => {
+ return (
+ {
+ props.search(props.item);
+ }}>Find
+ );
+};
+
+export default Search;
diff --git a/src/components/home/css/homeTitle.css b/src/components/home/css/homeTitle.css
index 874048f..46f254b 100644
--- a/src/components/home/css/homeTitle.css
+++ b/src/components/home/css/homeTitle.css
@@ -12,11 +12,23 @@
color: orange;
}
+.search-class {
+ margin-top: 2vw;
+ margin-bottom: 4vw;
+
+ display: flex;
+ align-items: center;
+}
+
@media only screen and (max-width: 800px) {
.homeTitle {
font-size: 8vh;
}
+
+ .search-class {
+ margin-top: 3vh;
+ }
}
.chatIcon {
diff --git a/src/components/reg/InputField.jsx b/src/components/reg/InputField.jsx
index c50ddf2..1b7ccca 100644
--- a/src/components/reg/InputField.jsx
+++ b/src/components/reg/InputField.jsx
@@ -8,6 +8,7 @@ const InputField = (props) => {
onChange={(e) => props.setValue(e.target.value)}
value={props.value}
className="Input"
+ placeholder={(props.placeholder) ? props.placeholder : ''}
/>
);
diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx
index a3f1037..794d43f 100644
--- a/src/pages/Home.jsx
+++ b/src/pages/Home.jsx
@@ -4,10 +4,14 @@ import ChatsList from "../components/home/ChatsList.jsx";
import Header from "../components/home/Header.jsx";
import {displayMessage} from "../backend/notifications/notifications";
import {MessageType} from "../backend/notifications/message";
-import {get} from "../backend/api";
+import {get, post} from "../backend/api";
+import InputField from "../components/reg/InputField.jsx";
+import Search from "../components/home/Search.jsx";
+import {URLs} from "../__data__/urls";
const Home = () => {
const [chats, setChats] = useState([])
+ const [interlocutor, setInterlocutor] = useState("")
async function retrieveChats() {
const username = localStorage.getItem("username");
@@ -24,6 +28,23 @@ const Home = () => {
setChats(data.chats);
}
+ async function createChat(alias) {
+ const username = localStorage.getItem("username");
+ if (!username) {
+ displayMessage("You're not logged in!", MessageType.WARN);
+ return;
+ }
+
+ const {ok, data} = await post('/chat/item/' + username + '/' + alias);
+ if (!ok) {
+ displayMessage(data.message, MessageType.ERROR);
+ } else {
+ localStorage.setItem('message', 'Successfully opened chat!');
+ localStorage.setItem('interlocutorId', alias);
+ window.location.href = URLs.chat.url;
+ }
+ }
+
useEffect(() => {retrieveChats().then()}, [])
return (
@@ -33,6 +54,15 @@ const Home = () => {
+
+
+
+
Your chats
diff --git a/stubs/api/chat/index.js b/stubs/api/chat/index.js
index 5ba9ced..06bfec1 100644
--- a/stubs/api/chat/index.js
+++ b/stubs/api/chat/index.js
@@ -2,7 +2,7 @@ const chatRouter = require('express').Router();
module.exports = chatRouter;
-const { getChatFromDB, getUsersChats, addChatToDB } = require('../db');
+const { getChatFromDB, getUsersChats, addChatToDB, getUserFromDB } = require('../db');
chatRouter.get('/item/:id1/:id2', (req, res) => {
const { id1, id2 } = req.params;
@@ -27,16 +27,20 @@ chatRouter.post('/item/:id1/:id2', (req, res) => {
// Chat already exists
res.status(200).send({chat});
} else {
- // Creating new chat
- const newChat = {
- id1: id1,
- id2: id2,
- messages: []
+ if (!getUserFromDB(id1) || !getUserFromDB(id2)) {
+ res.status(404).send({message: 'Such interlocutor does not exist'});
+ } else {
+ // Creating new chat
+ const newChat = {
+ id1: id1,
+ id2: id2,
+ messages: []
+ }
+
+ addChatToDB(newChat);
+
+ res.status(200).send({newChat});
}
-
- addChatToDB(newChat);
-
- res.status(200).send({newChat});
}
})