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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.vs/CommBank-Web/FileContentIndex/8d2c356b-6d55-4bc1-b87f-f946bbc7b78d.vsidx
.vs/CommBank-Web/FileContentIndex/9249bc86-b3ba-4f44-b8e5-ec4717f093a5.vsidx
.vs/CommBank-Web/FileContentIndex/9a5f6c10-30e5-4065-bf50-dc266c0ea273.vsidx
.vs/CommBank-Web/FileContentIndex/b18f3d19-3f42-463c-a5e3-e9f8fcc8379e.vsidx
.vs/CommBank-Web/FileContentIndex/561213b1-588c-465b-8922-a283db3d4612.vsidx
.vs/CommBank-Web/FileContentIndex/ef1c54a5-c862-4eb4-81f7-7d1f36b54753.vsidx
.vs/CommBank-Web/FileContentIndex/5d1ec056-5fd5-49a8-b029-33a18581789e.vsidx
.vs/CommBank-Web/FileContentIndex/65c1dc03-737d-47f2-9a75-e28d0eb22ce4.vsidx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1,021 changes: 1,021 additions & 0 deletions .vs/CommBank-Web/config/applicationhost.config

Large diffs are not rendered by default.

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
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# CommBank Goal Tracker
# CommBank Goal Tracker
#https://github.com/rezhang1128/CommBank-Web.git
3 changes: 3 additions & 0 deletions Task3_link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
I don't know why I can't submit tsx file
So I have to submit the link of the github to show my work
https://github.com/rezhang1128/CommBank-Web.git
1 change: 1 addition & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export interface Goal {
created: Date
accountId: string
transactionIds: string[]
tagIds: string[]
tagIds: string[]
icon: string | null
}

export interface Tag {
Expand Down
40 changes: 40 additions & 0 deletions src/test/GoalControllerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Threading.Tasks;
using Xunit;
using Microsoft.AspNetCore.Http;

public class GoalControllerTests
{
private readonly FakeCollections collections;

public GoalControllerTests()
{
collections = new();
}

[Fact]
public async Task GetForUser()
{
// Arrange
var goals = collections.GetGoals();
var users = collections.GetUsers();
IGoalsService goalsService = new FakeGoalsService(goals, goals[0]);
IUsersService usersService = new FakeUsersService(users, users[0]);
GoalController controller = new(goalsService, usersService);

var httpContext = new DefaultHttpContext();
controller.ControllerContext.HttpContext = httpContext;

// Act
var result = await controller.GetForUser(goals[0].UserId!);

// Assert
Assert.NotNull(result);
Assert.NotEmpty(result); // Ensure goals exist

Assert.All(result!, goal =>
{
Assert.IsAssignableFrom<Goal>(goal);
Assert.Equal(goals[0].UserId, goal.UserId);
});
}
}
77 changes: 72 additions & 5 deletions src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons'
import { faDollarSign, IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { MaterialUiPickersDate } from '@material-ui/pickers/typings/date'
Expand All @@ -11,16 +10,30 @@ 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 { selectMode } from '../../../store/themeSlice';
import GoalIcon from './GoalIcon';
import { TransparentButton } from '../../components/TransparentButton';
import { faCalendarAlt, faSmile } from '@fortawesome/free-regular-svg-icons';


type Props = { goal: Goal }
const EmojiPicker = ({ onClick }: { onClick: (emoji: BaseEmoji, event: React.MouseEvent) => void }) => {
const theme = useAppSelector(selectMode);
return (
<Picker theme={theme} showPreview={false} showSkinTones={false} onClick={onClick} color="primary" />
);
};

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

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

const [name, setName] = useState<string | null>(null)
const [targetDate, setTargetDate] = useState<Date | null>(null)
const [targetAmount, setTargetAmount] = useState<number | null>(null)
const [targetAmount, setTargetAmount] = useState<number | null>(null)
const [icon, setIcon] = useState<string | null>(props.goal.icon ?? null);
const [emojiPickerIsOpen, setEmojiPickerIsOpen] = useState(false)


useEffect(() => {
setName(props.goal.name)
Expand All @@ -36,6 +49,27 @@ export function GoalManager(props: Props) {
useEffect(() => {
setName(goal.name)
}, [goal.name])
const hasIcon = () => icon != null;
const addIconOnClick = (event: React.MouseEvent) => {
event.stopPropagation();
setEmojiPickerIsOpen(true);
};
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 updateNameOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const nextName = event.target.value
Expand Down Expand Up @@ -105,7 +139,20 @@ export function GoalManager(props: Props) {
<Value>
<StringValue>{new Date(props.goal.created).toLocaleDateString()}</StringValue>
</Value>
</Group>
</Group>

<GoalIconContainer shouldShow={hasIcon()}>
<GoalIcon icon={goal.icon} onClick={addIconOnClick} />
</GoalIconContainer>
<AddIconButtonContainer hasIcon={hasIcon()}>
<TransparentButton onClick={addIconOnClick}>
<FontAwesomeIcon icon={faSmile} size="2x" />
<AddIconButtonText>Add icon</AddIconButtonText>
</TransparentButton>
</AddIconButtonContainer>
<EmojiPickerContainer isOpen={emojiPickerIsOpen} hasIcon={hasIcon()} onClick={(e) => e.stopPropagation()}>
<EmojiPicker onClick={pickEmojiOnClick} />
</EmojiPickerContainer>
</GoalManagerContainer>
)
}
Expand All @@ -122,6 +169,19 @@ const Field = (props: FieldProps) => (
</FieldContainer>
)


const GoalIconContainer = styled.div<{ shouldShow: boolean }>`
display: ${(props) => (props.shouldShow ? 'flex' : 'none')};
`;

const AddIconButtonContainer = styled.div<{ hasIcon: boolean }>`
display: ${(props) => (props.hasIcon ? 'none' : 'flex')};
`;

const AddIconButtonText = styled.span`
margin-left: 0.5rem;
`;

const GoalManagerContainer = styled.div`
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -182,3 +242,10 @@ 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;
`
7 changes: 5 additions & 2 deletions src/ui/pages/Main/goals/GoalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
import { Card } from '../../../components/Card'

type Props = { id: string }

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

Expand All @@ -28,7 +30,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