diff options
| author | lonkaars <l.leblansch@gmail.com> | 2021-03-14 14:51:43 +0100 | 
|---|---|---|
| committer | lonkaars <l.leblansch@gmail.com> | 2021-03-14 14:51:43 +0100 | 
| commit | 7b2c1682c326d8194397fb43825c602da6a6c915 (patch) | |
| tree | 377ad66210308924436df30806150ac7a6a2b072 | |
| parent | 7ad4c4a45d9ce21e164f0dcfb5e22b23b97c1b31 (diff) | |
avatar working
| -rw-r--r-- | components/account.tsx | 40 | ||||
| -rw-r--r-- | components/navbar.tsx | 2 | ||||
| -rw-r--r-- | pages/index.tsx | 2 | ||||
| -rw-r--r-- | pages/search.tsx | 2 | ||||
| -rw-r--r-- | pages/settings.tsx | 2 | ||||
| -rw-r--r-- | pages/user.tsx | 2 | 
6 files changed, 28 insertions, 22 deletions
diff --git a/components/account.tsx b/components/account.tsx index 603e015..005e0d1 100644 --- a/components/account.tsx +++ b/components/account.tsx @@ -1,27 +1,33 @@ -import { Component } from "react"; +import { useState, useEffect } from 'react'; -interface AccountAvatarProps { +var dummy = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQYV2P4z/j/PwAHAQL/gXZXNQAAAABJRU5ErkJggg=="; + +export function AccountAvatar(props: {  	size: number; -	image?: string;  	dummy?: boolean;  	fallbackFill?: string;  	round?: boolean; -} -export class AccountAvatar extends Component<AccountAvatarProps> { -	render() { -		var image = this.props.dummy ? -			"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQYV2P4z/j/PwAHAQL/gXZXNQAAAABJRU5ErkJggg==)" : -			this.props.image; -		return <div style={{ -			width: this.props.size, -			height: this.props.size, -			backgroundImage: image, -			backgroundSize: "cover", -			display: "inline-block", -			borderRadius: this.props.size / 2 * Number(this.props.round || 0) -		}}/>; +	id?: string; +}) { +	var image = ""; +	image += "/api/user/avatar"; +	if (typeof props.id === "string") { +		if (!props.id) image = ""; +		else image += `?id=${props.id}`;  	} + +	if (props.dummy) image = dummy; + +	return <div style={{ +		width: props.size, +		height: props.size, +		backgroundColor: props.fallbackFill || "var(--background)", +		backgroundImage: `url(${image})`, +		backgroundSize: "cover", +		display: "inline-block", +		borderRadius: props.size / 2 * Number(props.round || 0) +	}}/>;  } diff --git a/components/navbar.tsx b/components/navbar.tsx index 3eabe2d..2c38c3c 100644 --- a/components/navbar.tsx +++ b/components/navbar.tsx @@ -99,7 +99,7 @@ export function NavBar() {  			<a href={loggedIn ? "/user" : "/login"} style={NavBarItemStyle}>  				{  					loggedIn ? -					<AccountAvatar size={24} dummy round/> : +					<AccountAvatar size={24} round/> :  					<PersonIcon/>  				}  			</a> diff --git a/pages/index.tsx b/pages/index.tsx index 719f9ea..41da36e 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -87,7 +87,7 @@ function AccountBox(props: {  			top: 0, left: 0,  			...SquareSize  		}}> -			<AccountAvatar size={90} dummy/> +			<AccountAvatar size={90}/>  		</div>  		<div style={{  			position: "absolute", diff --git a/pages/search.tsx b/pages/search.tsx index 66e16d2..50a2410 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -34,7 +34,7 @@ function SearchResult(props: { user: userInfo }) {  		padding: 12  	}} fullwidth href={"/user?id=" + props.user.id}>  		<div style={{ position: "relative" }}> -			<AccountAvatar size={48} dummy/> +			<AccountAvatar size={48} id={props.user.id}/>  			<div style={{  				position: "absolute",  				top: 0, right: 0, bottom: 0, diff --git a/pages/settings.tsx b/pages/settings.tsx index a713a5a..19208df 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -28,7 +28,7 @@ export default function SettingsPage() {  				<Vierkant fullwidth>  					<h2>Account</h2>  					<div style={SettingsSubsectionStyle}> -						<AccountAvatar size={100} dummy/> +						<AccountAvatar size={100}/>  						<IconLabelButton text="Profielfoto veranderen" icon={<EditOutlinedIcon/>}/>  					</div>  					<div style={SettingsSubsectionStyle}> diff --git a/pages/user.tsx b/pages/user.tsx index 8d4fb8d..c963550 100644 --- a/pages/user.tsx +++ b/pages/user.tsx @@ -136,7 +136,7 @@ export default function AccountPage() {  		<CenteredPage width={802}>  			<PageTitle>Profiel</PageTitle>  			<Vierkant fullwidth> -				<AccountAvatar size={128} dummy/> +				<AccountAvatar size={128} id={user?.id || ""}/>  				<div style={{  					display: "inline-block",  					verticalAlign: "top",  |