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

Feature/help coins balance #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion react-app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function App() {

return (
<Router>
<UserLoginContext.Provider value={{userLoggedIn, signUserOut }}>
<UserLoginContext.Provider value={{userLoggedIn, setUserLoggedIn, signUserOut }}>
<Switch>
<Route exact path="/">
{userLoggedIn ? (
Expand Down
4 changes: 2 additions & 2 deletions react-app/src/components/CardAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react'
import SignOutIcon from '../assets/sign-out.svg'

function CardAvatar({ user, onSignOut }) {
const {name, image} = user
const {name, image, coins} = user
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind, that user is potentially often encountered prop in your app, so it may make sense to move to some react context.

Otherwise, you may find yourself dealing with props drilling - when you need to pass some props way down the React tree just to pass them to some low level component.

return (
<div className='card-avatar-wrapper'>
<div className='card-avatar'>
<img src={image} alt={`${name} avatar`} />
<div className='card-avatar-info-container'>
<div className='card-avatar-title'>Hello, {name}!</div>
<button className='help-point-btn'>{425} HC</button>
<button className='help-point-btn'>{coins} HC</button>
</div>
</div>
<button className='leave-btn' onClick={onSignOut}>
Expand Down
2 changes: 1 addition & 1 deletion react-app/src/components/task-card/FlipTaskCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function FlipTaskCard({ task, completeTask, flippable = true }) {
return (
<CSSTransition in={task.isComplete} timeout={REMOVE_TASK_DELAY} classNames="remove-fade">
<ReactCardFlip isFlipped={isFlip} flipDirection='horizontal' infinite={true}>
<TaskCard key='front' task={task} onClick={handleCardClick}/>
<TaskCard key='front' task={task} isFlippable={flippable} onClick={handleCardClick}/>
{(task.isComplete) ? (
<CompletionCard key='back' points={task.rewardPoints} onClick={handleCardClick}/>
) : (
Expand Down
5 changes: 3 additions & 2 deletions react-app/src/components/task-card/TaskCard.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react'
import Card from './Card'

function TaskCard({ task, ...rest }) {
function TaskCard({ task, isFlippable, ...rest }) {
const { title, rewardPoints, colour } = task

return (
<Card colour={colour} {...rest}>
<Card colour={colour} className={(isFlippable) ? 'pointer': ''} {...rest}>
<div className='reward'><span className='reward-points'>{rewardPoints}</span></div>
<div className='task-title'>{title}</div>
</Card>
Expand Down
16 changes: 15 additions & 1 deletion react-app/src/components/task-grid/TaskGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import firebase from '../../firebase'
export const REMOVE_TASK_DELAY = 2000

function TaskGrid({ tasks = [], flippableTask = true, className = '' }) {
const { userLoggedIn } = useUserLogged()
const { userLoggedIn, setUserLoggedIn } = useUserLogged()
const [taskGridtasks, setTaskGridTasks] = useState([])
const [completedTask, setCompletedTask] = useState(null)

Expand All @@ -32,11 +32,25 @@ function TaskGrid({ tasks = [], flippableTask = true, className = '' }) {
completedBy: task.completedBy,
completedDate: firebase.firestore.FieldValue.serverTimestamp()
})
const totalHelpCoins = userLoggedIn.coins + task.rewardPoints
updateHelpCoins(totalHelpCoins)

} catch (err) {
console.log(err)
}
}

function updateHelpCoins(amount) {
firebase
.firestore()
.collection('users')
.doc(userLoggedIn.id)
.update({
coins: amount
})
setUserLoggedIn({ ...userLoggedIn, coins: amount})
}

function completeTask(task) {
setCompletedTask(task)
const newTasks = taskGridtasks.map(function completeSingleTask(t) {
Expand Down
5 changes: 3 additions & 2 deletions react-app/src/domain/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import JackImg from '../assets/users/[email protected]'
export const ADMIN_USER = 'admin'
export const REGULAR_USER = 'regular'

export function createUser({id, name, age, role}) {
export function createUser({id, name, age, role, coins}) {
return {
id,
name,
age,
role,
image: getUserImage(name)
image: getUserImage(name),
coins
}
}

Expand Down
6 changes: 6 additions & 0 deletions react-app/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ body {
padding: 0 0.5rem;
}

.pointer {
cursor: pointer;
}

.task-option-btn {
display: flex;
flex-direction: column;
Expand All @@ -70,6 +74,8 @@ body {
background: none;
border: none;
padding: 0;

cursor: pointer;
}

.task-option-btn.cross-option {
Expand Down