Browse Source

final_project

Levshin95 1 year ago
parent
commit
18a325ad79
3 changed files with 17 additions and 17 deletions
  1. 16 16
      HW013/index.js
  2. 1 0
      React_верстка/src/App.js
  3. 0 1
      Модуль_JS/index.js

+ 16 - 16
HW013/index.js

@@ -1,17 +1,16 @@
-function jsonPost(url, data)
-{
+function jsonPost(url, data) {
     return new Promise((resolve, reject) => {
-        var x = new XMLHttpRequest();   
+        var x = new XMLHttpRequest();
         x.onerror = () => reject(new Error('jsonPost failed'))
         //x.setRequestHeader('Content-Type', 'application/json');
         x.open("POST", url, true);
         x.send(JSON.stringify(data))
 
         x.onreadystatechange = () => {
-            if (x.readyState == XMLHttpRequest.DONE && x.status == 200){
+            if (x.readyState == XMLHttpRequest.DONE && x.status == 200) {
                 resolve(JSON.parse(x.responseText))
             }
-            else if (x.status != 200){
+            else if (x.status != 200) {
                 reject(new Error('status is not 200'))
             }
         }
@@ -25,25 +24,26 @@ let chat = document.getElementById('chat')
 let messageId = 0;
 
 
-async function sendMessage(nick , message ){
-        await jsonPost("http://students.a-level.com.ua:10012", {
-        func: 'addMessage', 
-        nick: login.value, 
-        message: msg.value})
+async function sendMessage(nick, message) {
+    await jsonPost("http://students.a-level.com.ua:10012", {
+        func: 'addMessage',
+        nick: login.value,
+        message: msg.value
+    })
 }
 
 
-async function getMessages(){
-        jsonPost("http://students.a-level.com.ua:10012", {
+async function getMessages() {
+    jsonPost("http://students.a-level.com.ua:10012", {
         func: "getMessages", messageId: 0
     }).then((a) => {
         showChat(a.data, chat)
     })
 }
 
-function showChat(data, container){
+function showChat(data, container) {
     let sortedData = data.sort((a, b) => b.timestamp - a.timestamp)
-    for(let message of sortedData){
+    for (let message of sortedData) {
         let div = document.createElement('div')
         let spanName = document.createElement('b')
         let spanMsg = document.createElement('span')
@@ -57,10 +57,10 @@ function showChat(data, container){
         spanName.innerHTML = message.nick + ': '
         spanMsg.innerHTML = message.message + '   '
         spanTime.innerHTML = time.toGMTString()
-    } 
+    }
 }
 
-async function sendAndCheck(){
+async function sendAndCheck() {
     sendMessage();
     getMessages();
     msg.value = ""

+ 1 - 0
React_верстка/src/App.js

@@ -10,6 +10,7 @@ import img2 from './img/img2.jpg'
 import microsoft from './img/microsoft.svg'
 import vk from './img/vk.svg'
 
+
 const HeaderItem = ({children = 'Главная', url = '#'}) => 
     <li class="header-item">
         <a href={url}>{children}</a>

+ 0 - 1
Модуль_JS/index.js

@@ -451,7 +451,6 @@ store.subscribe(() => {
         enterLogin.style.display = 'block';
         displayCategory();
     } else {
-        debugger
         enterLogin.style.display = 'none';
         enterCart.style.display = 'block';
         enterLogout.style.display = 'block';