fixing logbook date sort (#54)

This commit was merged in pull request #54.
This commit is contained in:
2025-02-25 00:51:22 +00:00
committed by GitHub
parent 07575302cc
commit 80cfa52413
3 changed files with 51 additions and 70 deletions

View File

@@ -1,3 +0,0 @@
# Flying
A pilot's logbook for tracking flight hours.

View File

@@ -186,8 +186,6 @@ const LogForm: React.FC<ILogFormProps> = ({
</Alert> </Alert>
</Grid> </Grid>
)} )}
{!FormMode.VIEW &&
<>
<Grid alignItems="center" display="flex" size={4}> <Grid alignItems="center" display="flex" size={4}>
<Typography variant="body1">Pilot *</Typography> <Typography variant="body1">Pilot *</Typography>
</Grid> </Grid>
@@ -197,7 +195,7 @@ const LogForm: React.FC<ILogFormProps> = ({
control={methods.control} control={methods.control}
render={({ field: { onChange, value } }) => { render={({ field: { onChange, value } }) => {
useEffect(() => { useEffect(() => {
if (value) { if (value && mode !== FormMode.ADD) {
const pilot = pilots?.find((pilot) => pilot.id === value); const pilot = pilots?.find((pilot) => pilot.id === value);
dispatch({ dispatch({
@@ -232,35 +230,18 @@ const LogForm: React.FC<ILogFormProps> = ({
value={value} value={value}
/> />
)} )}
{mode !== FormMode.ADD && (
<TextField
disabled={true}
fullWidth
value={state.selectedEntryPilotName}
/>
)}
</> </>
); );
}} }}
/> />
</Grid> </Grid>
</>
}
{FormMode.VIEW &&
<>
<Grid alignItems="center" display="flex" size={4}>
<Typography variant="body1">Pilot *</Typography>
</Grid>
<Grid size={8}>
<Controller
name="pilotName"
control={methods.control}
render={({ field: { value } }) => {
return (
<TextField
disabled={true}
fullWidth
value={value}
/>
)
}}
/>
</Grid>
</>
}
<Grid alignItems="center" display="flex" size={4}> <Grid alignItems="center" display="flex" size={4}>
<Typography variant="body1">Date *</Typography> <Typography variant="body1">Date *</Typography>
</Grid> </Grid>

View File

@@ -32,6 +32,9 @@ const Logbook: React.FC<unknown> = () => {
dispatch({ type: 'SET_IS_LOADING', payload: true }); dispatch({ type: 'SET_IS_LOADING', payload: true });
const response: AxiosResponse = await httpClient.get(`api/logs`); const response: AxiosResponse = await httpClient.get(`api/logs`);
const entries: ILogbookEntry[] = response.data;
entries.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
if (response.data.length > 0) { if (response.data.length > 0) {
dispatch({ type: 'SET_ENTRIES', payload: response.data }); dispatch({ type: 'SET_ENTRIES', payload: response.data });