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

forage-job-simulation_CommonBank-web_task-two_by-Wenwei #53

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
48 changes: 31 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"dependencies": {
"@date-io/date-fns": "^1.3.13",
"@fortawesome/free-regular-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.1.18",
"@fortawesome/free-solid-svg-icons": "^6.6.0",
"@fortawesome/react-fontawesome": "^0.1.19",
"@material-ui/core": "^4.12.4",
"@material-ui/pickers": "^3.3.10",
"@reduxjs/toolkit": "^1.5.1",
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 @@ -27,6 +27,7 @@ export interface Goal {
accountId: string
transactionIds: string[]
tagIds: string[]
icon: string | null
}

export interface Tag {
Expand Down
13 changes: 13 additions & 0 deletions src/ui/components/AddIconButtonStyles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import styled from 'styled-components';

export const AddIconButtonContainer = styled.div<{ hasIcon: boolean }>`
display: ${(props) => (props.hasIcon ? 'none' : 'flex')};
align-items: center;
justify-content: center;
`;

export const AddIconButtonText = styled.span`
margin-left: 8px;
font-size: 16px;
color: #333;
`;
16 changes: 16 additions & 0 deletions src/ui/components/EmojiPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@ export default function EmojiPicker(props: Props) {
/>
)
}

/*const EmojiPickerWrapper: React.FC<Props> = ({ onClick }) => {
const theme = useAppSelector(selectMode);

return (
<Picker
theme={theme}
showPreview={false}
showSkinTones={false}
onClick={onClick}
color="primary"
/>
);
};

export default EmojiPickerWrapper;*/
94 changes: 93 additions & 1 deletion src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,68 @@ 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 {TransparentButton} from '../../components/TransparentButton'
import GoalIcon from './GoalIcon'
import {AddIconButtonContainer, AddIconButtonText} from '../../components/AddIconButtonStyles'
import { faSmile } from '@fortawesome/free-solid-svg-icons';


type Props = { goal: Goal }

type EmojiPickerContainerProps = { isOpen: boolean; hasIcon: boolean }//

const EmojiPickerContainer = styled.div<EmojiPickerContainerProps>`
display: ${(props) => (props.isOpen ? 'flex' : 'none')};
position: absolute;
top: ${(props) => (props.hasIcon ? '10rem' : '2rem')};
left: 0;
`//

export function GoalManager(props: Props) {

const [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false)

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

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

const hasIcon = () => goal.icon != null

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

const pickEmojiOnClick = (emoji: BaseEmoji, event: React.MouseEvent) => {
// TODO(TASK-2) Stop event propogation
// TODO(TASK-2) Set icon locally
// TODO(TASK-2) Close emoji picker
// TODO(TASK-2) Create updated goal locally
// TODO(TASK-2) Update Redux store

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))

// TODO(TASK-3) Update database
}
//

const dispatch = useAppDispatch()

const goal = useAppSelector(selectGoalsMap)[props.goal.id]
Expand Down Expand Up @@ -75,6 +134,7 @@ export function GoalManager(props: Props) {
}
}


return (
<GoalManagerContainer>
<NameInput value={name ?? ''} onChange={updateNameOnChange} />
Expand Down Expand Up @@ -106,14 +166,46 @@ export function GoalManager(props: Props) {
<StringValue>{new Date(props.goal.created).toLocaleDateString()}</StringValue>
</Value>
</Group>

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

<Group>
<AddIconButtonContainer hasIcon={hasIcon()}>
<TransparentButton onClick={addIconOnClick}>
<FontAwesomeIcon icon= {faSmile} size="2x" />
<AddIconButtonText>Add icon</AddIconButtonText>
</TransparentButton>
</AddIconButtonContainer>
</Group>

<Group>
<GoalIconContainer shouldShow={hasIcon()}>
<GoalIcon icon={goal.icon} onClick={addIconOnClick} />
</GoalIconContainer>
</Group>
</GoalManagerContainer>



)
}

type FieldProps = { name: string; icon: IconDefinition }
type AddIconButtonContainerProps = { shouldShow: boolean }
type GoalIconContainerProps = { shouldShow: boolean }
type EmojiPickerContainerProps = { isOpen: boolean; hasIcon: boolean }
const GoalIconContainer = styled.div<GoalIconContainerProps>`
display: ${(props) => (props.shouldShow ? 'flex' : 'none')};
`



const Field = (props: FieldProps) => (
<FieldContainer>
Expand Down
3 changes: 3 additions & 0 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ export default function GoalCard(props: Props) {

const asLocaleDateString = (date: Date) => new Date(date).toLocaleDateString()

const Icon = styled.h1`font-size: 5.5rem;`

return (
<Container key={goal.id} onClick={onClick}>
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
<Icon>{goal.icon}</Icon>
</Container>
)
}
Expand Down