@@ -3,7 +3,7 @@ import { format } from 'date-fns';
33import React , { useContext , useEffect , useState } from 'react' ;
44import { useHistory } from 'react-router-dom' ;
55import { Button , Checkbox , Typography } from '@mui/material' ;
6- import { initiate } from '../api/generic.js' ;
6+ import { downloadData , initiate } from '../api/generic.js' ;
77import Pulse from '../components/pulse/Pulse.jsx' ;
88import { AppContext } from '../context/AppContext' ;
99import { selectCsrfToken , selectCurrentUser } from '../context/selectors' ;
@@ -42,18 +42,44 @@ const PulsePage = () => {
4242 const [ year , month , day ] = pulse . submissionDate ;
4343 setSubmittedToday (
4444 year === now . getFullYear ( ) &&
45- month === now . getMonth ( ) + 1 &&
46- day === now . getDate ( )
45+ month === now . getMonth ( ) + 1 &&
46+ day === now . getDate ( )
4747 ) ;
48-
49- setInternalComment ( pulse . internalFeelings ?? '' ) ;
50- setExternalComment ( pulse . externalFeelings ?? '' ) ;
51- setInternalScore ( pulse . internalScore == undefined ?
52- center : pulse . internalScore - 1 ) ;
53- setExternalScore ( pulse . externalScore == undefined ?
54- center : pulse . externalScore - 1 ) ;
5548 } , [ pulse ] ) ;
5649
50+ const loadTodayPulse = async ( ) => {
51+ if ( ! csrf || ! currentUser ?. id ) return ;
52+
53+ const query = {
54+ dateFrom : today ,
55+ dateTo : today ,
56+ teamMemberId : currentUser . id
57+ } ;
58+
59+ const res = await downloadData ( pulseURL , csrf , query ) ;
60+ if ( res . error ) return ;
61+
62+ // Sort pulse responses by date, latest to earliest
63+ const pulses = res . payload . data ?. sort ( ( a , b ) => {
64+ const l = a . submissionDate ;
65+ const r = b . submissionDate ;
66+ if ( r [ 0 ] == l [ 0 ] ) {
67+ if ( r [ 1 ] == l [ 1 ] ) {
68+ return r [ 2 ] - l [ 2 ] ;
69+ } else {
70+ return r [ 1 ] - l [ 1 ] ;
71+ }
72+ } else {
73+ return r [ 0 ] - l [ 0 ] ;
74+ }
75+ } ) ;
76+ setPulse ( pulses . at ( 0 ) ) ;
77+ } ;
78+
79+ useEffect ( ( ) => {
80+ loadTodayPulse ( ) ;
81+ } , [ csrf , currentUser ] ) ;
82+
5783 const submit = async ( ) => {
5884 const myId = currentUser ?. id ;
5985 const data = {
0 commit comments