Skip to content
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
1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Goal {
targetAmount: number
balance: number
targetDate: Date
icon:string|null
created: Date
accountId: string
transactionIds: string[]
Expand Down
14 changes: 14 additions & 0 deletions src/ui/components/AddIconButtonContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { ReactNode } from "react";

interface AddIconButtonContainerProps {
condition: boolean;
children: ReactNode;
wrapper?: (children: ReactNode) => JSX.Element; // Optional wrapper function
}

const AddIconButtonContainer: React.FC<AddIconButtonContainerProps> = ({ condition, children, wrapper }) => {
if (!condition) return null;
return wrapper ? wrapper(children) : <>{children}</>;
};

export default AddIconButtonContainer;
76 changes: 74 additions & 2 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,8 +11,18 @@ 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 } from 'emoji-mart'
import EmojiPicker from '../../components/EmojiPicker'
import AddIconButtonContainer from '../../components/AddIconButtonContainer'
import { TransparentButton } from '../../components/TransparentButton'
import GoalIcon from './GoalIcon'

type Props = { goal: Goal }
type EmojiPickerContainerProps = { isOpen: boolean; hasIcon: boolean }

const GoalIconContainer = styled.div<GoalIconContainerProps>`
display: ${(props) => (props.shouldShow ? 'flex' : 'none')};
`
export function GoalManager(props: Props) {
const dispatch = useAppDispatch()

Expand All @@ -22,6 +32,19 @@ export function GoalManager(props: Props) {
const [targetDate, setTargetDate] = useState<Date | null>(null)
const [targetAmount, setTargetAmount] = useState<number | null>(null)

const [icon, setIcon] = useState<string | null>(null)

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


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


useEffect(() => {
setName(props.goal.name)
setTargetDate(props.goal.targetDate)
Expand Down Expand Up @@ -61,6 +84,27 @@ export function GoalManager(props: Props) {
updateGoalApi(props.goal.id, updatedGoal)
}

const [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false)

const hasIcon = () => icon != null

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)
}
const pickDateOnChange = (date: MaterialUiPickersDate) => {
if (date != null) {
setTargetDate(date)
Expand Down Expand Up @@ -106,14 +150,36 @@ export function GoalManager(props: Props) {
<StringValue>{new Date(props.goal.created).toLocaleDateString()}</StringValue>
</Value>
</Group>
<GoalIconContainer shouldShow={hasIcon()}>
<GoalIcon icon={goal.icon} onClick={addIconOnClick} />
</GoalIconContainer>
<Group>
<EmojiPickerContainer
isOpen={emojiPickerIsOpen}
hasIcon={hasIcon()}
onClick={(event) => event.stopPropagation()}
>
<EmojiPicker onClick={pickEmojiOnClick} />
</EmojiPickerContainer>
</Group>

<Group>
<AddIconButtonContainer condition={!hasIcon()}>

<TransparentButton onClick={addIconOnClick}>
<FontAwesomeIcon icon={faSmile} size="2x" />
<p>Add icon</p>
</TransparentButton>

</AddIconButtonContainer>
</Group>
</GoalManagerContainer>
)
}

type FieldProps = { name: string; icon: IconDefinition }
type AddIconButtonContainerProps = { shouldShow: boolean }
type GoalIconContainerProps = { shouldShow: boolean }
type EmojiPickerContainerProps = { isOpen: boolean; hasIcon: boolean }

const Field = (props: FieldProps) => (
<FieldContainer>
Expand Down Expand Up @@ -182,3 +248,9 @@ const StringInput = styled.input`
const Value = styled.div`
margin-left: 2rem;
`
const EmojiPickerContainer = styled.div<EmojiPickerContainerProps>`
display: ${(props) => (props.isOpen ? 'flex' : 'none')};
position: absolute;
top: ${(props) => (props.hasIcon ? '10rem' : '2rem')};
left: 0;
`
4 changes: 4 additions & 0 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
} from '../../../../store/modalSlice'
import { Card } from '../../../components/Card'

const Icon = styled.h1`
font-size: 5.5rem;
`
type Props = { id: string }

export default function GoalCard(props: Props) {
Expand All @@ -29,6 +32,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 Down