diff options
author | crupest <crupest@outlook.com> | 2022-03-09 17:55:23 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-09 17:55:23 +0800 |
commit | b89ea2e72451133ca8be185de882aa848c277638 (patch) | |
tree | 754a73895af5bd10516c8de492124329a384509b /FrontEnd/src/views/settings/ChangeAvatarDialog.tsx | |
parent | 8e70994392d1be20dbd38c56e7cd44400d01f79e (diff) | |
download | timeline-b89ea2e72451133ca8be185de882aa848c277638.tar.gz timeline-b89ea2e72451133ca8be185de882aa848c277638.tar.bz2 timeline-b89ea2e72451133ca8be185de882aa848c277638.zip |
...
Diffstat (limited to 'FrontEnd/src/views/settings/ChangeAvatarDialog.tsx')
-rw-r--r-- | FrontEnd/src/views/settings/ChangeAvatarDialog.tsx | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/FrontEnd/src/views/settings/ChangeAvatarDialog.tsx b/FrontEnd/src/views/settings/ChangeAvatarDialog.tsx index c33687df..045ec00f 100644 --- a/FrontEnd/src/views/settings/ChangeAvatarDialog.tsx +++ b/FrontEnd/src/views/settings/ChangeAvatarDialog.tsx @@ -2,9 +2,9 @@ import React, { useState, useEffect } from "react"; import { useTranslation } from "react-i18next"; import { AxiosError } from "axios"; -import { UiLogicError } from "@/common"; +import { convertI18nText, I18nText, UiLogicError } from "@/common"; -import { useUserLoggedIn } from "@/services/user"; +import { useUser } from "@/services/user"; import { getHttpUserClient } from "@/http/user"; @@ -20,7 +20,7 @@ export interface ChangeAvatarDialogProps { const ChangeAvatarDialog: React.FC<ChangeAvatarDialogProps> = (props) => { const { t } = useTranslation(); - const user = useUserLoggedIn(); + const user = useUser(); const [file, setFile] = React.useState<File | null>(null); const [fileUrl, setFileUrl] = React.useState<string | null>(null); @@ -40,16 +40,11 @@ const ChangeAvatarDialog: React.FC<ChangeAvatarDialogProps> = (props) => { | "error" >("select"); - const [message, setMessage] = useState< - string | { type: "custom"; text: string } | null - >("settings.dialogChangeAvatar.prompt.select"); + const [message, setMessage] = useState<I18nText>( + "settings.dialogChangeAvatar.prompt.select" + ); - const trueMessage = - message == null - ? null - : typeof message === "string" - ? t(message) - : message.text; + const trueMessage = convertI18nText(message, t); const closeDialog = props.close; @@ -130,6 +125,10 @@ const ChangeAvatarDialog: React.FC<ChangeAvatarDialogProps> = (props) => { throw new UiLogicError(); } + if (user == null) { + throw new UiLogicError(); + } + setState("uploading"); getHttpUserClient() .putAvatar(user.username, resultBlob) @@ -139,10 +138,10 @@ const ChangeAvatarDialog: React.FC<ChangeAvatarDialogProps> = (props) => { }, (e: unknown) => { setState("error"); - setMessage({ type: "custom", text: (e as AxiosError).message }); + setMessage({ type: "custom", value: (e as AxiosError).message }); } ); - }, [user.username, resultBlob]); + }, [user, resultBlob]); const createPreviewRow = (): React.ReactElement => { if (resultUrl == null) { |