Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile chips ( Awards ) #240

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
21 changes: 21 additions & 0 deletions express-api/src/models/profile/award/award.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Joi from '@hapi/joi';
import { Schema } from 'mongoose';

export interface Award {
_id?: string;

text?: string;
color?: string;
}

export const Award = new Schema<Award>({
text: { type: String },
color: { type: String },
});

export const AwardJoi = Joi.object().keys({
_id: Joi.string().regex(/^[a-f\d]{24}$/i),

text: Joi.string(),
color: Joi.string().regex(/^#((0x){0,1}|#{0,1})([0-9A-F]{8}|[0-9A-F]{6})$/i),
});
1 change: 1 addition & 0 deletions express-api/src/models/profile/award/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './award';
4 changes: 4 additions & 0 deletions express-api/src/models/profile/profile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Joi from '@hapi/joi';
import { Document, model, Schema } from 'mongoose';

import { Award, AwardJoi } from './award';
import { Game, GameJoi } from './game';

export interface Profile {
Expand All @@ -18,6 +19,7 @@ export interface Profile {
discordUsername?: string;

games?: Game[];
awards?: Award[];
}

export type ProfileDocument = Profile & Document;
Expand All @@ -35,6 +37,7 @@ export const Profile = model<ProfileDocument>('Profile', new Schema<Profile>({
discordUsername: String,

games: [Game],
awards: [{ type: Award, immutable: true }],
}));

export const ProfileJoi = Joi.object().keys({
Expand All @@ -52,4 +55,5 @@ export const ProfileJoi = Joi.object().keys({
discordUsername: Joi.string().regex(/.+#\d{4}/i),

games: Joi.array().items(GameJoi).max(20),
awards: Joi.array().items(AwardJoi),
});
18 changes: 16 additions & 2 deletions react-app/src/components/cards/Profile/ProfileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React from 'react';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import CardMedia from '@material-ui/core/CardMedia';
import Chip from '@material-ui/core/Chip';
import Divider from '@material-ui/core/Divider';
import Grid from '@material-ui/core/Grid';
import Typography from '@material-ui/core/Typography';
import { createStyles, makeStyles } from '@material-ui/core/styles';

Expand All @@ -11,15 +13,18 @@ import Profile from '../../../models/profile';

const useStyles = makeStyles((theme) => createStyles({
card: {
minHeight: '26rem',
width: '18rem',
minHeight: theme.spacing(52),
width: theme.spacing(36),
},
username: {
marginBottom: theme.spacing(1),
},
bio: {
marginTop: theme.spacing(1),
},
awards: {
marginTop: theme.spacing(1),
},
}));

type Props = {
Expand All @@ -43,6 +48,15 @@ const ProfileCard: React.FC<Props> = ({ profile, children }) => {
<Typography variant="h5" align="center" className={classes.username}>{profile.name || 'About'}</Typography>
<Divider />
<Typography align="center" className={classes.bio}>{profile.bio || 'No Profile Bio'}</Typography>
{!!profile.awards?.length && (
<Grid container justify="center" spacing={1} className={classes.awards}>
{profile.awards.map((award) => (
<Grid item key={award._id}>
<Chip label={award.text} variant="outlined" style={{ borderColor: award.color }} />
</Grid>
))}
</Grid>
)}
</>
))}
</CardContent>
Expand Down
8 changes: 8 additions & 0 deletions react-app/src/models/profile/award/award.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ObjectID from 'bson-objectid';

export default class Award {
_id = new ObjectID().toHexString();

text = '';
color = '#F25822';
}
1 change: 1 addition & 0 deletions react-app/src/models/profile/award/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './award';
2 changes: 2 additions & 0 deletions react-app/src/models/profile/profile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ObjectID from 'bson-objectid';

import Game from './game';
import Award from './award';

export default class Profile {
_id = new ObjectID().toHexString();
Expand All @@ -17,4 +18,5 @@ export default class Profile {
discordUsername?: string;

games?: Game[];
awards?: Award[];
}