Skip to content

Commit

Permalink
Let API shrink images
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentTreguier committed Oct 8, 2024
1 parent 7d887d8 commit 01b0a7e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/lib/data/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
"errors": {
"413": {
"title": "File too large",
"message": "This file is too heavy; please select a file under 1M."
"message": "Uploaded files can only go up to 10M."
},
"415": {
"title": "Unsupported file format",
"message": "This file you have selected is not supported."
"message": "The type of file you have selected is not supported."
}
}
},
Expand Down
15 changes: 8 additions & 7 deletions src/routes/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import List from '$lib/components/list.svelte';
import Button from '$lib/components/inputs/button.svelte';
import EditableAvatar from './editable-avatar.svelte';
import Loader from '$lib/components/inputs/button/loader.svelte';
const isRegistering = writable(false);
const token = writable<string | null>(null);
let currentUser: User | null = null;
let isAvatarLoading = false;
let isLoadingAvatar = false;
onMount(() =>
token.subscribe(async ($token) => {
Expand All @@ -37,15 +38,15 @@
return call(
async () => {
try {
isAvatarLoading = true;
isLoadingAvatar = true;
const client = await getUsersClient();
const avatar = await client.setCurrentUserAvatar(event.detail);
if (currentUser) {
currentUser = { ...currentUser, avatar };
}
} finally {
isAvatarLoading = false;
isLoadingAvatar = false;
}
},
async (error) => {
Expand All @@ -65,15 +66,15 @@
return call(
async () => {
try {
isAvatarLoading = true;
isLoadingAvatar = true;
const client = await getUsersClient();
await client.deleteCurrentUserAvatar();
if (currentUser) {
currentUser = { ...currentUser, avatar: '' };
}
} finally {
isAvatarLoading = false;
isLoadingAvatar = false;
}
},
async () => new DisplayableError()
Expand Down Expand Up @@ -101,14 +102,14 @@
<tr>
<td>
<div class="avatar-wrapper">
<EditableAvatar user={currentUser} on:file={updateAvatar} />
<EditableAvatar user={currentUser} loading={isLoadingAvatar} on:file={updateAvatar} />
</div>
</td>
<td>
<Button
type="button"
disabled={!currentUser?.avatar}
loading={isAvatarLoading}
loading={isLoadingAvatar}
on:click={removeAvatar}
>
{t('settings.profile.avatar.remove')}
Expand Down
27 changes: 19 additions & 8 deletions src/routes/settings/editable-avatar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@
import ImagePicker from '$lib/components/inputs/image-picker.svelte';
import Icon from '$lib/components/icon.svelte';
import EditIcon from '$lib/components/icons/edit.svelte';
import Loader from '$lib/components/inputs/button/loader.svelte';
export let user: User | null = null;
export let loading = false;
</script>

<ImagePicker title={t('settings.profile.avatar.change')} on:file>
<Avatar {user} size={100} />
<span class="edit-icon">
<Icon size="32px"><EditIcon /></Icon>
<span class="overlay" class:loading>
{#if loading}
<Loader />
{:else}
<span class="edit-icon">
<Icon size="32px"><EditIcon /></Icon>
</span>
{/if}
</span>
</ImagePicker>

<style lang="scss">
.edit-icon {
.overlay {
position: absolute;
width: 100%;
height: 100%;
Expand All @@ -31,12 +39,15 @@
cursor: pointer;
transition: 0.1s;
@media (hover: none) {
display: none;
}
&:not(.loading) {
@media (hover: none) {
display: none;
}
&:not(:hover) {
opacity: 0;
&:not(:hover),
&:not(:hover) .edit-icon {
opacity: 0;
}
}
}
</style>

0 comments on commit 01b0a7e

Please sign in to comment.