Files
frontend/src/lib/components/Join.svelte
AtHeartEngineer ccc322334d feat: Improve Join functionality and SelectRoom component
- Added a code transformation to lowercase before sending to the server in the Join component.
- Modified the SelectRoom component to use a list layout instead of a dropdown menu.
- Added a click event to each room item in the SelectRoom component to update the selected room.
- Updated the styles for the SelectRoom component to improve readability.

fix: Handle errors in merkle proof generation

- Added error handling for generating merkle proofs with rate commitments and identity commitments in the Prover module.

style: Adjust grid template columns in Chat page

- Adjusted the grid template columns in the Chat page to make the sidebar narrower.

fix: Improve error handling in InputPrompt component

- Added validation for empty messages and messages that exceed the character limit.
- Added error handling for cases where generating merkle proofs fail, displaying appropriate error messages.

style: Adjust padding in Sidebar component

- Adjusted the padding in the Sidebar component to improve spacing.

feat: Reset state on identity deletion

- Reset the state on identity deletion by setting identityStore, configStore, roomsStore, selectedRoom, and messageStore to their initial values.
2023-08-23 19:48:43 -04:00

110 lines
2.7 KiB
Svelte

<script lang="ts">
import { selectedServer, configStore } from '$lib/stores';
import SelectServer from '$lib/components/SelectServer.svelte';
import { postInviteCode } from '$lib/services/server';
import type { JoinResponseI } from '$lib/types';
import { getCommitment, updateRooms } from '$lib/utils/';
let code = '';
let acceptedRoomNames: string[] = [];
async function addCode(newCode: string) {
const idc = getCommitment();
const result = (await postInviteCode($selectedServer, {
code: newCode.toLowerCase(),
idc
})) as JoinResponseI;
console.log('INVITE CODE RESPONSE: ', result);
if (result.status == 'valid' || result.status == 'already-added') {
acceptedRoomNames = await updateRooms($selectedServer, result.roomIds);
code = '';
$configStore.signUpStatus.inviteAccepted = true;
} else {
alert('Invalid invite code');
}
}
function inviteCodeKeyPress(event: KeyboardEvent) {
const input = event.target as HTMLInputElement | null;
// Check if the target is not an instance of HTMLInputElement or is null.
if (!input || !(input instanceof HTMLInputElement)) return;
const forbiddenKeys = [
'`',
'=',
'+',
'[',
']',
'\\',
';',
"'",
',',
'.',
'/',
'?',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0'
];
if (event.key === 'Enter') {
event.preventDefault();
addCode(code); // Assuming 'code' is available in the outer scope
} else if (event.key === ' ' || event.key === '-') {
event.preventDefault();
if (code.length > 0 && code[code.length - 1] !== '-') {
// Insert a dash where the cursor is
code = code.slice(0, input.selectionStart!) + '-' + code.slice(input.selectionStart!);
const cursorPosition = input.selectionStart!;
setTimeout(() => {
if (input) {
input.selectionStart = input.selectionEnd = cursorPosition + 1;
}
}, 0);
}
} else if (forbiddenKeys.includes(event.key)) {
// This just helps prevent typos
event.preventDefault();
}
}
</script>
<div class="grid place-content-center">
<label class="label">
<span>Select or Add a Server</span>
<SelectServer />
</label>
<label class="label mt-3">
<span>Invite Code</span>
<input
class="input max-w-md"
type="text"
placeholder="Invite Code"
bind:value={code}
on:keydown={(event) => inviteCodeKeyPress(event)}
/>
<button
class="btn variant-ghost-success"
type="button"
disabled={!code}
on:click={() => addCode(code)}>Submit</button
>
</label>
{#if acceptedRoomNames.length > 0}
<p class="text-center mt-2">You've been added to:</p>
<div class="my-2">
{#each acceptedRoomNames as name}
<ins class="ins border-y border-success-800">{name}</ins>
{/each}
</div>
{/if}
</div>