송용우

Merge commit '7a39581f' into feature/rest_api

......@@ -13,6 +13,7 @@
"moment": "^2.27.0",
"open-color": "^1.7.0",
"react": "^16.13.1",
"react-calendar-heatmap": "^1.8.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.0",
"react-router-dom": "^5.2.0",
......
import React, { use } from 'react';
import CalendarHeatmap from 'react-calendar-heatmap';
import 'react-calendar-heatmap/dist/styles.css';
/*
TODO: 날짜 범위 지정, 날짜별 검색 추가
*/
/*
solvedBJbyDATE:
solvedBJbyDATE:{
20190304 : [Object]
...
}
*/
const HeatMap = (HMArr) => {
return (
<div>
<CalendarHeatmap
onClick={() => {
console.log(HMArr);
}}
startDate={new Date('2020-01-01')}
endDate={new Date('2020-12-01')}
values={HMArr.HMArr}
classForValue={(value) => {
if (!value) {
return 'color-empty';
}
return `color-github-${value.count}`;
}}
tooltipDataAttrs={(value) => {
return {
'data-tooltip': `${value.date} has count: ${value.count}`,
};
}}
showWeekdayLabels={true}
/>
</div>
);
};
export default HeatMap;
......@@ -3,7 +3,7 @@ import { makeStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Grid from '@material-ui/core/Grid';
import palette from '../../lib/styles/palette';
import AuthForm from '../auth/AuthForm';
import HeatMap from './HeatMap';
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
......@@ -17,7 +17,7 @@ const useStyles = makeStyles((theme) => ({
color: theme.palette.text.secondary,
},
}));
const HomeForm = ({ PSdata, goalNum }) => {
const HomeForm = ({ PSdata, HMArr, goalNum }) => {
const classes = useStyles();
return PSdata ? (
<div className={classes.root}>
......@@ -48,7 +48,11 @@ const HomeForm = ({ PSdata, goalNum }) => {
<h3>마지막으로 문제</h3>
</Paper>
</Grid>
<Grid item xs={12}>
<Paper className={classes.paper}>
<HeatMap HMArr={HMArr} />
</Paper>
</Grid>
<Grid item xs={4}>
<Paper className={classes.paper}>
<h1>{PSdata.weekNum}</h1>
......
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { withRouter } from 'react-router-dom';
import HomeForm from '../../components/home/HomeForm';
import { getPROFILE, initializeProfile } from '../../modules/profile';
const HomeContainer = ({ history }) => {
const dispatch = useDispatch();
const [HMArr, setHMArr] = useState([]);
const { user, profile } = useSelector(({ user, profile }) => ({
user: user.user,
profile: profile,
}));
const makeHeatmapValues = (PSdata) => {
let obj_keys = Object.keys(PSdata);
let result = [];
for (let i = 0; i < obj_keys.length; i++) {
result.push({
date:
//2019-10-15
obj_keys[i].slice(0, 4) +
'-' +
obj_keys[i].slice(4, 6) +
'-' +
obj_keys[i].slice(6, 8),
count: PSdata[obj_keys[i]].length,
});
}
return result;
};
useEffect(() => {
if (!user) {
alert('로그인이 필요합니다 ');
......@@ -23,7 +42,9 @@ const HomeContainer = ({ history }) => {
}
}, [dispatch, user, history]);
useEffect(() => {
console.log(profile);
if (profile.solvedBJ_date) {
setHMArr(makeHeatmapValues(profile.solvedBJ_date.solvedBJbyDATE));
}
}, [profile]);
useEffect(() => {
if (user) {
......@@ -31,6 +52,12 @@ const HomeContainer = ({ history }) => {
dispatch(getPROFILE({ username }));
}
}, [dispatch, user]);
return <HomeForm PSdata={profile.solvedBJ_date} goalNum={profile.goalNum} />;
return (
<HomeForm
PSdata={profile.solvedBJ_date}
HMArr={HMArr}
goalNum={profile.goalNum}
/>
);
};
export default withRouter(HomeContainer);
......
This diff is collapsed. Click to expand it.
......@@ -2,47 +2,48 @@ const mongoose = require("mongoose");
const { Schema } = mongoose;
const ChallengeSchema = new Schema(
{
challengeName: { type: String, required: true },
startDate: { type: Object, required: true },
endDate: { type: Object, required: true },
durationPerSession: { type: String, required: true }, // '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session.
goalPerSession: { type: Number, required: true }, // number of problems for one session
isOpen: { type: Boolean },
},
{
collection: "challenge",
}
);
ChallengeSchema.statics.findByChallengeName = function (challengeName) {
return this.findOne({ challengeName: challengeName });
};
ChallengeSchema.methods.getChallengeName = function () {
return this.challengeName;
};
ChallengeSchema.methods.getStartDate = function () {
return this.startDate;
};
ChallengeSchema.methods.getEndDate = function () {
return this.endDate;
};
ChallengeSchema.methods.getDurationPerSession = function () {
return this.durationPerSession;
};
ChallengeSchema.methods.getGoalPerSession = function () {
return this.goalPerSession;
};
ChallengeSchema.methods.serialize = function () {
return this.toJSON();
};
const Challenge = mongoose.model("Challenge", ChallengeSchema);
module.exports = Challenge;
const ChallengeSchema=new Schema({
challengeName: {type: String, required: true},
startDate: {type: Object, required: true},
endDate: {type: Object, required: true},
durationPerSession: {type: String, required: true}, // '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session.
goalPerSession: {type: Number, required:true}, // number of problems for one session
status: { type: String }
},{
collection: 'challenge'
});
ChallengeSchema.statics.findByChallengeName=function(challengeName){
return this.findOne({challengeName:challengeName});
}
ChallengeSchema.methods.getChallengeName=function(){
return this.challengeName;
}
ChallengeSchema.methods.getStartDate=function(){
return this.startDate;
}
ChallengeSchema.methods.getEndDate=function(){
return this.endDate;
}
ChallengeSchema.method.getDurationPerSession=function(){
return this.durationPerSession;
}
ChallengeSchema.methods.getGoalPerSession=function(){
return this.goalPerSession;
}
ChallengeSchema.methods.getStatus=function(){
return this.status;
}
ChallengeSchema.methods.serialize=function(){
return this.toJSON();
}
const Challenge = mongoose.model('Challenge', ChallengeSchema);
module.exports = Challenge;
\ No newline at end of file
......
......@@ -6,7 +6,7 @@ const SessionSchema = new Schema({
challengeId: { type: Schema.Types.ObjectId, ref: 'Challenge' },
sessionStartDate: { type: Object },
sessionEndDate: { type: Object },
isOpen: { type: Boolean }
status: { type: String }
},{
collection: 'session'
});
......@@ -23,8 +23,8 @@ SessionSchema.methods.getSessionEndDate=function(){
return this.sessionEndDate;
}
SessionSchema.methods.getIsOpen=function(){
return this.isOpen;
SessionSchema.methods.getStatus=function(){
return this.status;
}
SessionSchema.methods.serialize=function(){
......