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 package-lock.json

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

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
}

export interface Tag {
Expand Down
28 changes: 28 additions & 0 deletions src/ui/features/goalmanager/GoalManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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 { Picker } from 'emoji-mart'

type Props = { goal: Goal }
export function GoalManager(props: Props) {
Expand All @@ -21,6 +22,7 @@ export function GoalManager(props: Props) {
const [name, setName] = useState<string | null>(null)
const [targetDate, setTargetDate] = useState<Date | null>(null)
const [targetAmount, setTargetAmount] = useState<number | null>(null)
const [emoji, setEmoji] = useState<string>("🎯")

useEffect(() => {
setName(props.goal.name)
Expand All @@ -43,6 +45,7 @@ export function GoalManager(props: Props) {
const updatedGoal: Goal = {
...props.goal,
name: nextName,
icon: emoji,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
Expand All @@ -56,6 +59,7 @@ export function GoalManager(props: Props) {
name: name ?? props.goal.name,
targetDate: targetDate ?? props.goal.targetDate,
targetAmount: nextTargetAmount,
icon: emoji,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
Expand All @@ -69,11 +73,28 @@ export function GoalManager(props: Props) {
name: name ?? props.goal.name,
targetDate: date ?? props.goal.targetDate,
targetAmount: targetAmount ?? props.goal.targetAmount,
icon: emoji,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}
}
const pickEmojiOnClick = async (e: any) => {
const selectedEmoji = e.native

setEmoji(selectedEmoji)

const updatedGoal: Goal = {
...props.goal,
icon: selectedEmoji,
name: name ?? props.goal.name,
targetDate: targetDate ?? props.goal.targetDate,
targetAmount: targetAmount ?? props.goal.targetAmount,
}

dispatch(updateGoalRedux(updatedGoal))
await updateGoalApi(props.goal.id, updatedGoal)
}

return (
<GoalManagerContainer>
Expand Down Expand Up @@ -106,6 +127,13 @@ export function GoalManager(props: Props) {
<StringValue>{new Date(props.goal.created).toLocaleDateString()}</StringValue>
</Value>
</Group>

<Group>
<Field name="Emoji" icon={faCalendarAlt} />
<Value>
<Picker onSelect={pickEmojiOnClick} />
</Value>
</Group>
</GoalManagerContainer>
)
}
Expand Down
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 @@ -15,6 +15,7 @@ export default function GoalCard(props: Props) {
const dispatch = useAppDispatch()

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

const onClick = (event: React.MouseEvent) => {
event.stopPropagation()
Expand All @@ -27,6 +28,9 @@ export default function GoalCard(props: Props) {

return (
<Container key={goal.id} onClick={onClick}>
<span style={{ fontSize: "2rem"}}>
{goal?.icon ?? "🎯"}
</span>
<TargetAmount>${goal.targetAmount}</TargetAmount>
<TargetDate>{asLocaleDateString(goal.targetDate)}</TargetDate>
</Container>
Expand Down
38 changes: 38 additions & 0 deletions src/ui/pages/Main/goals/GoalControllerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Xunit;

public class GoalControllerTests
{
private readonly FakeCollections collections;

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

[Fact]
public async void 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);

// Act
var httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext();
controller.ControllerContext.HttpContext = httpContext;
var result = await controller.GetForUser(goals[0].UserId!);

// Assert
Assert.NotNull(result);

var index = 0;
foreach (Goal goal in result!)
{
Assert.IsAssignableFrom<Goal>(goal);
Assert.Equal(goals[0].UserId, goal.UserId);
index++;
}
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2017",
"lib": [
"dom",
"dom.iterable",
Expand Down