add: profile backgrounds

This commit is contained in:
Mar0xy 2023-10-06 02:32:09 +02:00
parent 6dd0b88050
commit 4e64397635
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
14 changed files with 205 additions and 4 deletions

View file

@ -22,6 +22,10 @@ SPDX-License-Identifier: AGPL-3.0-only
<img :class="$style.labelImg" src="/client-assets/label.svg"/>
<p :class="$style.labelText">{{ i18n.ts.banner }}</p>
</div>
<div v-if="$i?.backgroundId == file.id" :class="[$style.label]">
<img :class="$style.labelImg" src="/client-assets/label.svg"/>
<p :class="$style.labelText">Background</p>
</div>
<div v-if="file.isSensitive" :class="[$style.label, $style.red]">
<img :class="$style.labelImg" src="/client-assets/label-red.svg"/>
<p :class="$style.labelText">{{ i18n.ts.sensitive }}</p>

View file

@ -10,9 +10,11 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkAvatar :class="$style.avatar" :user="$i" @click="changeAvatar"/>
<MkButton primary rounded @click="changeAvatar">{{ i18n.ts._profile.changeAvatar }}</MkButton>
</div>
<MkButton primary rounded :class="$style.backgroundEdit" @click="changeBackground">Change Background</MkButton>
<MkButton primary rounded :class="$style.bannerEdit" @click="changeBanner">{{ i18n.ts._profile.changeBanner }}</MkButton>
</div>
<MkInput v-model="profile.name" :max="30" manualSave>
<template #label>{{ i18n.ts._profile.name }}</template>
</MkInput>
@ -254,6 +256,31 @@ function changeBanner(ev) {
});
}
function changeBackground(ev) {
selectFile(ev.currentTarget ?? ev.target, i18n.ts.banner).then(async (file) => {
let originalOrCropped = file;
const { canceled } = await os.confirm({
type: 'question',
text: i18n.t('cropImageAsk'),
okText: i18n.ts.cropYes,
cancelText: i18n.ts.cropNo,
});
if (!canceled) {
originalOrCropped = await os.cropImage(file, {
aspectRatio: 1,
});
}
const i = await os.apiWithDialog('i/update', {
backgroundId: originalOrCropped.id,
});
$i.backgroundId = i.backgroundId;
$i.backgroundUrl = i.backgroundUrl;
});
}
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);
@ -292,6 +319,11 @@ definePageMetadata({
top: 16px;
right: 16px;
}
.backgroundEdit {
position: absolute;
top: 103px;
right: 16px;
}
.metadataRoot {
container-type: inline-size;

View file

@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<MkSpacer :contentMax="narrow ? 800 : 1100">
<MkSpacer :contentMax="narrow ? 800 : 1100" :style="background">
<div ref="rootEl" class="ftskorzw" :class="{ wide: !narrow }" style="container-type: inline-size;">
<div class="main _gaps">
<!-- TODO -->
@ -236,6 +236,13 @@ if (props.user.listenbrainz) {
}
}
const background = computed(() => {
if (props.user.backgroundUrl == null) return {};
return {
'--backgroundImageStatic': `url('${props.user.backgroundUrl}')`
};
});
watch($$(moderationNote), async () => {
await os.api('admin/update-user-note', { userId: props.user.id, text: moderationNote });
});
@ -338,6 +345,24 @@ onUnmounted(() => {
<style lang="scss" scoped>
.ftskorzw {
&::before {
content: "";
position: fixed;
inset: 0;
background: var(--backgroundImageStatic);
background-size: cover;
background-position: center;
pointer-events: none;
filter: blur(8px) opacity(0.6);
// Funny CSS schenanigans to make background escape container
padding-left: 20px;
margin-left: -20px;
padding-right: 20px;
margin-right: -20px;
padding-top: 20px;
margin-top: -20px;
background-attachment: fixed;
}
> .main {