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.

32 changes: 32 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const express = require('express')
const cors = require('cors')

const app = express()
app.use(cors())
app.use(express.json())

const goals = [
{ id: "1", name: "Buy Car", targetAmount: 5000, icon: "🚗" },
{ id: "2", name: "Trip", targetAmount: 2000, icon: "✈️" }
]

// GET goals route
app.get("/goals", (req, res) => {
const { userId } = req.query

if (userId) {
return res.json(goals)
}

res.json(goals)
})

// export app for testing
module.exports = app

// run server only when not testing
if (require.main === module) {
app.listen(3001, () => {
console.log("Server running on http://localhost:3001")
})
}
1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Application {
export interface Goal {
id: string
name: string
icon: string;
targetAmount: number
balance: number
targetDate: Date
Expand Down
12 changes: 11 additions & 1 deletion src/store/goalsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@ export const goalsSlice = createSlice({
updateGoal: (state, action: PayloadAction<Goal>) => {
state.map[action.payload.id] = action.payload
},

setGoals: (state, action: PayloadAction<Goal[]>) => {
state.map = {}
state.list = []

action.payload.forEach((goal) => {
state.map[goal.id] = goal
state.list.push(goal.id)
})
},
},
})

export const { createGoal, updateGoal } = goalsSlice.actions
export const { createGoal, updateGoal, setGoals } = goalsSlice.actions

export const selectGoalsMap = (state: RootState) => state.goals.map
export const selectGoalsList = (state: RootState) => state.goals.list
Expand Down
34 changes: 34 additions & 0 deletions src/ui/features/#include <iostream>.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
using namespace std ;

class A {
public :
void showA(){
cout <<"this is class A"<<endl;
}
};
class B {
public :
void showB(){
cout <<"this is class B"<<endl;
}
};
class C :public B ,public A
{
public :
void showC(){
cout<<"this is class C( derived form A and B)"<<endl;
}

};

int main(){
c obj;
obj.show A();
obj.show B();
obj.show C();


return 0;
}
sss
227 changes: 227 additions & 0 deletions src/ui/features/GoalManager.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
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'
import 'date-fns'
import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
import { updateGoal as updateGoalApi } from '../../../api/lib'
import { Goal } from '../../../api/types'
import { selectGoalsMap, updateGoal as updateGoalRedux } from '../../../store/goalsSlice'
import { useAppDispatch, useAppSelector } from '../../../store/hooks'
import DatePicker from '../../components/DatePicker'
import { Theme } from '../../components/Theme'
import { Picker } from 'emoji-mart'
import 'emoji-mart/css/emoji-mart.css'

type Props = { goal: Goal }
export function GoalManager(props: Props) {
const dispatch = useAppDispatch()

const goal = useAppSelector(selectGoalsMap)[props.goal.id] as Goal | undefined
const [showPicker, setShowPicker] = React.useState(false)
const [icon, setIcon] = React.useState(goal?.icon || "🎯")
const [name, setName] = useState<string | null>(null)
const [targetDate, setTargetDate] = useState<Date | null>(null)
const [targetAmount, setTargetAmount] = useState<number | null>(null)

useEffect(() => {
setName(props.goal.name)
setTargetDate(props.goal.targetDate)
setTargetAmount(props.goal.targetAmount)
setIcon(props.goal.icon || "🎯")
}, [
props.goal.id,
props.goal.name,
props.goal.targetDate,
props.goal.targetAmount,
])

useEffect(() => {
if (goal) {
setName(goal.name)
}
}, [goal])

const updateNameOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const nextName = event.target.value
setName(nextName)
const updatedGoal: Goal = {
...props.goal,
name: nextName,
icon: icon,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}

const updateTargetAmountOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const nextTargetAmount = parseFloat(event.target.value) || 0
setTargetAmount(nextTargetAmount)
const updatedGoal: Goal = {
...props.goal,
name: name ?? props.goal.name,
targetDate: targetDate ?? props.goal.targetDate,
targetAmount: nextTargetAmount,
icon: icon,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}

const pickDateOnChange = (date: MaterialUiPickersDate) => {
if (date != null) {
setTargetDate(date)
const updatedGoal: Goal = {
...props.goal,
name: name ?? props.goal.name,
targetDate: date ?? props.goal.targetDate,
targetAmount: targetAmount ?? props.goal.targetAmount,
icon: icon,
}
dispatch(updateGoalRedux(updatedGoal))
updateGoalApi(props.goal.id, updatedGoal)
}
}

const pickEmojiOnClick = (emoji: any) => {
setIcon(emoji.native)
setShowPicker(false)

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

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

if (!goal) {
return <div>Loading...</div>
}

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

<Group>
<Field name="Icon" icon={faDollarSign} />
<Value>
<button onClick={() => setShowPicker(!showPicker)}>
{icon}
</button>
{showPicker && (
<Picker
onSelect={pickEmojiOnClick}
/>
)}
</Value>
</Group>

<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>
</Container>
)
}

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>
<FontAwesomeIcon icon={props.icon} size="2x" />
<FieldName>{props.name}</FieldName>
</FieldContainer>
)

const Container = styled.div`
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
height: 100%;
width: 100%;
position: relative;
`

const Group = styled.div`
display: flex;
flex-direction: row;
width: 100%;
margin-top: 1.25rem;
margin-bottom: 1.25rem;
`
const NameInput = styled.input`
display: flex;
background-color: transparent;
outline: none;
border: none;
font-size: 4rem;
font-weight: bold;
color: ${({ theme }: { theme: Theme }) => theme.text};
`

const FieldName = styled.h1`
font-size: 1.8rem;
margin-left: 1rem;
color: rgba(174, 174, 174, 1);
font-weight: normal;
`
const FieldContainer = styled.div`
display: flex;
flex-direction: row;
align-items: center;
width: 20rem;

svg {
color: rgba(174, 174, 174, 1);
}
`
const StringValue = styled.h1`
font-size: 1.8rem;
font-weight: bold;
`
const StringInput = styled.input`
display: flex;
background-color: transparent;
outline: none;
border: none;
font-size: 1.8rem;
font-weight: bold;
color: ${({ theme }: { theme: Theme }) => theme.text};
`

const Value = styled.div`
margin-left: 2rem;
`
31 changes: 0 additions & 31 deletions src/ui/features/goalmanager/AddIconButton.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions src/ui/features/goalmanager/GoalIcon.tsx

This file was deleted.

Loading