@@ -81,17 +76,11 @@ export default function Notifications(props: { user: User }) {
tabs={[
{
title: 'Notifications',
- content: privateUser ? (
+ content: (
- ) : (
-
-
-
),
},
{
diff --git a/web/pages/profile.tsx b/web/pages/profile.tsx
index 541f5de9..42bcb5c3 100644
--- a/web/pages/profile.tsx
+++ b/web/pages/profile.tsx
@@ -1,25 +1,35 @@
-import React, { useEffect, useState } from 'react'
+import React, { useState } from 'react'
import { RefreshIcon } from '@heroicons/react/outline'
import { AddFundsButton } from 'web/components/add-funds-button'
import { Page } from 'web/components/page'
import { SEO } from 'web/components/SEO'
import { Title } from 'web/components/title'
-import { usePrivateUser, useUser } from 'web/hooks/use-user'
import { formatMoney } from 'common/util/format'
import { cleanDisplayName, cleanUsername } from 'common/util/clean-username'
import { changeUserInfo } from 'web/lib/firebase/api'
import { uploadImage } from 'web/lib/firebase/storage'
import { Col } from 'web/components/layout/col'
import { Row } from 'web/components/layout/row'
-import { User } from 'common/user'
-import { updateUser, updatePrivateUser } from 'web/lib/firebase/users'
+import { User, PrivateUser } from 'common/user'
+import {
+ getUser,
+ getPrivateUser,
+ updateUser,
+ updatePrivateUser,
+} from 'web/lib/firebase/users'
import { defaultBannerUrl } from 'web/components/user-page'
import { SiteLink } from 'web/components/site-link'
import Textarea from 'react-expanding-textarea'
import { redirectIfLoggedOut } from 'web/lib/firebase/server-auth'
-export const getServerSideProps = redirectIfLoggedOut('/')
+export const getServerSideProps = redirectIfLoggedOut('/', async (_, creds) => {
+ const [user, privateUser] = await Promise.all([
+ getUser(creds.user.uid),
+ getPrivateUser(creds.user.uid),
+ ])
+ return { props: { user, privateUser } }
+})
function EditUserField(props: {
user: User
@@ -58,64 +68,45 @@ function EditUserField(props: {
)
}
-export default function ProfilePage() {
- const user = useUser()
- const privateUser = usePrivateUser(user?.id)
-
- const [avatarUrl, setAvatarUrl] = useState(user?.avatarUrl || '')
+export default function ProfilePage(props: {
+ user: User
+ privateUser: PrivateUser
+}) {
+ const { user, privateUser } = props
+ const [avatarUrl, setAvatarUrl] = useState(user.avatarUrl || '')
const [avatarLoading, setAvatarLoading] = useState(false)
- const [name, setName] = useState(user?.name || '')
- const [username, setUsername] = useState(user?.username || '')
- const [apiKey, setApiKey] = useState(privateUser?.apiKey || '')
-
- useEffect(() => {
- if (user) {
- setAvatarUrl(user.avatarUrl || '')
- setName(user.name || '')
- setUsername(user.username || '')
- }
- }, [user])
-
- useEffect(() => {
- if (privateUser) {
- setApiKey(privateUser.apiKey || '')
- }
- }, [privateUser])
+ const [name, setName] = useState(user.name)
+ const [username, setUsername] = useState(user.username)
+ const [apiKey, setApiKey] = useState(privateUser.apiKey || '')
const updateDisplayName = async () => {
const newName = cleanDisplayName(name)
-
if (newName) {
setName(newName)
- await changeUserInfo({ name: newName }).catch((_) =>
- setName(user?.name || '')
- )
+ await changeUserInfo({ name: newName }).catch((_) => setName(user.name))
} else {
- setName(user?.name || '')
+ setName(user.name)
}
}
const updateUsername = async () => {
const newUsername = cleanUsername(username)
-
if (newUsername) {
setUsername(newUsername)
await changeUserInfo({ username: newUsername }).catch((_) =>
- setUsername(user?.username || '')
+ setUsername(user.username)
)
} else {
- setUsername(user?.username || '')
+ setUsername(user.username)
}
}
const updateApiKey = async (e: React.MouseEvent) => {
const newApiKey = crypto.randomUUID()
- if (user?.id != null) {
- setApiKey(newApiKey)
- await updatePrivateUser(user.id, { apiKey: newApiKey }).catch(() => {
- setApiKey(privateUser?.apiKey || '')
- })
- }
+ setApiKey(newApiKey)
+ await updatePrivateUser(user.id, { apiKey: newApiKey }).catch(() => {
+ setApiKey(privateUser.apiKey || '')
+ })
e.preventDefault()
}
@@ -124,7 +115,7 @@ export default function ProfilePage() {
setAvatarLoading(true)
- await uploadImage(user?.username || 'default', file)
+ await uploadImage(user.username, file)
.then(async (url) => {
await changeUserInfo({ avatarUrl: url })
setAvatarUrl(url)
@@ -132,14 +123,10 @@ export default function ProfilePage() {
})
.catch(() => {
setAvatarLoading(false)
- setAvatarUrl(user?.avatarUrl || '')
+ setAvatarUrl(user.avatarUrl || '')
})
}
- if (user == null) {
- return <>>
- }
-
return (
@@ -147,7 +134,7 @@ export default function ProfilePage() {
-
+
Done
@@ -192,54 +179,53 @@ export default function ProfilePage() {
/>
- {user && (
- <>
- {/* TODO: Allow users with M$ 2000 of assets to set custom banners */}
- {/*