mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 16:20:04 +00:00
Bugfix in avatar management
This commit is contained in:
@@ -10,7 +10,7 @@ import UserUpdateDto from "Frontend/generated/de/grimsi/gameyfin/users/dto/UserU
|
|||||||
import {UserEndpoint} from "Frontend/generated/endpoints";
|
import {UserEndpoint} from "Frontend/generated/endpoints";
|
||||||
import {SmallInfoField} from "Frontend/components/general/SmallInfoField";
|
import {SmallInfoField} from "Frontend/components/general/SmallInfoField";
|
||||||
import {toast} from "sonner";
|
import {toast} from "sonner";
|
||||||
import FileUpload from "Frontend/components/general/FileUpload";
|
import AvatarUpload from "Frontend/components/general/AvatarUpload";
|
||||||
|
|
||||||
export default function ProfileManagement() {
|
export default function ProfileManagement() {
|
||||||
const [configSaved, setConfigSaved] = useState(false);
|
const [configSaved, setConfigSaved] = useState(false);
|
||||||
@@ -90,13 +90,12 @@ export default function ProfileManagement() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-row flex-1 justify-between gap-8">
|
<div className="flex flex-row flex-1 justify-between gap-16">
|
||||||
<div className="flex flex-col basis-1/4 items-center">
|
<div className="flex flex-col basis-1/4 mt-8 items-center">
|
||||||
<Section title="Avatar"></Section>
|
|
||||||
<Avatar showFallback
|
<Avatar showFallback
|
||||||
src={`/images/avatar?username=${auth.state.user?.username}`}
|
src={`/images/avatar?username=${auth.state.user?.username}`}
|
||||||
className="size-40 m-4"></Avatar>
|
className="size-40 m-4"></Avatar>
|
||||||
<FileUpload upload="/avatar/upload" clear="/avatar/delete" accept="image/*"/>
|
<AvatarUpload upload="/avatar/upload" remove="/avatar/delete" accept="image/*"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col flex-grow">
|
<div className="flex flex-col flex-grow">
|
||||||
|
|||||||
+5
-5
@@ -4,7 +4,7 @@ import {Button, Input, Tooltip} from "@nextui-org/react";
|
|||||||
import {useState} from "react";
|
import {useState} from "react";
|
||||||
import {Trash} from "@phosphor-icons/react";
|
import {Trash} from "@phosphor-icons/react";
|
||||||
|
|
||||||
export default function FileUpload({upload, clear, accept}: { upload: string, clear: string, accept: string }) {
|
export default function AvatarUpload({upload, remove, accept}: { upload: string, remove: string, accept: string }) {
|
||||||
|
|
||||||
const [avatar, setAvatar] = useState<any>();
|
const [avatar, setAvatar] = useState<any>();
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ export default function FileUpload({upload, clear, accept}: { upload: string, cl
|
|||||||
const result = await response.text();
|
const result = await response.text();
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
toast.success("Avatar updated");
|
window.location.reload();
|
||||||
} else {
|
} else {
|
||||||
toast.error("Error uploading avatar", {description: result});
|
toast.error("Error uploading avatar", {description: result});
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ export default function FileUpload({upload, clear, accept}: { upload: string, cl
|
|||||||
|
|
||||||
async function removeAvatar() {
|
async function removeAvatar() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(clear, {
|
const response = await fetch(remove, {
|
||||||
headers: {
|
headers: {
|
||||||
"X-CSRF-Token": getCsrfToken()
|
"X-CSRF-Token": getCsrfToken()
|
||||||
},
|
},
|
||||||
@@ -51,7 +51,7 @@ export default function FileUpload({upload, clear, accept}: { upload: string, cl
|
|||||||
const result = await response.text();
|
const result = await response.text();
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
toast.success("Avatar removed");
|
window.location.reload();
|
||||||
} else {
|
} else {
|
||||||
toast.error("Error removing avatar", {description: result});
|
toast.error("Error removing avatar", {description: result});
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ export default function FileUpload({upload, clear, accept}: { upload: string, cl
|
|||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<div className="flex flex-row gap-2">
|
<div className="flex flex-row gap-2">
|
||||||
<Input type="file" accept={accept} onChange={onFileSelected}/>
|
<Input type="file" accept={accept} onChange={onFileSelected}/>
|
||||||
<Button onClick={uploadAvatar} color="success">Upload</Button>
|
<Button onClick={uploadAvatar} isDisabled={avatar == null} color="success">Upload</Button>
|
||||||
<Tooltip content="Remove your current avatar">
|
<Tooltip content="Remove your current avatar">
|
||||||
<Button onClick={removeAvatar} isIconOnly color="danger"><Trash/></Button>
|
<Button onClick={removeAvatar} isIconOnly color="danger"><Trash/></Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
@@ -78,6 +78,8 @@ class UserService(
|
|||||||
fun deleteAvatar(username: String) {
|
fun deleteAvatar(username: String) {
|
||||||
val user = userByUsername(username)
|
val user = userByUsername(username)
|
||||||
|
|
||||||
|
if (user.avatar == null) return
|
||||||
|
|
||||||
avatarStore.unsetContent(user.avatar)
|
avatarStore.unsetContent(user.avatar)
|
||||||
user.avatar = null
|
user.avatar = null
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user