Skip to content

Commit

Permalink
Finished with changes
Browse files Browse the repository at this point in the history
  • Loading branch information
plahteenlahti committed Sep 1, 2020
1 parent e994e46 commit 60831ac
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Types/SleepClockState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface SleepClockState {
sleepDataUpdated: string
today: string
current_day: Day
selectedDay: Day
selectedDay: string
activeIndex: number | null
ratings: []
days: Day[] | []
Expand Down
4 changes: 2 additions & 2 deletions src/actions/coaching/content-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getFieldValue = (
entry: Entry<any>,
fieldToGet: string,
object: any,
callback?: () => void,
callback?: (args: any) => void,
fieldToSet?: string
) => {
if (entry.fields[fieldToGet]) {
Expand All @@ -51,7 +51,7 @@ export const getAllWeeks = (): Thunk => async (dispatch: Dispatch) => {
const coachingWeeks: any = await client.getEntries({
locale,
content_type: 'coachingWeek',
'fields.slug[ne]': 'introduction',
// 'fields.slug[ne]': 'introduction',
include: 3
})

Expand Down
30 changes: 23 additions & 7 deletions src/actions/manual-sleep/manual-sleep-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { GetState } from '../../Types/GetState'
import { Day, Value, Night } from '../../Types/Sleepdata'
import { updateSleepData } from '../sleep/sleep-data-actions'
import { Dispatch, Thunk } from 'Types/ReduxActions'

export const SET_VALUES = 'SET_VALUES'
export const TOGGLE_EDIT_MODE = 'TOGGLE_EDIT_MODE'
Expand All @@ -30,7 +31,7 @@ export const addManualDataToNight = (
date: string,
nightStart: { h: number; m: number },
nightEnd: { h: number; m: number }
) => async (dispatch: Function, getState: GetState) => {
): Thunk => async (dispatch: Dispatch, getState: GetState) => {
const {
sleepclock: { days, nights }
} = getState()
Expand Down Expand Up @@ -102,21 +103,36 @@ export const createNight = async (
value: Value.Asleep
}

await AppleHealthKit.saveSleep(
newNightBed,
(error: any, response: any) => {}
)
await AppleHealthKit.saveSleep(newNightBed, (error: any, response: any) => {
if (error) {
throw error
} else {
return response
}
})

await AppleHealthKit.saveSleep(
newNightSleep,
(error: any, response: any) => {}
(error: any, response: any) => {
if (error) {
throw error
} else {
return response
}
}
)
} else {
const newNight = {
value,
startDate: startTime,
endDate: endTime
}
await AppleHealthKit.saveSleep(newNight, (error: any, response: any) => {})
await AppleHealthKit.saveSleep(newNight, (error: any, response: any) => {
if (error) {
throw error
} else {
return response
}
})
}
}
5 changes: 4 additions & 1 deletion src/actions/sleep/sleep-data-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export const updateDay = (day: Day) => ({
payload: day
})

export const updateSleepData = (data: { days: Day[]; nights: Night[] }) => ({
export const updateSleepData = (data: {
days: Day[]
nights: Night[]
}): ReduxAction => ({
type: UPDATE_SLEEP_DATA,
payload: data
})
Expand Down
1 change: 0 additions & 1 deletion src/components/Charts/SleepChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const SleepTimeChart: FC = () => {
const yTicks = scaleY.ticks(5)
const xTicks = scaleX.ticks(days.length)

console.log(normalizedSleepData, bedtimeWindow)
return (
<Card>
<Title>Sleep Goal Trend</Title>
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ export const getFormattedDateOrPlaceholder = (
formatter: string
): string => {
if (value) {
const asdasd = parseISO(value)
console.log(asdasd)
return format(asdasd, formatter)
return format(parseISO(value), formatter)
}

return '-'
Expand Down
21 changes: 9 additions & 12 deletions src/store/Reducers/sleepclockReducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { CREATE_SUCCESS } from '@actions/sleep/sleep-to-cloud-actions'
import moment from 'moment'
import ReduxAction from 'Types/ReduxActions'
import { RESET_APP } from '@actions/shared'
import {
CREATE_NEW_CALENDAR,
Expand All @@ -14,8 +11,10 @@ import {
UPDATE_DAY,
UPDATE_SLEEP_DATA
} from '@actions/sleep/sleep-data-actions'
import { CREATE_SUCCESS } from '@actions/sleep/sleep-to-cloud-actions'
import moment from 'moment'
import ReduxAction from 'Types/ReduxActions'
import { sortDays } from '../../helpers/sleep'
import { sameDay } from '../../helpers/time'
import { SleepClockState } from '../../Types/SleepClockState'
import { Day } from '../../Types/Sleepdata'
import { initialState } from '../InitialStates/SleepClock'
Expand All @@ -36,12 +35,7 @@ const reducer = (
}

case SET_TODAY_AS_SELECTED: {
const selectedDay = state.days.find((day: Day) =>
sameDay(payload, day.date)
)
const day = selectedDay || state.selectedDay

return { ...state, selectedDay: day }
return { ...state, selectedDay: payload }
}

case CREATE_NEW_CALENDAR:
Expand Down Expand Up @@ -78,9 +72,12 @@ const reducer = (

case RATE_NIGHT: {
const filteredDays = state.days.filter(
(item: Day) => item.date !== state.selectedDay.date
(item: Day) => item.date !== state.selectedDay
)
const day = state.days.find(
(item: Day) => item.date === state.selectedDay
)
const newDay = { ...state.selectedDay, rating: payload }
const newDay = { ...(day as Day), rating: payload }
const daysArray = [...filteredDays, newDay]
const sorted = sortDays(daysArray)
return { ...state, days: sorted }
Expand Down
24 changes: 14 additions & 10 deletions src/store/Selectors/SleepDataSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { clockTimeToAngle } from 'helpers/geometry'
import Moment from 'moment'
import { createSelector } from 'reselect'
import { SleepClockState } from '../../Types/SleepClockState'
import { Day } from '../../Types/Sleepdata'
import { Day, Days } from '../../Types/Sleepdata'
import { State } from '../../Types/State'

const getState = (state: State) => state.sleepclock
Expand Down Expand Up @@ -209,7 +209,7 @@ const dummyDay: Day = {
}

const getSday = (state: State) =>
state.sleepclock.selectedDay ? state.sleepclock.selectedDay : dummyDay
state.sleepclock.selectedDay ? state.sleepclock.selectedDay : dummyDay.date

const getSleepclock = (state: State) => state.sleepclock

Expand All @@ -219,18 +219,22 @@ export const getSleepTrackerName = createSelector(
)

export const getSelectedDay = createSelector(
(state: State) => state.sleepclock.selectedDay,
(selectedDay) => selectedDay
[getDays, getSday],
(days, selectedDay) => {
const fromState = days.find((day) => day.date === selectedDay)
const day = fromState ?? { ...dummyDay, date: selectedDay }
return day
}
)

export const getSelectedDayInBedDuration = createSelector(
getSday,
(selectedDay) => selectedDay.inBedDuration
getSelectedDay,
(selectedDay) => (selectedDay ? selectedDay.inBedDuration : 0)
)

export const getSelectedDayAsleepDuration = createSelector(
getSday,
(selectedDay) => selectedDay.asleepDuration
getSelectedDay,
(selectedDay) => (selectedDay ? selectedDay.asleepDuration : 0)
)

export const getSleepDataUpdated = createSelector(
Expand All @@ -249,13 +253,13 @@ export const getStartDate = createSelector(
)

export const getNightInAngles = createSelector(getSelectedDay, (day) => {
if (day.bedEnd && day.bedStart) {
if (day?.bedEnd && day?.bedStart) {
return {
startAngle: clockTimeToAngle(day.bedStart),
endAngle: clockTimeToAngle(day.bedEnd)
}
}
if (day.sleepEnd && day.sleepStart) {
if (day?.sleepEnd && day?.sleepStart) {
return {
startAngle: clockTimeToAngle(day.sleepStart),
endAngle: clockTimeToAngle(day.sleepEnd)
Expand Down
8 changes: 4 additions & 4 deletions src/styles/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export const lightTheme: DefaultTheme = {
SECONDARY_BUTTON_COLOR: colors.radiantBlue,
HAIRLINE_COLOR: '#C9C9CB',
GRADIENT: [
'rgba(255,255,255,0)',
'rgba(255,255,255,0)',
'rgba(255,255,255,1)'
'rgba(246,246,249,0)',
'rgba(246,246,249,0)',
'rgba(246,246,249,1)'
],
SHADOW: ` 1px 1px 5px rgba(32, 33, 37, 0.1)`,
SHADOW: `1px 1px 5px rgba(32, 33, 37, 0.1)`,

FONT_REGULAR: 'Montserrat-Regular',
FONT_MEDIUM: 'Montserrat-Medium',
Expand Down
10 changes: 7 additions & 3 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"Time asleep": "Time asleep",

"ClockNotLoading": "Something went wrong in loading data",
"Sleep Goal Trend": "Sleep Goal Trend",
"Sleep Goal Trend": "Sleep Trend",

"NEED_HELP": {
"TITLE": "Need Help?",
Expand Down Expand Up @@ -602,7 +602,10 @@

"HABITS": "Habits",
"ACTIVE": "Active Habits",
"ACTIVE_SUBTITLE": "Habits that are currently active.",
"ARCHIVED": "Archived Habits",
"ARCHIVED_SUBTITLE": "Habits that have been archived previously.",

"COMPLETED_HABITS": "{{completedCount}}/{{taskCount}} habits completed",
"NEW_HABIT": "New Habit",
"HABIT_STREAK": "{{dayStreak}}-day streak",
Expand All @@ -618,9 +621,10 @@
"DESCRIPTION_FIELD": "Description",
"LONGEST_STREAK": "Longest streak",
"CURRENT_STREAK": "Current streak",

"WARNING_TITLE_EXISTS": "Habit with this title already exists.",
"EXPLANATION_1": "TODO",
"EXPLANATION_2": "TODO",
"EXPLANATION_1": "Here you manage your Habits. You can create new ones from the top right corner. By swiping left or right on the Habit card, you can mark it as completed, archive it, or delete it.",
"EXPLANATION_2": "",

"MORNING": "Morning",
"AFTERNOON": "Afternoon",
Expand Down

0 comments on commit 60831ac

Please sign in to comment.