Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend improvements 5 #158

Merged
merged 6 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 49 additions & 16 deletions frontend/src/lib/components/user/FileRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
} from '../../../server/files';
import { getWebhooksForSpecifiedUser, sendWebhook } from '../../../server/webhooks';
import { FileMetadata } from '../../types/FileMetadata';
import { onMount } from 'svelte';

export let file = new FileMetadata(
'test',
Expand Down Expand Up @@ -61,8 +62,14 @@
});

const downloadFile = () => {
if (file.encrypted) isDownloadWindowVisible = true;
else getFile();
if (file.encrypted) {
isDownloadWindowVisible = true;
window.scrollTo(0, 0);

return;
}

getFile();
};

const getFile = async () => {
Expand Down Expand Up @@ -201,6 +208,7 @@
const openShare = () => {
if (file.shared) {
visible = true;
window.scrollTo(0, 0);
}
};

Expand All @@ -212,6 +220,12 @@
minute: 'numeric'
});

let currentUsername: string | null = null;

onMount(() => {
currentUsername = localStorage.getItem('username');
});

$: ({ classes, getStyles } = useStyles());
</script>

Expand Down Expand Up @@ -288,10 +302,39 @@
<Box class={getStyles()}>
<Flex direction="column" align="space-evenly" gap="md" justify="center">
<Title order={3}>Share File</Title>

<Flex justify="space-around" align="center" direction="column" gap="md">
<TextInput
label="Username"
bind:value={usernameShare}
placeholder="Username..."
required
/>

{#if currentUsername === usernameShare}
<Text color="red">You cannot share files with yourself.</Text>
{/if}

<Flex direction="row" justify="space-between" gap="lg">
<Button
variant="filled"
on:click={shareFile}
disabled={!usernameShare.length || currentUsername === usernameShare}
>
Share
</Button>

<Button variant="light" on:click={() => (visible = false)}>Close</Button>
</Flex>
</Flex>

<br />

<Title order={3}>Shared With</Title>
{#if file.shared_people.length > 0}
{#each file.shared_people as share}
<Box class={getStyles()}>
<Flex align="center" justify="space-evenly" style="height: 100%;">
<Box>
<Flex align="center" justify="space-evenly" style="height: 50%;">
<Text size="sm" css={{ flex: 1, textAlign: 'center' }}>
{share.username}
</Text>
Expand All @@ -306,17 +349,6 @@
{:else}
<Text>This file is not yet shared with anyone.</Text>
{/if}
<br />
<Flex justify="space-around" align="center">
<TextInput label="Username" bind:value={usernameShare} />
</Flex>
<Flex justify="space-around" align="center">
<Button variant="filled" on:click={shareFile}>Share</Button>
</Flex>
<br />
<Flex justify="space-around" align="center">
<Button variant="light" on:click={() => (visible = false)}>Close</Button>
</Flex>
</Flex>
</Box>
</Overlay>
Expand All @@ -332,9 +364,10 @@
name="filepassword"
bind:value={downloadFilePassword}
placeholder="Password..."
required
/>
<Flex gap="lg" justify="space-between">
<Button variant="filled" on:click={getFile} disabled={!downloadFilePassword?.length}>
<Button variant="filled" on:click={getFile} disabled={!downloadFilePassword.length}>
Submit
</Button>
<Button variant="light" on:click={() => (isDownloadWindowVisible = false)}>Close</Button>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/components/user/WebhookRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
<Box class={getStyles()}>
<Flex align="center" justify="space-evenly" style="height: 100%;">
<Text size="sm" css={{ flex: 1, textAlign: 'center' }}>
{webhook.platform}
{webhook.platform.length > 50 ? `${webhook.platform.slice(0, 50)}...` : webhook.platform}
</Text>
<Text size="sm" css={{ flex: 1, textAlign: 'center' }}>
{webhook.url}
{webhook.url.length > 50 ? `${webhook.url.slice(0, 50)}...` : webhook.url}
</Text>
<Flex justify="center" gap="xs" css={{ flex: 1 }}>
<Tooltip openDelay={10} label="Delete">
Expand Down
28 changes: 22 additions & 6 deletions frontend/src/routes/auth/login/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts">
import { Button, Text, TextInput } from '@svelteuidev/core';
import { Anchor, Button, Text, TextInput } from '@svelteuidev/core';
import { isAxiosError } from 'axios';
import { login } from '../../../server/auth';
import { onMount } from 'svelte';
import { login } from '../../../server/auth';

let username: string = '';
let password: string = '';
Expand Down Expand Up @@ -55,15 +55,25 @@
<div
style="width: 300px; margin: auto; top: 50%; transform: translate(0, 30vh); border: 1px solid gray; padding: 10px; border-radius: 5px"
>
<TextInput label="Username" bind:value={username} />
<TextInput label="Password" bind:value={password} type="password" />
<TextInput label="Username" bind:value={username} required placeholder="Username..." />
<TextInput
label="Password"
bind:value={password}
type="password"
required
placeholder="Password..."
/>

<br />

<div style="display: flex; justify-content: center;">
<Button on:click={handleSubmit} disabled={!username.length || !password.length}>Login</Button>
</div>

<br />

<Text align="center">
No account? <a href="/auth/register">Register!</a>
No account? <Anchor href="/auth/register">Register!</Anchor>
</Text>
</div>
{/if}
Expand All @@ -72,15 +82,21 @@
<div
style="width: 300px; margin: auto; top: 50%; transform: translate(0, 30vh); border: 1px solid gray; padding: 10px; border-radius: 5px"
>
<TextInput label="Code" bind:value={code2FA} />
<TextInput label="Code" bind:value={code2FA} required placeholder="Code..." />

<br />

<div style="display: flex; justify-content: center;">
<Button on:click={handleSubmit} disabled={!code2FA?.length}>Submit</Button>
</div>
<br />
</div>

<br />

<Text align="center" size="lg">2FA Authentication</Text>

<br />

<Text align="center">Please enter the code currently displayed in your authenticator app.</Text>
{/if}
31 changes: 26 additions & 5 deletions frontend/src/routes/auth/register/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { Button, Text, TextInput } from '@svelteuidev/core';
import { Anchor, Button, Text, TextInput } from '@svelteuidev/core';
import { isAxiosError } from 'axios';
import { onMount } from 'svelte';
import { register } from '../../../server/auth';
Expand Down Expand Up @@ -46,10 +46,29 @@
<div
style="width: 300px; margin: auto; top: 50%; transform: translate(0, 30vh); border: 1px solid gray; padding: 10px; border-radius: 5px"
>
<TextInput label="Username (between 5 and 24 characters)" bind:value={username} />
<TextInput label="Password (between 5 and 24 characters)" bind:value={password} type="password" />
<TextInput label="Repeat Password" bind:value={repeatPassword} type="password" />
<TextInput
label="Username (between 5 and 24 characters)"
bind:value={username}
required
placeholder="Username..."
/>
<TextInput
label="Password (between 5 and 24 characters)"
bind:value={password}
type="password"
required
placeholder="Password..."
/>
<TextInput
label="Repeat Password"
bind:value={repeatPassword}
type="password"
required
placeholder="Password..."
/>

<br />

<div style="display: flex; justify-content: center;">
<Button
on:click={handleSubmit}
Expand All @@ -58,8 +77,10 @@
Register
</Button>
</div>

<br />

<Text align="center">
Already have an account? <a href="/auth/login">Login!</a>
Already have an account? <Anchor href="/auth/login">Login!</Anchor>
</Text>
</div>
17 changes: 14 additions & 3 deletions frontend/src/routes/download/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,24 @@
{/if}

{#if fileMetadata?.encrypted}
<TextInput placeholder="Password..." type="password" bind:value={downloadFilePassword} />
<TextInput
placeholder="Password..."
type="password"
bind:value={downloadFilePassword}
required
/>
<br />
{/if}

<Button
on:click={downloadFile}
disabled={fileMetadata?.encrypted && !downloadFilePassword?.length}>Download</Button
disabled={fileMetadata?.encrypted && !downloadFilePassword?.length}
>
Download
</Button>

<br />

{#if fileUrl && isPreviewable}
<div
style="display: flex; justify-content: center; align-items: center; height: 80vh; width: 80vw; border: 2px solid #ccc;"
Expand All @@ -182,7 +193,7 @@
<Text>
The file must be one of the following types to be previewed: {SUPPORTED_FILE_TYPES.join(
', '
)}
)}.
</Text>
</div>
{/if}
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/routes/user/2fa/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { page } from '$app/stores';
import QR from '@svelte-put/qr/img/QR.svelte';
import { Button, Flex, Text, TextInput } from '@svelteuidev/core';
import { Anchor, Button, Flex, Text, TextInput } from '@svelteuidev/core';
import { isAxiosError } from 'axios';
import { onMount } from 'svelte';
import { get2FAToken, remove2FAToken } from '../../../server/auth';
Expand Down Expand Up @@ -50,10 +50,16 @@

{#if code == null}
<div class="container">
<TextInput label="Password" bind:value={password} type="password" />
<TextInput
label="Password"
bind:value={password}
type="password"
required
placeholder="Password..."
/>
<br />
<div class="button-container">
<Button on:click={fetchCode} disabled={!password.length}>Login</Button>
<Button on:click={fetchCode} disabled={!password.length}>Verify</Button>
</div>
<br />
</div>
Expand Down Expand Up @@ -86,7 +92,7 @@

<Flex justify="center">
<Button>
<a href="/user/account">Back</a>
<Anchor href="/user/account">Back</Anchor>
</Button>
</Flex>
{/if}
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/routes/user/home/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
{/each}

{#if visible}
<Overlay opacity={0.9} color="#000" zIndex={5} center class={classes.flexOverlay}>
<Overlay opacity={1} color="#000" zIndex={5} center class={classes.flexOverlay}>
<Box class={getStyles()}>
<Flex direction="column" align="space-evenly" gap="md" justify="center">
<Title order={3}>Upload File</Title>
Expand All @@ -153,7 +153,7 @@
on:change={handleFileChange}
/>
</Flex>

<br />
<Text align="center">
{#if filesToUpload}
{fileName}
Expand All @@ -177,13 +177,14 @@
disabled={!passwordLock}
placeholder="Password..."
type="password"
label="Password (at least 5 characters)"
/>
<Flex justify="space-around" align="center">
<Button
variant="filled"
on:click={sendData}
disabled={!filesToUpload?.length ||
(filesToUpload?.length && passwordLock && !filePassword?.length)}
(filesToUpload?.length && passwordLock && filePassword.length < 5)}
>
Submit
</Button>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/routes/user/webhooks/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@
{/each}

{#if visible}
<Overlay opacity={0.9} color="#000" zIndex={5} center class={classes.flexOverlay}>
<Overlay opacity={1} color="#000" zIndex={5} center class={classes.flexOverlay}>
<Box class={getStyles()}>
<Flex direction="column" align="space-evenly" gap="md" justify="center">
<Title order={3}>Add Webhook</Title>

<TextInput label="Name" bind:value={name} />
<TextInput label="URL" bind:value={url} />
<TextInput label="Name" bind:value={name} required placeholder="Name..." />
<TextInput label="URL" bind:value={url} required placeholder="URL..." />

<Flex justify="space-around" align="center">
<Button
Expand Down
Loading