forked from mirrors/pronouns.cc
feat(frontend): add names+pronouns to edit profile page, add robots.txt
This commit is contained in:
parent
d67aaefdc0
commit
e8d45ed4e9
4 changed files with 153 additions and 27 deletions
|
@ -14,8 +14,6 @@ export const load = async ({ params }) => {
|
||||||
throw error(404, (e as APIError).message);
|
throw error(404, (e as APIError).message);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(e);
|
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { apiFetch } from "$lib/api/fetch";
|
||||||
import type { PageServerLoad, Actions } from "./$types";
|
import type { PageServerLoad, Actions } from "./$types";
|
||||||
import { PUBLIC_BASE_URL } from "$env/static/public";
|
import { PUBLIC_BASE_URL } from "$env/static/public";
|
||||||
|
|
||||||
export const load = (async ({ locals, url }) => {
|
export const load = (async ({ url }) => {
|
||||||
try {
|
try {
|
||||||
const resp = await apiFetch<CallbackResponse>("/auth/discord/callback", {
|
const resp = await apiFetch<CallbackResponse>("/auth/discord/callback", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -18,8 +18,6 @@ export const load = (async ({ locals, url }) => {
|
||||||
...resp,
|
...resp,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
|
||||||
|
|
||||||
return { error: e as APIError };
|
return { error: e as APIError };
|
||||||
}
|
}
|
||||||
}) satisfies PageServerLoad;
|
}) satisfies PageServerLoad;
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from "$app/navigation";
|
import { goto } from "$app/navigation";
|
||||||
import type { APIError, Field, FieldEntry, MeUser, Pronoun } from "$lib/api/entities";
|
import {
|
||||||
|
WordStatus,
|
||||||
|
type APIError,
|
||||||
|
type Field,
|
||||||
|
type FieldEntry,
|
||||||
|
type MeUser,
|
||||||
|
type Pronoun,
|
||||||
|
} from "$lib/api/entities";
|
||||||
import FallbackImage from "$lib/components/FallbackImage.svelte";
|
import FallbackImage from "$lib/components/FallbackImage.svelte";
|
||||||
import { userStore } from "$lib/store";
|
import { userStore } from "$lib/store";
|
||||||
import { Alert, Button, FormGroup, Input } from "sveltestrap";
|
import { Alert, Button, FormGroup, Icon, Input } from "sveltestrap";
|
||||||
import { encode } from "base64-arraybuffer";
|
import { encode } from "base64-arraybuffer";
|
||||||
import { apiFetchClient } from "$lib/api/fetch";
|
import { apiFetchClient } from "$lib/api/fetch";
|
||||||
|
|
||||||
|
@ -88,13 +95,10 @@
|
||||||
if (!list || list.length === 0) return null;
|
if (!list || list.length === 0) return null;
|
||||||
if (list[0].size > MAX_AVATAR_BYTES) return null;
|
if (list[0].size > MAX_AVATAR_BYTES) return null;
|
||||||
|
|
||||||
console.log(list[0].type);
|
|
||||||
|
|
||||||
const buffer = await list[0].arrayBuffer();
|
const buffer = await list[0].arrayBuffer();
|
||||||
const base64 = encode(buffer);
|
const base64 = encode(buffer);
|
||||||
|
|
||||||
const uri = `data:${dataTypeFromFilename(list[0].name)};base64,${base64}`;
|
const uri = `data:${dataTypeFromFilename(list[0].name)};base64,${base64}`;
|
||||||
console.log(uri.slice(0, 256));
|
|
||||||
|
|
||||||
return uri;
|
return uri;
|
||||||
};
|
};
|
||||||
|
@ -113,19 +117,30 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const moveName = (index: number, up: boolean) => {
|
||||||
|
if (up && index == 0) return;
|
||||||
|
if (!up && index == names.length - 1) return;
|
||||||
|
|
||||||
|
const newIndex = up ? index - 1 : index + 1;
|
||||||
|
|
||||||
|
const temp = names[index];
|
||||||
|
names[index] = names[newIndex];
|
||||||
|
names[newIndex] = temp;
|
||||||
|
};
|
||||||
|
|
||||||
|
const movePronoun = (index: number, up: boolean) => {
|
||||||
|
if (up && index == 0) return;
|
||||||
|
if (!up && index == pronouns.length - 1) return;
|
||||||
|
|
||||||
|
const newIndex = up ? index - 1 : index + 1;
|
||||||
|
|
||||||
|
const temp = pronouns[index];
|
||||||
|
pronouns[index] = pronouns[newIndex];
|
||||||
|
pronouns[newIndex] = temp;
|
||||||
|
};
|
||||||
|
|
||||||
const updateUser = async () => {
|
const updateUser = async () => {
|
||||||
try {
|
try {
|
||||||
console.log(
|
|
||||||
JSON.stringify({
|
|
||||||
display_name,
|
|
||||||
avatar,
|
|
||||||
bio,
|
|
||||||
names,
|
|
||||||
pronouns,
|
|
||||||
fields,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const resp = await apiFetchClient<MeUser>("/users/@me", "PATCH", {
|
const resp = await apiFetchClient<MeUser>("/users/@me", "PATCH", {
|
||||||
display_name,
|
display_name,
|
||||||
avatar,
|
avatar,
|
||||||
|
@ -138,6 +153,7 @@
|
||||||
userStore.set(resp);
|
userStore.set(resp);
|
||||||
localStorage.setItem("pronouns-user", JSON.stringify(resp));
|
localStorage.setItem("pronouns-user", JSON.stringify(resp));
|
||||||
|
|
||||||
|
avatar = null;
|
||||||
error = null;
|
error = null;
|
||||||
modified = false;
|
modified = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -146,6 +162,10 @@
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Edit profile - pronouns.cc</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<h1>
|
<h1>
|
||||||
Edit profile
|
Edit profile
|
||||||
{#if modified}
|
{#if modified}
|
||||||
|
@ -167,13 +187,9 @@
|
||||||
<Alert color="danger" fade={false}>Error: No user object</Alert>
|
<Alert color="danger" fade={false}>Error: No user object</Alert>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="row">
|
<div class="row m-1">
|
||||||
<div class="col-md">
|
<div class="col-md">
|
||||||
<FormGroup floating label="Username">
|
<h4>Avatar</h4>
|
||||||
<Input value={$userStore.name} disabled />
|
|
||||||
</FormGroup>
|
|
||||||
<span>To change your username, go to <a href="/settings">settings</a>.</span>
|
|
||||||
<h3>Avatar</h3>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md">
|
<div class="col-md">
|
||||||
{#if avatar}
|
{#if avatar}
|
||||||
|
@ -198,5 +214,114 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row m-1">
|
||||||
|
<div class="col-md">
|
||||||
|
<h4>Names</h4>
|
||||||
|
{#each names as _, index}
|
||||||
|
<div class="input-group m-1">
|
||||||
|
<Button color="secondary" on:click={() => moveName(index, true)}>
|
||||||
|
<Icon name="chevron-up" />
|
||||||
|
</Button>
|
||||||
|
<Button color="secondary" on:click={() => moveName(index, false)}>
|
||||||
|
<Icon name="chevron-down" />
|
||||||
|
</Button>
|
||||||
|
<input type="text" class="form-control" bind:value={names[index].value} />
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
on:click={() => (names[index].status = WordStatus.Favourite)}
|
||||||
|
active={names[index].status === WordStatus.Favourite}
|
||||||
|
>
|
||||||
|
<Icon name="heart-fill" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
on:click={() => (names[index].status = WordStatus.Okay)}
|
||||||
|
active={names[index].status === WordStatus.Okay}
|
||||||
|
>
|
||||||
|
<Icon name="hand-thumbs-up" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
on:click={() => (names[index].status = WordStatus.Jokingly)}
|
||||||
|
active={names[index].status === WordStatus.Jokingly}
|
||||||
|
>
|
||||||
|
<Icon name="emoji-laughing" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
on:click={() => (names[index].status = WordStatus.FriendsOnly)}
|
||||||
|
active={names[index].status === WordStatus.FriendsOnly}
|
||||||
|
>
|
||||||
|
<Icon name="people" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
on:click={() => (names[index].status = WordStatus.Avoid)}
|
||||||
|
active={names[index].status === WordStatus.Avoid}
|
||||||
|
>
|
||||||
|
<Icon name="hand-thumbs-down" />
|
||||||
|
</Button>
|
||||||
|
<Button color="danger">
|
||||||
|
<Icon name="trash3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row m-1">
|
||||||
|
<div class="col-md">
|
||||||
|
<h4>Pronouns</h4>
|
||||||
|
{#each pronouns as _, index}
|
||||||
|
<div class="input-group m-1">
|
||||||
|
<Button color="secondary" on:click={() => movePronoun(index, true)}>
|
||||||
|
<Icon name="chevron-up" />
|
||||||
|
</Button>
|
||||||
|
<Button color="secondary" on:click={() => movePronoun(index, false)}>
|
||||||
|
<Icon name="chevron-down" />
|
||||||
|
</Button>
|
||||||
|
<input type="text" class="form-control" bind:value={pronouns[index].pronouns} />
|
||||||
|
<input type="text" class="form-control" bind:value={pronouns[index].display_text} />
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
on:click={() => (pronouns[index].status = WordStatus.Favourite)}
|
||||||
|
active={pronouns[index].status === WordStatus.Favourite}
|
||||||
|
>
|
||||||
|
<Icon name="heart-fill" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
on:click={() => (pronouns[index].status = WordStatus.Okay)}
|
||||||
|
active={pronouns[index].status === WordStatus.Okay}
|
||||||
|
>
|
||||||
|
<Icon name="hand-thumbs-up" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
on:click={() => (pronouns[index].status = WordStatus.Jokingly)}
|
||||||
|
active={pronouns[index].status === WordStatus.Jokingly}
|
||||||
|
>
|
||||||
|
<Icon name="emoji-laughing" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
on:click={() => (pronouns[index].status = WordStatus.FriendsOnly)}
|
||||||
|
active={pronouns[index].status === WordStatus.FriendsOnly}
|
||||||
|
>
|
||||||
|
<Icon name="people" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
on:click={() => (pronouns[index].status = WordStatus.Avoid)}
|
||||||
|
active={pronouns[index].status === WordStatus.Avoid}
|
||||||
|
>
|
||||||
|
<Icon name="hand-thumbs-down" />
|
||||||
|
</Button>
|
||||||
|
<Button color="danger">
|
||||||
|
<Icon name="trash3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
5
frontend/static/robots.txt
Normal file
5
frontend/static/robots.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
User-agent: *
|
||||||
|
Disallow: /@*
|
||||||
|
Disallow: /auth
|
||||||
|
Disallow: /settings
|
||||||
|
Disallow: /edit
|
Loading…
Reference in a new issue