Skip to content

Commit

Permalink
Fix: sending mechanism updated, same message bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
beef-e committed May 5, 2024
1 parent 600b8f4 commit ff4f9ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
36 changes: 22 additions & 14 deletions src/lib/WritingBar.svelte
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
<script>
import { message } from "../utils/utils"
let messaggio;
import { message } from '../utils/utils';
import { actualSend } from '../utils/utils';
let messaggio;
function sendMessage(){
message.set(messaggio);
messaggio = "";
}
function sendMessage() {
message.set(messaggio);
actualSend(messaggio);
messaggio = '';
}
</script>


<form class="writing-div" on:submit|preventDefault={sendMessage}>
<input type="text" placeholder="Scrivi un messaggio" bind:value={messaggio}/>
<button type="submit">Invia</button>
<form
class="writing-div"
on:submit|preventDefault={sendMessage}
>
<input
type="text"
placeholder="Scrivi un messaggio"
bind:value={messaggio}
/>
<button type="submit">Invia</button>
</form>

<style>
input{
padding-left: 1.5%;
}
</style>
input {
padding-left: 1.5%;
}
</style>
24 changes: 11 additions & 13 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,6 @@ MyID.subscribe((value) => {
ID = value;
});

message.subscribe((value) => {
testo = value;

if (testo.length > 0 && conn != null && messageIsMineValue != 2 && validate(testo)) {
try {
messageIsMine.set(1);
conn.send(testo);
} catch (error) {
console.log('Errore: ' + error);
}
}
});

messageIsMine.subscribe((value) => {
messageIsMineValue = value;
});
Expand All @@ -204,3 +191,14 @@ export function validate(text: string) {
return true;
}
}

export function actualSend(message: string) {
if (message.length > 0 && conn != null && messageIsMineValue != 2 && validate(message)) {
try {
messageIsMine.set(1);
conn.send(message);
} catch (error) {
console.log('Errore: ' + error);
}
}
}

0 comments on commit ff4f9ae

Please # to comment.