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

Add icon support for goals #37

Open
wants to merge 1 commit into
base: main
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
13,044 changes: 8,034 additions & 5,010 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@types/node": "^17.0.41",
"@types/react": "^16.9.0",
"@types/react-redux": "^7.1.7",
"axios": "^0.27.2",
"axios": "^1.6.8",
"css-in-js-media": "^2.0.1",
"date-fns": "^2.28.0",
"emoji-mart": "^3.0.1",
Expand All @@ -23,7 +23,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.0",
"react-scripts": "5.0.1",
"react-scripts": "^5.0.1",
"sass": "^1.52.3",
"styled-components": "^5.3.5",
"typescript": "^4.7.3",
Expand Down Expand Up @@ -59,4 +59,4 @@
"@types/react-dom": "^18.0.5",
"@types/styled-components": "^5.1.25"
}
}
}
1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Application {
export interface Goal {
id: string
name: string
icon: string | null
targetAmount: number
balance: number
targetDate: Date
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/EmojiPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export default function EmojiPicker(props: Props) {
color="primary"
/>
)
}
}
2 changes: 1 addition & 1 deletion src/ui/features/goalmanager/GoalIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export default function GoalIcon(props: Props) {
const Icon = styled.h1`
font-size: 6rem;
cursor: pointer;
`
`
78 changes: 75 additions & 3 deletions src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons'
import { faDollarSign, IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { faDollarSign, faSmile, IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date'
import 'date-fns'
Expand All @@ -11,16 +11,28 @@ import { selectGoalsMap, updateGoal as updateGoalRedux } from '../../../store/go
import { useAppDispatch, useAppSelector } from '../../../store/hooks'
import DatePicker from '../../components/DatePicker'
import { Theme } from '../../components/Theme'
import { BaseEmoji, Picker } from 'emoji-mart'
import EmojiPicker from '../../components/EmojiPicker'
import AddIcon from '../../components/AddIcon'

import { TransparentButton } from '../../components/TransparentButton'
import GoalIcon from './GoalIcon'

type Props = { goal: Goal }
export function GoalManager(props: Props) {
const dispatch = useAppDispatch()

const goal = useAppSelector(selectGoalsMap)[props.goal.id]

const [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false)
const [name, setName] = useState<string | null>(null)
const [targetDate, setTargetDate] = useState<Date | null>(null)
const [targetAmount, setTargetAmount] = useState<number | null>(null)
const [icon, setIcon] = useState<string | null>(null) // Declare the 'icon' variable

useEffect(() => {
setIcon(props.goal.icon)
}, [props.goal.id, props.goal.icon])

const hasIcon = () => icon != null // Use the 'icon' variable

useEffect(() => {
setName(props.goal.name)
Expand Down Expand Up @@ -48,6 +60,12 @@ export function GoalManager(props: Props) {
updateGoalApi(props.goal.id, updatedGoal)
}

const addIconOnClick = (event: React.MouseEvent) => {
event.stopPropagation()
setEmojiPickerIsOpen(true)
}


const updateTargetAmountOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const nextTargetAmount = parseFloat(event.target.value)
setTargetAmount(nextTargetAmount)
Expand All @@ -74,10 +92,53 @@ export function GoalManager(props: Props) {
updateGoalApi(props.goal.id, updatedGoal)
}
}
const pickEmojiOnClick = (emoji: BaseEmoji, event: React.MouseEvent) => {
event.stopPropagation()

setIcon(emoji.native)
setEmojiPickerIsOpen(false)

const updatedGoal: Goal = {
...props.goal,
icon: emoji.native ?? props.goal.icon,
name: name ?? props.goal.name,
targetDate: targetDate ?? props.goal.targetDate,
targetAmount: targetAmount ?? props.goal.targetAmount,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}
return (
<GoalManagerContainer>
<NameInput value={name ?? ''} onChange={updateNameOnChange} />

{emojiPickerIsOpen && (
<EmojiPicker onClick={pickEmojiOnClick} />
)}

{!icon ? (
<TransparentButton onClick={addIconOnClick}>
<FontAwesomeIcon icon={faSmile} size="2x" />
Add Icon
</TransparentButton>
) : (
<TransparentButton onClick={addIconOnClick}>
<GoalIcon icon={icon} onClick={addIconOnClick} />
</TransparentButton>
)}

{emojiPickerIsOpen && (
<EmojiPickerContainer isOpen={emojiPickerIsOpen} hasIcon={hasIcon()}>
<EmojiPicker onClick={pickEmojiOnClick} />
</EmojiPickerContainer>
)}

<EmojiPickerContainer
isOpen={emojiPickerIsOpen}
hasIcon={hasIcon()}
onClick={(event) => event.stopPropagation()}>
<EmojiPicker onClick={pickEmojiOnClick} />
</EmojiPickerContainer>

<Group>
<Field name="Target Date" icon={faCalendarAlt} />
Expand Down Expand Up @@ -106,6 +167,7 @@ export function GoalManager(props: Props) {
<StringValue>{new Date(props.goal.created).toLocaleDateString()}</StringValue>
</Value>
</Group>

</GoalManagerContainer>
)
}
Expand All @@ -131,6 +193,12 @@ const GoalManagerContainer = styled.div`
width: 100%;
position: relative;
`
const EmojiPickerContainer = styled.div<EmojiPickerContainerProps>`
display: ${(props) => (props.isOpen ? 'flex' : 'none')};
position: absolute;
top: ${(props) => (props.hasIcon ? '10rem' : '2rem')};
left: 0;
`

const Group = styled.div`
display: flex;
Expand Down Expand Up @@ -182,3 +250,7 @@ const StringInput = styled.input`
const Value = styled.div`
margin-left: 2rem;
`
function setEmojiPickerIsOpen(arg0: boolean) {
throw new Error('Function not implemented.')
}

6 changes: 6 additions & 0 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
setType as setTypeRedux
} from '../../../../store/modalSlice'
import { Card } from '../../../components/Card'
import { Icon as MaterialIcon} from '@material-ui/core'

type Props = { id: string }


export default function GoalCard(props: Props) {
const dispatch = useAppDispatch()

Expand All @@ -29,6 +31,7 @@ export default function GoalCard(props: Props) {
<Container key={goal.id} onClick={onClick}>
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
<Icon>{goal.icon}</Icon>
</Container>
)
}
Expand All @@ -54,3 +57,6 @@ const TargetDate = styled.h4`
color: rgba(174, 174, 174, 1);
font-size: 1rem;
`
const Icon = styled.h1`
font-size: 5.5rem;
`
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "preserve"
},
"include": [
"src"
Expand Down