Correction form review and checks

This commit is contained in:
GRL 2021-06-22 09:43:41 +02:00
parent 232fd33ec8
commit 5cac4f52bc
4 changed files with 57 additions and 43 deletions

View File

@ -2,7 +2,7 @@
import InputTextGlobalMessage from "./InputTextGlobalMessage.svelte";
import UploadAudioGlobalMessage from "./UploadAudioGlobalMessage.svelte";
import {gameManager} from "../../Phaser/Game/GameManager";
import {Game} from "../../Phaser/Game/Game";
import type {Game} from "../../Phaser/Game/Game";
export let game: Game;
let inputSendTextActive = true;

View File

@ -1,7 +1,7 @@
<script lang="ts">
import {ConsoleGlobalMessageManagerFocusStore, ConsoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore";
import {onMount} from "svelte";
import {Game} from "../../Phaser/Game/Game";
import type {Game} from "../../Phaser/Game/Game";
import {GameManager} from "../../Phaser/Game/GameManager";
import type {PlayGlobalMessageInterface} from "../../Connexion/ConnexionModels";
import {AdminMessageEventTypes} from "../../Connexion/AdminMessagesService";
@ -33,10 +33,12 @@
export let game: Game;
export let gameManager: GameManager;
let gameScene = game.scene.getScene(gameManager.currentGameSceneName);
let gameScene;
if (gameManager.currentGameSceneName) {
gameScene = gameManager.getCurrentGameScene(game.scene.getScene(gameManager.currentGameSceneName));
}
let quill;
let INPUT_CONSOLE_MESSAGE = 'quill';
let INPUT_CONSOLE_MESSAGE;
const MESSAGE_TYPE = AdminMessageEventTypes.admin;
@ -53,7 +55,7 @@
},
});
quill.on('selection-change', function (range, oldRange, source) {
quill.on('selection-change', function (range, oldRange) {
if (range === null && oldRange !== null) {
ConsoleGlobalMessageManagerFocusStore.set(false);
} else if (range !== null && oldRange === null)
@ -67,17 +69,15 @@
}
function SendTextMessage() {
const elements = document.getElementsByClassName('ql-editor');
const quillEditor = elements.item(0);
if (!quillEditor) {
throw "Error get quill node";
}
const text = quill.getText(0, quill.getLength());
const GlobalMessage: PlayGlobalMessageInterface = {
id: "1", // FIXME: use another ID?
message: quillEditor.innerHTML,
message: text,
type: MESSAGE_TYPE
};
quillEditor.innerHTML = '';
quill.deleteText(0, quill.getLength());
gameScene.connection.emitGlobalMessage(GlobalMessage);
disableConsole();
}

View File

@ -1,6 +1,6 @@
<script lang="ts">
import {HtmlUtils} from "../../WebRtc/HtmlUtils";
import {Game} from "../../Phaser/Game/Game";
import type {Game} from "../../Phaser/Game/Game";
import {GameManager} from "../../Phaser/Game/GameManager";
import {ConsoleGlobalMessageManagerFocusStore, ConsoleGlobalMessageManagerVisibleStore} from "../../Stores/ConsoleGlobalMessageManagerStore";
import {AdminMessageEventTypes} from "../../Connexion/AdminMessagesService";
@ -14,21 +14,25 @@
export let game: Game;
export let gameManager: GameManager;
let gameScene = game.scene.getScene(gameManager.currentGameSceneName);
let gameScene;
if (gameManager.currentGameSceneName) {
gameScene = gameManager.getCurrentGameScene(game.scene.getScene(gameManager.currentGameSceneName));
}
let fileinput;
let filename: string;
let filesize: string;
let errorfile: boolean;
const UPLOAD_CONSOLE_MESSAGE = 'input-upload-music';
const AUDIO_TYPE = AdminMessageEventTypes.audio;
async function SendAudioMessage() {
const inputAudio = HtmlUtils.getElementByIdOrFail<HTMLInputElement>(UPLOAD_CONSOLE_MESSAGE);
const inputAudio = HtmlUtils.getElementByIdOrFail<HTMLInputElement>("input-send-audio");
const selectedFile = inputAudio.files ? inputAudio.files[0] : null;
if (!selectedFile) {
throw 'no file selected';
}
errorfile = true;
throw 'no file selected';
}
const fd = new FormData();
fd.append('file', selectedFile);
@ -45,7 +49,6 @@
}
function inputAudioFile(event: Event) {
console.log('Input');
const eventTarget : EventTargetFiles = (event.target as EventTargetFiles);
if(!eventTarget || !eventTarget.files || eventTarget.files.length === 0){
return;
@ -58,6 +61,7 @@
filename = file.name;
filesize = getFileSize(file.size);
errorfile = false;
}
function getFileSize(number: number) {
@ -85,9 +89,41 @@
{#if filename != undefined}
<label for="input-send-audio">{filename} : {filesize}</label>
{/if}
{#if errorfile}
<p class="err">No file selected. You need to upload a file before sending it.</p>
{/if}
<input type="file" id="input-send-audio" bind:this={fileinput} on:change={(e) => {inputAudioFile(e)}}>
</div>
<div class="btn-action">
<button class="nes-btn is-primary" on:click|preventDefault={SendAudioMessage}>Send</button>
</div>
</section>
</section>
<style lang="scss">
//UploadAudioGlobalMessage
.section-input-send-audio {
margin: 10px;
}
.section-input-send-audio .input-send-audio {
text-align: center;
}
.section-input-send-audio #input-send-audio{
display: none;
}
.section-input-send-audio div.input-send-audio label{
color: white;
}
.section-input-send-audio div.input-send-audio p.err {
color: #ce372b;
text-align: center;
}
.section-input-send-audio div.input-send-audio img{
height: 150px;
cursor: url('style/images/cursor_pointer.png'), pointer;
}
</style>

View File

@ -57,26 +57,4 @@ div.main-console.nes-container {
.section-input-send-text .ql-toolbar{
background: white;
}
//UploadAudioGlobalMessage
.section-input-send-audio {
margin: 10px;
}
.section-input-send-audio .input-send-audio {
text-align: center;
}
.section-input-send-audio #input-send-audio{
display: none;
}
.section-input-send-audio div.input-send-audio label{
color: white;
}
.section-input-send-audio div.input-send-audio img{
height: 150px;
cursor: url('./images/cursor_pointer.png'), pointer;
}
}