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

Icons #35

Open
wants to merge 3 commits 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
3 changes: 3 additions & 0 deletions .vs/CMakeWorkspaceSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"enableCMake": false
}
Empty file.
Binary file added .vs/CommBank-Web/v17/.wsuo
Binary file not shown.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
10 changes: 10 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ExpandedNodes": [
"",
"\\src",
"\\src\\ui",
"\\src\\ui\\features\\goalmanager"
],
"SelectedNode": "\\src",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
12,790 changes: 7,814 additions & 4,976 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.7",
"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"
}
}
}
2 changes: 1 addition & 1 deletion src/api/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ export async function updateGoal(goalId: string, updatedGoal: Goal): Promise<boo
} catch (error: any) {
return false
}
}
}
2 changes: 2 additions & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface Goal {
accountId: string
transactionIds: string[]
tagIds: string[]
//Update the goal model
icon: string | null
}

export interface Tag {
Expand Down
1 change: 1 addition & 0 deletions src/ui/features/goalmanager/GoalIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TransparentButton } from '../../components/TransparentButton'

type Props = { icon: string | null; onClick: (e: React.MouseEvent) => void }


export default function GoalIcon(props: Props) {
return (
<TransparentButton onClick={props.onClick}>
Expand Down
181 changes: 148 additions & 33 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, IconDefinition, faSmile } 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 @@ -12,7 +12,15 @@ import { useAppDispatch, useAppSelector } from '../../../store/hooks'
import DatePicker from '../../components/DatePicker'
import { Theme } from '../../components/Theme'

// IEP Part 1- Imports (IEP)
import { BaseEmoji } from 'emoji-mart'
import EmojiPicker from '../../components/EmojiPicker'
import GoalIcon from './GoalIcon'


type Props = { goal: Goal }


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

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

// IEP Part 2-Emoji picker use state
const [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false)

// Task 2 MGM Part 1-Icon use state
const [icon, setIcon] = useState<string | null>(null)


useEffect(() => {
setName(props.goal.name)
setTargetDate(props.goal.targetDate)
Expand All @@ -37,6 +52,14 @@ export function GoalManager(props: Props) {
setName(goal.name)
}, [goal.name])

// Task 2 MGM Part 2-Icon use effect
useEffect(() => {
setIcon(props.goal.icon)
}, [props.goal.id, props.goal.icon])

// Task 2 MGM Part 3-Icon has icon
const hasIcon = () => icon != null

const updateNameOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const nextName = event.target.value
setName(nextName)
Expand Down Expand Up @@ -73,45 +96,104 @@ export function GoalManager(props: Props) {
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}
}
}

// Task 2 MGM Part 4-Add icon on click action
const addIconOnClick = (event: React.MouseEvent) => {
event.stopPropagation()
setEmojiPickerIsOpen(true)
}

// IEP Part 4- On click event (IEP)
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
updateGoalApi(props.goal.id, updatedGoal)
}



return (
<GoalManagerContainer>
<NameInput value={name ?? ''} onChange={updateNameOnChange} />

<Group>
<Field name="Target Date" icon={faCalendarAlt} />
<Value>
<DatePicker value={targetDate} onChange={pickDateOnChange} />
</Value>
</Group>

<Group>
<Field name="Target Amount" icon={faDollarSign} />
<Value>
<StringInput value={targetAmount ?? ''} onChange={updateTargetAmountOnChange} />
</Value>
</Group>

<Group>
<Field name="Balance" icon={faDollarSign} />
<Value>
<StringValue>{props.goal.balance}</StringValue>
</Value>
</Group>

<Group>
<Field name="Date Created" icon={faCalendarAlt} />
<Value>
<StringValue>{new Date(props.goal.created).toLocaleDateString()}</StringValue>
</Value>
</Group>
</GoalManagerContainer>
<NameInput value={name ?? ''} onChange={updateNameOnChange} />

<Group>
<Field name="Target Date" icon={faCalendarAlt} />
<Value>
<DatePicker value={targetDate} onChange={pickDateOnChange} />
</Value>
</Group>

<Group>
<Field name="Target Amount" icon={faDollarSign} />
<Value>
<StringInput value={targetAmount ?? ''} onChange={updateTargetAmountOnChange} />
</Value>
</Group>

<Group>
<Field name="Balance" icon={faDollarSign} />
<Value>
<StringValue>{props.goal.balance}</StringValue>
</Value>
</Group>

<Group>
<Field name="Date Created" icon={faCalendarAlt} />
<Value>
<StringValue>{new Date(props.goal.created).toLocaleDateString()}</StringValue>
</Value>
</Group>


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

// MGM-Part 5
<AddIconButtonContainer shouldShow={hasIcon()} hasIcon={hasIcon()}>
<TransparentButton onClick={addIconOnClick}>
<FontAwesomeIcon icon={faSmile} size="2x" />
<AddIconButtonText>Add icon</AddIconButtonText>
</TransparentButton>
</AddIconButtonContainer>

// MGM-Part 6
<GoalIconContainer shouldShow={hasIcon()}>
<GoalIcon icon={goal.icon} onClick={addIconOnClick} />
</GoalIconContainer>
</GoalManagerContainer>



)
}

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

Expand Down Expand Up @@ -182,3 +264,36 @@ const StringInput = styled.input`
const Value = styled.div`
margin-left: 2rem;
`

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

// Task 2 MGM-Part 7
const GoalIconContainer = styled.div<GoalIconContainerProps>`
display: ${(props) => (props.shouldShow ? 'flex' : 'none')};
`

// Styles
const AddIconButtonContainer = styled.div<AddIconButtonContainerProps>`
display: ${(props) => (props.shouldShow ? 'flex' : 'none')};
margin-top: 1.25rem;
margin-bottom: 1.25rem;
`;

const TransparentButton = styled.button`
display: flex;
background-color: transparent;
outline: none;
border: none;
cursor: pointer;
`;

const AddIconButtonText = styled.span`
font-size: 1.8rem;
font-weight: bold;
`;
8 changes: 7 additions & 1 deletion src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { Card } from '../../../components/Card'

type Props = { id: string }

// GoalCard.tsx

const Icon = styled.h1`
font-size: 5.5rem;
`
export default function GoalCard(props: Props) {
const dispatch = useAppDispatch()

Expand All @@ -28,7 +33,8 @@ export default function GoalCard(props: Props) {
return (
<Container key={goal.id} onClick={onClick}>
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
<Icon>{goal.icon}</Icon>
</Container>
)
}
Expand Down