aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/user/User.tsx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-06-11 17:27:15 +0800
committercrupest <crupest@outlook.com>2020-06-11 17:27:15 +0800
commitcf6cfe87b46a2a3eb2913209092ab4c5639e75c3 (patch)
treeeba7504d04dad89f67524b48d88a3b5eb27de6de /Timeline/ClientApp/src/app/user/User.tsx
parent4b8abdd1921935ebb29d18961534db04a2e58fbb (diff)
downloadtimeline-cf6cfe87b46a2a3eb2913209092ab4c5639e75c3.tar.gz
timeline-cf6cfe87b46a2a3eb2913209092ab4c5639e75c3.tar.bz2
timeline-cf6cfe87b46a2a3eb2913209092ab4c5639e75c3.zip
feat(front): Service worker is coming!
Diffstat (limited to 'Timeline/ClientApp/src/app/user/User.tsx')
-rw-r--r--Timeline/ClientApp/src/app/user/User.tsx79
1 files changed, 79 insertions, 0 deletions
diff --git a/Timeline/ClientApp/src/app/user/User.tsx b/Timeline/ClientApp/src/app/user/User.tsx
new file mode 100644
index 00000000..0e1977b1
--- /dev/null
+++ b/Timeline/ClientApp/src/app/user/User.tsx
@@ -0,0 +1,79 @@
+import React, { useState } from 'react';
+import { useParams } from 'react-router';
+
+import { useUser } from '../data/user';
+import { changeNickname, changeAvatar } from './api';
+import { personalTimelineService } from '../data/timeline';
+
+import UserPage from './UserPage';
+import ChangeNicknameDialog from './ChangeNicknameDialog';
+import ChangeAvatarDialog from './ChangeAvatarDialog';
+import TimelinePageTemplate from '../timeline/TimelinePageTemplate';
+import { PersonalTimelineManageItem } from './UserInfoCard';
+import { UiLogicError } from '../common';
+
+const User: React.FC = (_) => {
+ const { username } = useParams<{ username: string }>();
+
+ const user = useUser();
+
+ const [dialog, setDialog] = useState<null | PersonalTimelineManageItem>(null);
+ const [dataKey, setDataKey] = useState<number>(0);
+
+ let dialogElement: React.ReactElement | undefined;
+
+ const closeDialogHandler = (): void => {
+ setDialog(null);
+ };
+
+ if (dialog === 'nickname') {
+ if (user == null) {
+ throw new UiLogicError('Change nickname without login.');
+ }
+
+ dialogElement = (
+ <ChangeNicknameDialog
+ open
+ close={closeDialogHandler}
+ onProcess={(newNickname) => {
+ const p = changeNickname(user.token, username, newNickname);
+ return p.then((_) => {
+ setDataKey(dataKey + 1);
+ });
+ }}
+ />
+ );
+ } else if (dialog === 'avatar') {
+ if (user == null) {
+ throw new UiLogicError('Change avatar without login.');
+ }
+
+ dialogElement = (
+ <ChangeAvatarDialog
+ open
+ close={closeDialogHandler}
+ process={(file) => changeAvatar(user.token, username, file, file.type)}
+ />
+ );
+ }
+
+ const onManage = React.useCallback((item: PersonalTimelineManageItem) => {
+ setDialog(item);
+ }, []);
+
+ return (
+ <>
+ <TimelinePageTemplate
+ dataVersion={dataKey}
+ name={username}
+ UiComponent={UserPage}
+ onManage={onManage}
+ service={personalTimelineService}
+ notFoundI18nKey="timeline.userNotExist"
+ />
+ {dialogElement}
+ </>
+ );
+};
+
+export default User;