Fixes according to Stephen's code review

This commit is contained in:
Austin Chen 2022-02-17 17:13:17 -08:00
parent 02cc6d86f5
commit 51d7448879
4 changed files with 23 additions and 12 deletions

View File

@ -14,7 +14,7 @@ service cloud.firestore {
match /users/{userId} { match /users/{userId} {
allow read; allow read;
allow update: if resource.data.id == request.auth.uid allow update: if resource.data.id == request.auth.uid
|| request.resource.data.diff(resource.data).affectedKeys() && request.resource.data.diff(resource.data).affectedKeys()
.hasOnly(['bio', 'bannerUrl', 'website', 'twitterHandle', 'discordHandle']); .hasOnly(['bio', 'bannerUrl', 'website', 'twitterHandle', 'discordHandle']);
} }

View File

@ -35,7 +35,7 @@ function getNavigationOptions(
href: user ? '/home' : '/', href: user ? '/home' : '/',
}, },
{ {
name: `@${user?.username}`, name: `Your profile`,
href: `/${user?.username}`, href: `/${user?.username}`,
}, },
...(mobile ...(mobile

View File

@ -132,6 +132,7 @@ export function UserPage(props: { user: User; currentUser?: User }) {
} }
// Assign each user to a random default banner based on the hash of userId // Assign each user to a random default banner based on the hash of userId
// TODO: Consider handling banner uploads using our own storage bucket, like user avatars.
export function defaultBannerUrl(userId: string) { export function defaultBannerUrl(userId: string) {
const defaultBanner = [ const defaultBanner = [
'https://images.unsplash.com/photo-1501523460185-2aa5d2a0f981?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2131&q=80', 'https://images.unsplash.com/photo-1501523460185-2aa5d2a0f981?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2131&q=80',

View File

@ -20,31 +20,41 @@ import { User } from '../../common/user'
import { updateUser } from '../lib/firebase/users' import { updateUser } from '../lib/firebase/users'
import { defaultBannerUrl } from '../components/user-page' import { defaultBannerUrl } from '../components/user-page'
import { SiteLink } from '../components/site-link' import { SiteLink } from '../components/site-link'
import Textarea from 'react-expanding-textarea'
function EditUserField(props: { function EditUserField(props: {
user: User user: User
field: 'bio' | 'bannerUrl' | 'twitterHandle' | 'discordHandle' field: 'bio' | 'bannerUrl' | 'twitterHandle' | 'discordHandle'
label: string label: string
isEditing: boolean
}) { }) {
const { user, field, label, isEditing } = props const { user, field, label } = props
const [value, setValue] = useState(user[field] ?? '') const [value, setValue] = useState(user[field] ?? '')
async function updateField() { async function updateField() {
await updateUser(user.id, { [field]: value }) // Note: We trim whitespace before uploading to Firestore
await updateUser(user.id, { [field]: value.trim() })
} }
return ( return (
<div> <div>
<label className="label">{label}</label> <label className="label">{label}</label>
<input {field === 'bio' ? (
type="text" <Textarea
className="input input-bordered" className="textarea textarea-bordered w-full"
value={value} value={value}
onChange={(e) => setValue(e.target.value || '')} onChange={(e) => setValue(e.target.value)}
onBlur={updateField} onBlur={updateField}
/> />
) : (
<input
type="text"
className="input input-bordered"
value={value}
onChange={(e) => setValue(e.target.value || '')}
onBlur={updateField}
/>
)}
</div> </div>
) )
} }