import React from 'react' import Layout from '../components/layout' import { callAPI } from '../utils/api' import { capitalize, getAvatarOfFallback } from '../utils/misc' import { withAuthSync } from '../utils/auth' const avatars = ['anteater', 'bear', 'beaver', 'boar', 'buffalo-1', 'buffalo', 'cat', 'chicken', 'cow', 'crow', 'dog-1', 'dog', 'donkey', 'elephant', 'fox', 'giraffe', 'hedgehog', 'hen', 'hippopotamus', 'horse', 'kangaroo', 'koala', 'leopard', 'lion', 'marten', 'monkey-1', 'monkey', 'mouse', 'octopus', 'ostrich', 'owl', 'panda', 'parrot', 'penguin-1', 'penguin', 'pig', 'polar-bear', 'rabbit', 'racoon', 'rhinoceros', 'rooster', 'seagull', 'seal', 'sheep-1', 'sheep', 'sloth', 'snake', 'tiger', 'whale', 'zebra'] const selectAvatar = avatar => callAPI(null, { url: `/api/users/me/avatar`, method: 'post', data: { avatar }, }).then(() => location.reload()).catch(() => alert('There was a problem deleting the purchase')) const Me = me => { const { name, debts, purchases, avatar } = me return

{capitalize(name)}

Current Avatar
avatar-icon

Select Avatar
{avatars.map((avatar, i) => selectAvatar(avatar)} key={i} alt="avatar-icon" src={`/static/icons/animals/${avatar}.svg`} className="avatar avatar-md m-1" />)}
{/*

*/} {/*

Purchases

*/} {/*{purchases.map((purchase, i) => )}*/} {/*

*/} {/*

Debts

*/} {/*{debts.map((purchase, i) => )}*/} {/* language=CSS */}
} Me.getInitialProps = async ctx => await callAPI(ctx, { url: `/api/users/me` }) export default withAuthSync(Me)