fixed create form

This commit is contained in:
simplonco
2023-01-05 18:56:29 +01:00
parent f0736ab20b
commit 26150f6761
6 changed files with 362 additions and 211 deletions

View File

@@ -1,6 +1,7 @@
import { Controller, UseGuards, Get, Post, Body, Req } from '@nestjs/common';
import { Controller, UseGuards, HttpException, HttpStatus, Get, Post, Body, Req, Res } from '@nestjs/common';
import { AuthenticateGuard, TwoFactorGuard } from 'src/auth/42/guards/42guards';
import { ChatService } from './chat.service';
import { User } from 'src/users/entities/user.entity';
@Controller('chat')
export class ChatController {
@@ -20,22 +21,21 @@ export class ChatController {
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
@Post('join')
async join_room(@Body() body) {
async join_room(@Body() body, @Req() req, @Res() res) {
console.log("------ create :");
console.log(typeof body);
console.log(body);
console.log(body.room_name);
const { room_name } = body;
console.log("room_name:");
console.log(room_name);
//const { room_name } = body;
const { room_id } = body;
// get user
let user;
await this.chatService.addUserToRoom(user, room_id);
//const user: User = req.user;
//const { user } = requete;
// let user;
//let room_name;
//await this.chatService.addUserToRoom(user, room_name);
//return { message: 'Successfully joined room.' };
//return res.status(HttpStatus.BAD_REQUEST).json({message : 'You can\'t grant a ticket to another user'});
return body;
}

View File

@@ -6,10 +6,11 @@ import { UsersModule } from 'src/users/users.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Chatroom } from './entities/chat.entity';
import { User } from 'src/users/entities/user.entity';
@Module({
imports: [
TypeOrmModule.forFeature([Chatroom]),
TypeOrmModule.forFeature([Chatroom, User]),
UsersModule,
],
controllers: [

View File

@@ -1,15 +1,17 @@
import { Injectable } from '@nestjs/common';
import { User } from 'src/users/entities/user.entity';
//import { InjectRepository } from '@nestjs/typeorm';
//import { Repository } from 'typeorm';
import { Chatroom } from './entities/chat.entity';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
@Injectable()
export class ChatService {
constructor(
// @InjectRepository(User)
// private readonly userRepository: Repository<User>,
@InjectRepository(User)
private readonly userRepository: Repository<User>,
@InjectRepository(Chatroom)
private readonly chatroomRepository: Repository<Chatroom>,
) { }
//async add_message(server, message) {
@@ -22,7 +24,7 @@ export class ChatService {
// return rooms;
}
async addUserToRoom(user: User, room_id: string)
async addUserToRoom(user: User, room_name: string)
{
// get room
//if !room
@@ -30,7 +32,7 @@ export class ChatService {
// add user to room
}
async removeUserFromRoom(user: User, room_id: string)
async removeUserFromRoom(user: User, room_name: string)
{
// get room
// remove user

View File

@@ -1323,7 +1323,7 @@ var app = (function () {
}
// (260:0) {#if componentParams}
function create_if_block$d(ctx) {
function create_if_block$e(ctx) {
let switch_instance;
let switch_instance_anchor;
let current;
@@ -1408,7 +1408,7 @@ var app = (function () {
dispatch_dev("SvelteRegisterBlock", {
block,
id: create_if_block$d.name,
id: create_if_block$e.name,
type: "if",
source: "(260:0) {#if componentParams}",
ctx
@@ -1422,7 +1422,7 @@ var app = (function () {
let if_block;
let if_block_anchor;
let current;
const if_block_creators = [create_if_block$d, create_else_block$6];
const if_block_creators = [create_if_block$e, create_else_block$6];
const if_blocks = [];
function select_block_type(ctx, dirty) {
@@ -2336,7 +2336,7 @@ var app = (function () {
}
// (25:4) {#if $location !== '/profile'}
function create_if_block$c(ctx) {
function create_if_block$d(ctx) {
let button;
let mounted;
let dispose;
@@ -2366,7 +2366,7 @@ var app = (function () {
dispatch_dev("SvelteRegisterBlock", {
block,
id: create_if_block$c.name,
id: create_if_block$d.name,
type: "if",
source: "(25:4) {#if $location !== '/profile'}",
ctx
@@ -2399,7 +2399,7 @@ var app = (function () {
let dispose;
function select_block_type(ctx, dirty) {
if (/*$location*/ ctx[0] !== '/profile') return create_if_block$c;
if (/*$location*/ ctx[0] !== '/profile') return create_if_block$d;
if (/*$location*/ ctx[0] === '/profile') return create_if_block_1$5;
}
@@ -2610,7 +2610,7 @@ var app = (function () {
const file$t = "src/pieces/GenerateUserDisplay.svelte";
// (58:2) {#if user !== undefined}
function create_if_block$b(ctx) {
function create_if_block$c(ctx) {
let main;
let img;
let img_src_value;
@@ -2821,7 +2821,7 @@ var app = (function () {
dispatch_dev("SvelteRegisterBlock", {
block,
id: create_if_block$b.name,
id: create_if_block$c.name,
type: "if",
source: "(58:2) {#if user !== undefined}",
ctx
@@ -2832,7 +2832,7 @@ var app = (function () {
function create_fragment$w(ctx) {
let div;
let if_block = /*user*/ ctx[0] !== undefined && create_if_block$b(ctx);
let if_block = /*user*/ ctx[0] !== undefined && create_if_block$c(ctx);
const block = {
c: function create() {
@@ -2853,7 +2853,7 @@ var app = (function () {
if (if_block) {
if_block.p(ctx, dirty);
} else {
if_block = create_if_block$b(ctx);
if_block = create_if_block$c(ctx);
if_block.c();
if_block.m(div, null);
}
@@ -10348,7 +10348,7 @@ var app = (function () {
const { console: console_1$8 } = globals;
const file$h = "src/pieces/chat/Layout_create.svelte";
// (30:1) <Button bind:layout new_layout={back} my_class="back icon" my_title="go back {back}">
// (39:1) <Button bind:layout new_layout={back} my_class="back icon" my_title="go back {back}">
function create_default_slot_2$3(ctx) {
let t;
@@ -10368,14 +10368,14 @@ var app = (function () {
block,
id: create_default_slot_2$3.name,
type: "slot",
source: "(30:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
source: "(39:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
ctx
});
return block;
}
// (35:1) <Button my_class="create deactivate">
// (44:1) <Button my_class="create deactivate">
function create_default_slot_1$3(ctx) {
let t;
@@ -10395,14 +10395,14 @@ var app = (function () {
block,
id: create_default_slot_1$3.name,
type: "slot",
source: "(35:1) <Button my_class=\\\"create deactivate\\\">",
source: "(44:1) <Button my_class=\\\"create deactivate\\\">",
ctx
});
return block;
}
// (40:1) <Button bind:layout new_layout="close" my_class="close icon">
// (49:1) <Button bind:layout new_layout="close" my_class="close icon">
function create_default_slot$5(ctx) {
let t;
@@ -10422,7 +10422,77 @@ var app = (function () {
block,
id: create_default_slot$5.name,
type: "slot",
source: "(40:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
source: "(49:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
ctx
});
return block;
}
// (75:3) {#if room_type === 'protected'}
function create_if_block$b(ctx) {
let div;
let label;
let p;
let t1;
let input;
let mounted;
let dispose;
const block = {
c: function create() {
div = element("div");
label = element("label");
p = element("p");
p.textContent = "choose a password :";
t1 = space();
input = element("input");
attr_dev(p, "class", "svelte-1b1eu8h");
add_location(p, file$h, 76, 28, 2038);
attr_dev(label, "for", "chat_pswd");
attr_dev(label, "class", "svelte-1b1eu8h");
add_location(label, file$h, 76, 5, 2015);
attr_dev(input, "id", "chat_pswd");
attr_dev(input, "type", "password");
attr_dev(input, "placeholder", "minimum 8 characters");
attr_dev(input, "minlength", "8");
attr_dev(input, "name", "password");
input.required = true;
attr_dev(input, "class", "svelte-1b1eu8h");
add_location(input, file$h, 77, 5, 2078);
attr_dev(div, "class", "svelte-1b1eu8h");
add_location(div, file$h, 75, 4, 2004);
},
m: function mount(target, anchor) {
insert_dev(target, div, anchor);
append_dev(div, label);
append_dev(label, p);
append_dev(div, t1);
append_dev(div, input);
set_input_value(input, /*room_password*/ ctx[4]);
if (!mounted) {
dispose = listen_dev(input, "input", /*input_input_handler*/ ctx[13]);
mounted = true;
}
},
p: function update(ctx, dirty) {
if (dirty & /*room_password*/ 16 && input.value !== /*room_password*/ ctx[4]) {
set_input_value(input, /*room_password*/ ctx[4]);
}
},
d: function destroy(detaching) {
if (detaching) detach_dev(div);
mounted = false;
dispose();
}
};
dispatch_dev("SvelteRegisterBlock", {
block,
id: create_if_block$b.name,
type: "if",
source: "(75:3) {#if room_type === 'protected'}",
ctx
});
@@ -10430,7 +10500,7 @@ var app = (function () {
}
function create_fragment$k(ctx) {
let div2;
let div1;
let button0;
let updating_layout;
let t0;
@@ -10439,41 +10509,36 @@ var app = (function () {
let button2;
let updating_layout_1;
let t2;
let div1;
let div0;
let form;
let label0;
let p0;
let t4;
let input0;
let t5;
let input1;
let t6;
let label1;
let p1;
let t7;
let input1;
let t8;
let input2;
let t9;
let label2;
let p2;
let t10;
let input2;
let t11;
let input3;
let t12;
let label3;
let p3;
let t13;
let input3;
let t14;
let div0;
let label4;
let p4;
let t16;
let t15;
let input4;
let t17;
let input5;
let current;
let mounted;
let dispose;
function button0_layout_binding(value) {
/*button0_layout_binding*/ ctx[2](value);
/*button0_layout_binding*/ ctx[6](value);
}
let button0_props = {
@@ -10501,7 +10566,7 @@ var app = (function () {
});
function button2_layout_binding(value) {
/*button2_layout_binding*/ ctx[3](value);
/*button2_layout_binding*/ ctx[7](value);
}
let button2_props = {
@@ -10517,17 +10582,18 @@ var app = (function () {
button2 = new Chat_button({ props: button2_props, $$inline: true });
binding_callbacks.push(() => bind(button2, 'layout', button2_layout_binding));
let if_block = /*room_type*/ ctx[3] === 'protected' && create_if_block$b(ctx);
const block = {
c: function create() {
div2 = element("div");
div1 = element("div");
create_component(button0.$$.fragment);
t0 = space();
create_component(button1.$$.fragment);
t1 = space();
create_component(button2.$$.fragment);
t2 = space();
div1 = element("div");
div0 = element("div");
form = element("form");
label0 = element("label");
p0 = element("p");
@@ -10535,140 +10601,141 @@ var app = (function () {
t4 = space();
input0 = element("input");
t5 = space();
input1 = element("input");
t6 = space();
label1 = element("label");
p1 = element("p");
p1.textContent = "public";
t7 = space();
input1 = element("input");
t8 = space();
input2 = element("input");
t9 = space();
label2 = element("label");
p2 = element("p");
p2.textContent = "private";
t10 = space();
input2 = element("input");
t11 = space();
input3 = element("input");
t12 = space();
label3 = element("label");
p3 = element("p");
p3.textContent = "protected";
t13 = space();
input3 = element("input");
t14 = space();
div0 = element("div");
label4 = element("label");
p4 = element("p");
p4.textContent = "choose a password :";
t16 = space();
if (if_block) if_block.c();
t15 = space();
input4 = element("input");
t17 = space();
input5 = element("input");
attr_dev(p0, "class", "svelte-111r258");
add_location(p0, file$h, 56, 26, 1484);
attr_dev(p0, "class", "svelte-1b1eu8h");
add_location(p0, file$h, 56, 26, 1201);
attr_dev(label0, "for", "chat_name");
add_location(label0, file$h, 56, 3, 1461);
attr_dev(label0, "class", "svelte-1b1eu8h");
add_location(label0, file$h, 56, 3, 1178);
attr_dev(input0, "id", "chat_name");
attr_dev(input0, "name", "room_name");
input0.required = true;
add_location(input0, file$h, 57, 3, 1518);
attr_dev(input0, "class", "svelte-1b1eu8h");
add_location(input0, file$h, 57, 3, 1235);
attr_dev(p1, "class", "svelte-1b1eu8h");
add_location(p1, file$h, 60, 4, 1378);
attr_dev(input1, "id", "chat_public");
attr_dev(input1, "type", "radio");
attr_dev(input1, "name", "room_type");
input1.value = "public";
input1.checked = true;
attr_dev(input1, "class", "svelte-111r258");
add_location(input1, file$h, 59, 3, 1593);
attr_dev(p1, "class", "svelte-111r258");
add_location(p1, file$h, 60, 43, 1715);
input1.__value = "public";
input1.value = input1.__value;
input1.required = true;
attr_dev(input1, "class", "svelte-1b1eu8h");
/*$$binding_groups*/ ctx[10][0].push(input1);
add_location(input1, file$h, 61, 4, 1396);
attr_dev(label1, "for", "chat_public");
attr_dev(label1, "class", "_radio svelte-111r258");
add_location(label1, file$h, 60, 3, 1675);
attr_dev(label1, "class", "_radio svelte-1b1eu8h");
add_location(label1, file$h, 59, 3, 1333);
attr_dev(p2, "class", "svelte-1b1eu8h");
add_location(p2, file$h, 65, 4, 1584);
attr_dev(input2, "id", "chat_private");
attr_dev(input2, "type", "radio");
attr_dev(input2, "name", "room_type");
input2.value = "private";
attr_dev(input2, "class", "svelte-111r258");
add_location(input2, file$h, 62, 3, 1764);
attr_dev(p2, "class", "svelte-111r258");
add_location(p2, file$h, 63, 44, 1881);
input2.__value = "private";
input2.value = input2.__value;
input2.required = true;
attr_dev(input2, "class", "svelte-1b1eu8h");
/*$$binding_groups*/ ctx[10][0].push(input2);
add_location(input2, file$h, 66, 4, 1603);
attr_dev(label2, "for", "chat_private");
attr_dev(label2, "class", "_radio svelte-111r258");
add_location(label2, file$h, 63, 3, 1840);
attr_dev(label2, "class", "_radio svelte-1b1eu8h");
add_location(label2, file$h, 64, 3, 1538);
attr_dev(p3, "class", "svelte-1b1eu8h");
add_location(p3, file$h, 70, 4, 1797);
attr_dev(input3, "id", "chat_protected");
attr_dev(input3, "class", "__check_change_next svelte-111r258");
attr_dev(input3, "type", "radio");
attr_dev(input3, "name", "room_type");
input3.value = "protected";
add_location(input3, file$h, 65, 3, 1933);
attr_dev(p3, "class", "svelte-111r258");
add_location(p3, file$h, 66, 46, 2084);
input3.__value = "protected";
input3.value = input3.__value;
input3.required = true;
attr_dev(input3, "class", "svelte-1b1eu8h");
/*$$binding_groups*/ ctx[10][0].push(input3);
add_location(input3, file$h, 71, 4, 1818);
attr_dev(label3, "for", "chat_protected");
attr_dev(label3, "class", "_radio svelte-111r258");
add_location(label3, file$h, 66, 3, 2041);
attr_dev(p4, "class", "svelte-111r258");
add_location(p4, file$h, 69, 27, 2189);
attr_dev(label4, "for", "chat_pswd");
add_location(label4, file$h, 69, 4, 2166);
attr_dev(input4, "id", "chat_pswd");
attr_dev(input4, "type", "password");
attr_dev(input4, "placeholder", "minimum 8 characters");
attr_dev(input4, "minlength", "8");
attr_dev(input4, "name", "password");
add_location(input4, file$h, 70, 4, 2228);
attr_dev(div0, "class", "__to_show");
add_location(div0, file$h, 68, 3, 2138);
attr_dev(input5, "type", "submit");
input5.value = "⮡";
attr_dev(input5, "class", "svelte-111r258");
add_location(input5, file$h, 72, 3, 2346);
add_location(form, file$h, 54, 2, 1393);
attr_dev(div1, "class", "panel panel_create __border_top svelte-111r258");
add_location(div1, file$h, 44, 1, 848);
attr_dev(div2, "class", "grid_box svelte-111r258");
add_location(div2, file$h, 26, 0, 503);
attr_dev(label3, "class", "_radio svelte-1b1eu8h");
add_location(label3, file$h, 69, 3, 1749);
attr_dev(input4, "type", "submit");
input4.value = "⮡";
attr_dev(input4, "class", "svelte-1b1eu8h");
add_location(input4, file$h, 80, 3, 2242);
attr_dev(form, "class", "svelte-1b1eu8h");
add_location(form, file$h, 54, 2, 1110);
attr_dev(div0, "class", "panel panel_create __border_top svelte-1b1eu8h");
add_location(div0, file$h, 53, 1, 1062);
attr_dev(div1, "class", "grid_box svelte-1b1eu8h");
add_location(div1, file$h, 35, 0, 717);
},
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
},
m: function mount(target, anchor) {
insert_dev(target, div2, anchor);
mount_component(button0, div2, null);
append_dev(div2, t0);
mount_component(button1, div2, null);
append_dev(div2, t1);
mount_component(button2, div2, null);
append_dev(div2, t2);
append_dev(div2, div1);
append_dev(div1, form);
insert_dev(target, div1, anchor);
mount_component(button0, div1, null);
append_dev(div1, t0);
mount_component(button1, div1, null);
append_dev(div1, t1);
mount_component(button2, div1, null);
append_dev(div1, t2);
append_dev(div1, div0);
append_dev(div0, form);
append_dev(form, label0);
append_dev(label0, p0);
append_dev(form, t4);
append_dev(form, input0);
set_input_value(input0, /*room_name*/ ctx[2]);
append_dev(form, t5);
append_dev(form, input1);
append_dev(form, t6);
append_dev(form, label1);
append_dev(label1, p1);
append_dev(label1, t7);
append_dev(label1, input1);
input1.checked = input1.__value === /*room_type*/ ctx[3];
append_dev(form, t8);
append_dev(form, input2);
append_dev(form, t9);
append_dev(form, label2);
append_dev(label2, p2);
append_dev(label2, t10);
append_dev(label2, input2);
input2.checked = input2.__value === /*room_type*/ ctx[3];
append_dev(form, t11);
append_dev(form, input3);
append_dev(form, t12);
append_dev(form, label3);
append_dev(label3, p3);
append_dev(label3, t13);
append_dev(label3, input3);
input3.checked = input3.__value === /*room_type*/ ctx[3];
append_dev(form, t14);
append_dev(form, div0);
append_dev(div0, label4);
append_dev(label4, p4);
append_dev(div0, t16);
append_dev(div0, input4);
append_dev(form, t17);
append_dev(form, input5);
if (if_block) if_block.m(form, null);
append_dev(form, t15);
append_dev(form, input4);
current = true;
if (!mounted) {
dispose = listen_dev(form, "submit", prevent_default(handleSubmit), false, true, false);
dispose = [
listen_dev(input0, "input", /*input0_input_handler*/ ctx[8]),
listen_dev(input1, "change", /*input1_change_handler*/ ctx[9]),
listen_dev(input2, "change", /*input2_change_handler*/ ctx[11]),
listen_dev(input3, "change", /*input3_change_handler*/ ctx[12]),
listen_dev(form, "submit", prevent_default(/*handleSubmit*/ ctx[5]), false, true, false)
];
mounted = true;
}
},
@@ -10677,7 +10744,7 @@ var app = (function () {
if (dirty & /*back*/ 2) button0_changes.new_layout = /*back*/ ctx[1];
if (dirty & /*back*/ 2) button0_changes.my_title = "go back " + /*back*/ ctx[1];
if (dirty & /*$$scope*/ 16) {
if (dirty & /*$$scope*/ 16384) {
button0_changes.$$scope = { dirty, ctx };
}
@@ -10690,14 +10757,14 @@ var app = (function () {
button0.$set(button0_changes);
const button1_changes = {};
if (dirty & /*$$scope*/ 16) {
if (dirty & /*$$scope*/ 16384) {
button1_changes.$$scope = { dirty, ctx };
}
button1.$set(button1_changes);
const button2_changes = {};
if (dirty & /*$$scope*/ 16) {
if (dirty & /*$$scope*/ 16384) {
button2_changes.$$scope = { dirty, ctx };
}
@@ -10708,6 +10775,35 @@ var app = (function () {
}
button2.$set(button2_changes);
if (dirty & /*room_name*/ 4 && input0.value !== /*room_name*/ ctx[2]) {
set_input_value(input0, /*room_name*/ ctx[2]);
}
if (dirty & /*room_type*/ 8) {
input1.checked = input1.__value === /*room_type*/ ctx[3];
}
if (dirty & /*room_type*/ 8) {
input2.checked = input2.__value === /*room_type*/ ctx[3];
}
if (dirty & /*room_type*/ 8) {
input3.checked = input3.__value === /*room_type*/ ctx[3];
}
if (/*room_type*/ ctx[3] === 'protected') {
if (if_block) {
if_block.p(ctx, dirty);
} else {
if_block = create_if_block$b(ctx);
if_block.c();
if_block.m(form, t15);
}
} else if (if_block) {
if_block.d(1);
if_block = null;
}
},
i: function intro(local) {
if (current) return;
@@ -10723,12 +10819,16 @@ var app = (function () {
current = false;
},
d: function destroy(detaching) {
if (detaching) detach_dev(div2);
if (detaching) detach_dev(div1);
destroy_component(button0);
destroy_component(button1);
destroy_component(button2);
/*$$binding_groups*/ ctx[10][0].splice(/*$$binding_groups*/ ctx[10][0].indexOf(input1), 1);
/*$$binding_groups*/ ctx[10][0].splice(/*$$binding_groups*/ ctx[10][0].indexOf(input2), 1);
/*$$binding_groups*/ ctx[10][0].splice(/*$$binding_groups*/ ctx[10][0].indexOf(input3), 1);
if (if_block) if_block.d();
mounted = false;
dispose();
run_all(dispose);
}
};
@@ -10743,34 +10843,38 @@ var app = (function () {
return block;
}
async function handleSubmit(evt) {
let formIsValid = evt.target.checkValidity();
if (formIsValid) {
const formData = new FormData(evt.target);
console.log(formData);
const response = await fetch('/api/v2/chat/join', {
method: 'POST',
//headers: { 'Content-Type': 'multipart/form-data' },
body: formData
});
console.log(await response.json());
}
}
function instance$k($$self, $$props, $$invalidate) {
let { $$slots: slots = {}, $$scope } = $$props;
validate_slots('Layout_create', slots, []);
let { layout = "" } = $$props;
let { back = "" } = $$props;
let room_name = "";
let room_type = "";
let room_password = "";
async function handleSubmit(evt) {
let formIsValid = evt.target.checkValidity();
if (!formIsValid) return;
let formData = { room_name, room_type, room_password };
console.log("formData:", formData);
const response = await fetch(`http://${'transcendance'}:${'8080'}/api/v2/chat/join`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData)
});
console.log(await response.json());
}
const writable_props = ['layout', 'back'];
Object.keys($$props).forEach(key => {
if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console_1$8.warn(`<Layout_create> was created with unknown prop '${key}'`);
});
const $$binding_groups = [[]];
function button0_layout_binding(value) {
layout = value;
$$invalidate(0, layout);
@@ -10781,23 +10885,74 @@ var app = (function () {
$$invalidate(0, layout);
}
function input0_input_handler() {
room_name = this.value;
$$invalidate(2, room_name);
}
function input1_change_handler() {
room_type = this.__value;
$$invalidate(3, room_type);
}
function input2_change_handler() {
room_type = this.__value;
$$invalidate(3, room_type);
}
function input3_change_handler() {
room_type = this.__value;
$$invalidate(3, room_type);
}
function input_input_handler() {
room_password = this.value;
$$invalidate(4, room_password);
}
$$self.$$set = $$props => {
if ('layout' in $$props) $$invalidate(0, layout = $$props.layout);
if ('back' in $$props) $$invalidate(1, back = $$props.back);
};
$$self.$capture_state = () => ({ Button: Chat_button, layout, back, handleSubmit });
$$self.$capture_state = () => ({
Button: Chat_button,
layout,
back,
room_name,
room_type,
room_password,
handleSubmit
});
$$self.$inject_state = $$props => {
if ('layout' in $$props) $$invalidate(0, layout = $$props.layout);
if ('back' in $$props) $$invalidate(1, back = $$props.back);
if ('room_name' in $$props) $$invalidate(2, room_name = $$props.room_name);
if ('room_type' in $$props) $$invalidate(3, room_type = $$props.room_type);
if ('room_password' in $$props) $$invalidate(4, room_password = $$props.room_password);
};
if ($$props && "$$inject" in $$props) {
$$self.$inject_state($$props.$$inject);
}
return [layout, back, button0_layout_binding, button2_layout_binding];
return [
layout,
back,
room_name,
room_type,
room_password,
handleSubmit,
button0_layout_binding,
button2_layout_binding,
input0_input_handler,
input1_change_handler,
$$binding_groups,
input2_change_handler,
input3_change_handler,
input_input_handler
];
}
class Layout_create extends SvelteComponentDev {

File diff suppressed because one or more lines are too long

View File

@@ -5,21 +5,30 @@
export let layout = "";
export let back = "";
let room_name = "";
let room_type = "";
let room_password = "";
async function handleSubmit(evt)
{
let formIsValid = evt.target.checkValidity();
if (formIsValid)
{
const formData = new FormData(evt.target);
console.log(formData);
const response = await fetch('/api/v2/chat/join', {
method: 'POST',
//headers: { 'Content-Type': 'multipart/form-data' },
body: formData,
});
console.log(await response.json());
}
if (!formIsValid)
return;
let formData = {
room_name: room_name,
room_type: room_type,
room_password: room_password,
};
console.log("formData:", formData);
const response = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/chat/join`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
});
console.log(await response.json());
}
</script>
@@ -43,33 +52,32 @@
<!-- panel_create -->
<div class="panel panel_create __border_top">
<!--
<form action="/api/v2/chat/create" method="post" onsubmit="return submit();">
<Button on_click={submit} my_class="border light thin">&#x2BA1</Button>
<form bind:this={form} onsubmit="return my_submit();">
<form action="/api/v2/chat/create" method="post" on:submit|stopPropagation>
<form action="/api/v2/chat/create" method="post">
<form action="/api/v2/chat/create" method="post" on:submit|preventDefault>
<form bind:this={form} on:submit|preventDefault={handleSubmit}>
-->
<form on:submit|preventDefault={handleSubmit}>
<!-- name: -->
<label for="chat_name"><p>new room name :</p></label>
<input id="chat_name" name="room_name" required>
<input id="chat_name" bind:value={room_name} name="room_name" required>
<!-- [ ] pubic -->
<input id="chat_public" type="radio" name="room_type" value="public" checked>
<label for="chat_public" class="_radio"><p>public</p></label>
<label for="chat_public" class="_radio">
<p>public</p>
<input id="chat_public" bind:group={room_type} type="radio" name="room_type" value="public" required>
</label>
<!-- [ ] private -->
<input id="chat_private" type="radio" name="room_type" value="private">
<label for="chat_private" class="_radio"><p>private</p></label>
<label for="chat_private" class="_radio">
<p>private</p>
<input id="chat_private" bind:group={room_type} type="radio" name="room_type" value="private" required>
</label>
<!-- [ ] protected -->
<input id="chat_protected" class="__check_change_next" type="radio" name="room_type" value="protected">
<label for="chat_protected" class="_radio"><p>protected</p></label>
<label for="chat_protected" class="_radio">
<p>protected</p>
<input id="chat_protected" bind:group={room_type} type="radio" name="room_type" value="protected" required>
</label>
<!-- [x] protected -->
<div class="__to_show">
<label for="chat_pswd"><p>choose a password :</p></label>
<input id="chat_pswd" type="password" placeholder="minimum 8 characters" minlength="8" name="password">
</div>
{#if room_type === 'protected'}
<div>
<label for="chat_pswd"><p>choose a password :</p></label>
<input id="chat_pswd" bind:value={room_password} type="password" placeholder="minimum 8 characters" minlength="8" name="password" required>
</div>
{/if}
<input type="submit" value="&#x2BA1">
</form>
</div>
@@ -94,34 +102,19 @@
/* radio elements style check
*/
.panel input[type=radio] {
display: none;
}
.panel label._radio {
margin: 0px 20px 0px auto;
display: inline;
margin: 10px 0px 0px auto;
padding-right: 10px;
cursor: pointer;
}
.panel label._radio * {
display: inline;
}
.panel label._radio p {
margin-top: 0px;
margin-bottom: 0px;
}
.panel label._radio::after {
content: "";
position: absolute;
top: calc(50% - 6px);
right: 0px;
width: 12px;
height: 12px;
border-radius: 6px;
border: 2px solid rgb(150, 150, 150);
box-sizing: border-box;
cursor: pointer;
}
.panel input[type=radio]:checked
+ label._radio::after {
background-color: rgb(200, 200, 200);
}
/* submit