passed all console log in a function
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { layout, msgs, user, current_room } from './Store_chat';
|
||||
import { change_room, get_room_messages, get_my_rooms } from './Request_rooms';
|
||||
import { to_print } from './Utils_chat';
|
||||
import { onMount } from 'svelte';
|
||||
import Button from './Element_button.svelte';
|
||||
|
||||
@@ -10,9 +11,9 @@
|
||||
// go to clicked room
|
||||
async function go_to_room(room)
|
||||
{
|
||||
console.log("inside go_to_room");
|
||||
to_print("inside go_to_room");
|
||||
|
||||
console.log("room:", room);
|
||||
to_print("room:", room);
|
||||
if (room.protection && !room.allowed)
|
||||
{
|
||||
await current_room.set(room);
|
||||
@@ -55,7 +56,7 @@
|
||||
<p>rooms are loading...</p>
|
||||
{:then rooms}
|
||||
{#each rooms as room}
|
||||
<Button my_class="list" on:click={function() {go_to_room(room)}}>
|
||||
<Button my_class="list" on:click={function(){go_to_room(room)}}>
|
||||
{room.client_name}
|
||||
</Button>
|
||||
{/each}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { layout, user, current_room } from './Store_chat';
|
||||
import { get_all_users, invite_user } from './Request_rooms';
|
||||
import { to_print } from './Utils_chat';
|
||||
import Button from './Element_button.svelte';
|
||||
|
||||
export let back = "";
|
||||
@@ -11,7 +12,7 @@
|
||||
// invite user in this room
|
||||
async function invite_this_user(username: string)
|
||||
{
|
||||
console.log("inside invite_this_user");
|
||||
to_print("inside invite_this_user");
|
||||
|
||||
invite_user(username);
|
||||
layout.set("room");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { layout, msgs, user, socket, current_room } from './Store_chat';
|
||||
import { join_room, change_room, get_room_messages, get_all_rooms } from './Request_rooms';
|
||||
import { to_print } from './Utils_chat';
|
||||
import Button from './Element_button.svelte';
|
||||
|
||||
export let back = "";
|
||||
@@ -11,7 +12,7 @@
|
||||
// join the room
|
||||
async function join_rooms(room)
|
||||
{
|
||||
console.log("inside join_room");
|
||||
to_print("inside join_room");
|
||||
|
||||
const updated_room = await join_room(room);
|
||||
if (updated_room.protection)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { layout, current_room } from './Store_chat';
|
||||
import { change_room, validate_password, change_password, add_password, remove_password } from './Request_rooms';
|
||||
import type { FetchResponse } from './Types_chat';
|
||||
import { to_print } from './Utils_chat';
|
||||
import Button from './Element_button.svelte';
|
||||
import Warning from './Element_warning.svelte';
|
||||
|
||||
@@ -22,7 +23,7 @@
|
||||
|
||||
async function handleSubmit(evt)
|
||||
{
|
||||
console.log("in handleSubmit");
|
||||
to_print("in handleSubmit");
|
||||
|
||||
let formIsValid = evt.target.checkValidity();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { layout, current_room, settings_user } from './Store_chat';
|
||||
import { get_room_users, leave_room, get_is_admin } from './Request_rooms';
|
||||
import { to_print } from './Utils_chat';
|
||||
import Button from './Element_button.svelte';
|
||||
|
||||
export let back = "";
|
||||
@@ -10,18 +11,18 @@
|
||||
let is_admin = false;
|
||||
get_is_admin().then(response => is_admin = response);
|
||||
|
||||
console.log("current_room:", $current_room);
|
||||
to_print("current_room:", $current_room);
|
||||
|
||||
function user_profile(username: string)
|
||||
{
|
||||
console.log("in user_profile");
|
||||
to_print("in user_profile");
|
||||
settings_user.set(username);
|
||||
layout.set("user");
|
||||
}
|
||||
|
||||
function user_leave_room()
|
||||
{
|
||||
console.log("in leave_room");
|
||||
to_print("in leave_room");
|
||||
leave_room();
|
||||
layout.set("home");
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { msgs, user, layout, socket, current_room } from './Store_chat';
|
||||
import type { Room, FetchResponse } from './Types_chat';
|
||||
import { FetchMethod } from './Utils_chat';
|
||||
import { FetchMethod } from './Types_chat';
|
||||
import { to_print } from './Utils_chat';
|
||||
import { fetch_chat_request, set_client_name_on_room, fill_fetch_response } from './Request_utils';
|
||||
|
||||
export async function get_room_messages()
|
||||
{
|
||||
console.log("in get_room_messages");
|
||||
to_print("in get_room_messages");
|
||||
|
||||
let response: FetchResponse = await fetch_chat_request('messages', FetchMethod.GET);
|
||||
|
||||
@@ -24,33 +25,33 @@ export async function get_room_messages()
|
||||
|
||||
export async function create_room(room: Room)
|
||||
{
|
||||
console.log("in create_room");
|
||||
to_print("in create_room");
|
||||
|
||||
console.log("room sent to create:", room);
|
||||
to_print("room sent to create:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('create', FetchMethod.POST, room);
|
||||
console.log("room returned from create:", response.room);
|
||||
to_print("room returned from create:", response.room);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function join_room(room: Room)
|
||||
{
|
||||
console.log("in join_room");
|
||||
to_print("in join_room");
|
||||
|
||||
console.log("room sent to join:", room);
|
||||
to_print("room sent to join:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('join', FetchMethod.POST, room);
|
||||
console.log("room returned from join:", response.room);
|
||||
to_print("room returned from join:", response.room);
|
||||
|
||||
return response.room;
|
||||
}
|
||||
|
||||
export async function change_room(room: Room)
|
||||
{
|
||||
console.log("in change_room");
|
||||
to_print("in change_room");
|
||||
|
||||
console.log("room sent to change:", room);
|
||||
to_print("room sent to change:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('change', FetchMethod.POST, room);
|
||||
console.log("room returned from change:", response.room);
|
||||
to_print("room returned from change:", response.room);
|
||||
|
||||
await get_room_messages();
|
||||
|
||||
@@ -62,29 +63,29 @@ console.log("room returned from change:", response.room);
|
||||
|
||||
export async function validate_password(room: Room)
|
||||
{
|
||||
console.log("in validate_password");
|
||||
to_print("in validate_password");
|
||||
|
||||
console.log("room sent to validate password:", room);
|
||||
to_print("room sent to validate password:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('passwordauth', FetchMethod.POST, room);
|
||||
console.log("room returned from validate password:", response.room);
|
||||
to_print("room returned from validate password:", response.room);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function add_password(room: Room)
|
||||
{
|
||||
console.log("in add_password");
|
||||
to_print("in add_password");
|
||||
|
||||
console.log("room sent to add password:", room);
|
||||
to_print("room sent to add password:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('addpassword', FetchMethod.POST, room);
|
||||
console.log("room returned from add password:", response.room);
|
||||
to_print("room returned from add password:", response.room);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function change_password(room: Room, old_password: string)
|
||||
{
|
||||
console.log("in send_password");
|
||||
to_print("in send_password");
|
||||
|
||||
let request_body =
|
||||
{
|
||||
@@ -92,27 +93,27 @@ export async function change_password(room: Room, old_password: string)
|
||||
old_password: old_password,
|
||||
}
|
||||
|
||||
console.log("room sent to change password:", room);
|
||||
to_print("room sent to change password:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('changepassword', FetchMethod.POST, request_body);
|
||||
console.log("room returned from change password:", response.room);
|
||||
to_print("room returned from change password:", response.room);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function remove_password(room: Room)
|
||||
{
|
||||
console.log("in send_password");
|
||||
to_print("in send_password");
|
||||
|
||||
console.log("room sent to remove password:", room);
|
||||
to_print("room sent to remove password:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('removepassword', FetchMethod.DELETE, room);
|
||||
console.log("room returned from remove password:", response.room);
|
||||
to_print("room returned from remove password:", response.room);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function invite_user(user_name: string)
|
||||
{
|
||||
console.log("in invite_user");
|
||||
to_print("in invite_user");
|
||||
|
||||
let response: FetchResponse = await fetch_chat_request('invite', FetchMethod.POST, {username: user_name});
|
||||
|
||||
@@ -121,7 +122,7 @@ export async function invite_user(user_name: string)
|
||||
|
||||
export async function get_my_rooms()
|
||||
{
|
||||
console.log("in get_my_rooms");
|
||||
to_print("in get_my_rooms");
|
||||
|
||||
let response: FetchResponse = await fetch_chat_request('myrooms', FetchMethod.GET);
|
||||
|
||||
@@ -132,7 +133,7 @@ export async function get_my_rooms()
|
||||
|
||||
export async function get_all_rooms()
|
||||
{
|
||||
console.log("in get_all_rooms");
|
||||
to_print("in get_all_rooms");
|
||||
|
||||
let response: FetchResponse = await fetch_chat_request('allrooms', FetchMethod.GET);
|
||||
|
||||
@@ -141,7 +142,7 @@ export async function get_all_rooms()
|
||||
|
||||
export async function get_room_users()
|
||||
{
|
||||
console.log("in get_room_users");
|
||||
to_print("in get_room_users");
|
||||
|
||||
let response: FetchResponse = await fetch_chat_request('roomusers', FetchMethod.GET);
|
||||
|
||||
@@ -150,7 +151,7 @@ export async function get_room_users()
|
||||
|
||||
export async function get_all_users()
|
||||
{
|
||||
console.log("in get_all_users");
|
||||
to_print("in get_all_users");
|
||||
|
||||
let response: FetchResponse = await fetch_chat_request('users', FetchMethod.GET);
|
||||
|
||||
@@ -159,17 +160,17 @@ export async function get_all_users()
|
||||
|
||||
export async function leave_room(): Promise<void>
|
||||
{
|
||||
console.log("in leave_room");
|
||||
to_print("in leave_room");
|
||||
|
||||
let response: FetchResponse = await fetch_chat_request('leave', FetchMethod.DELETE);
|
||||
}
|
||||
|
||||
export async function get_is_admin(): Promise<boolean>
|
||||
{
|
||||
console.log("in is_admin");
|
||||
to_print("in is_admin");
|
||||
|
||||
let response: FetchResponse = await fetch_chat_request('isadmin', FetchMethod.GET);
|
||||
console.log("is_admin return:", response.is_admin);
|
||||
to_print("is_admin return:", response.is_admin);
|
||||
|
||||
return response.is_admin;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { user } from './Store_chat';
|
||||
import type { Room, FetchResponse, FetchInit } from './Types_chat';
|
||||
import type { FetchMethod } from './Utils_chat';
|
||||
import type { Room, FetchResponse, FetchInit, FetchMethod } from './Types_chat';
|
||||
import { to_print } from './Utils_chat';
|
||||
|
||||
export async function fetch_chat_request(route: string, fetchMethod: FetchMethod, param?: any)
|
||||
{
|
||||
console.log("in fetch_chat_request");
|
||||
to_print("in fetch_chat_request");
|
||||
|
||||
let response: FetchResponse = { status: 0 };
|
||||
|
||||
@@ -36,7 +36,7 @@ export async function fetch_chat_request(route: string, fetchMethod: FetchMethod
|
||||
|
||||
export function set_client_name_on_room(room: Room)
|
||||
{
|
||||
console.log("in set_client_name_on_room");
|
||||
to_print("in set_client_name_on_room");
|
||||
|
||||
if (room.type === 'direct')
|
||||
{
|
||||
@@ -51,7 +51,7 @@ export function set_client_name_on_room(room: Room)
|
||||
|
||||
export function fill_fetch_response(response: FetchResponse, data: any)
|
||||
{
|
||||
console.log("in fill_fetch_response");
|
||||
to_print("in fill_fetch_response");
|
||||
|
||||
Object.keys(data).forEach(key =>
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import io from 'socket.io-client';
|
||||
import { user, msgs, layout, set_socket, set_user } from './Store_chat';
|
||||
import { to_print } from './Utils_chat';
|
||||
|
||||
const address = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}`;
|
||||
|
||||
@@ -28,7 +29,7 @@ function socket_events(socket)
|
||||
{
|
||||
socket.on('message', function(from, message)
|
||||
{
|
||||
console.log("received msg:", message, from);
|
||||
to_print("received msg:", message, from);
|
||||
if (from === user.username)
|
||||
from = "me";
|
||||
msgs.update(msgs => [...msgs, { name: from, message: message }]);
|
||||
@@ -36,7 +37,7 @@ function socket_events(socket)
|
||||
|
||||
socket.on('new_password', function()
|
||||
{
|
||||
console.log("notification new password:");
|
||||
to_print("notification new password:");
|
||||
layout.set("password");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,3 +34,10 @@ export interface FetchInit
|
||||
body?: string;
|
||||
}
|
||||
|
||||
export enum FetchMethod
|
||||
{
|
||||
POST = 'POST',
|
||||
GET = 'GET',
|
||||
DELETE = 'DELETE',
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
export enum FetchMethod
|
||||
export function to_print(...args)
|
||||
{
|
||||
POST = 'POST',
|
||||
GET = 'GET',
|
||||
DELETE = 'DELETE',
|
||||
console.log(...args);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user