fixing logbook date sort #54
@@ -1,3 +0,0 @@
|
|||||||
# Flying
|
|
||||||
|
|
||||||
A pilot's logbook for tracking flight hours.
|
|
||||||
@@ -186,81 +186,62 @@ const LogForm: React.FC<ILogFormProps> = ({
|
|||||||
</Alert>
|
</Alert>
|
||||||
</Grid>
|
</Grid>
|
||||||
)}
|
)}
|
||||||
{!FormMode.VIEW &&
|
<Grid alignItems="center" display="flex" size={4}>
|
||||||
<>
|
<Typography variant="body1">Pilot *</Typography>
|
||||||
<Grid alignItems="center" display="flex" size={4}>
|
</Grid>
|
||||||
<Typography variant="body1">Pilot *</Typography>
|
<Grid size={8}>
|
||||||
</Grid>
|
<Controller
|
||||||
<Grid size={8}>
|
name="pilotId"
|
||||||
<Controller
|
control={methods.control}
|
||||||
name="pilotId"
|
render={({ field: { onChange, value } }) => {
|
||||||
control={methods.control}
|
useEffect(() => {
|
||||||
render={({ field: { onChange, value } }) => {
|
if (value && mode !== FormMode.ADD) {
|
||||||
useEffect(() => {
|
const pilot = pilots?.find((pilot) => pilot.id === value);
|
||||||
if (value) {
|
|
||||||
const pilot = pilots?.find((pilot) => pilot.id === value);
|
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'SET_SELECTED_ENTRY_PILOT_NAME',
|
type: 'SET_SELECTED_ENTRY_PILOT_NAME',
|
||||||
payload: pilot.name
|
payload: pilot.name
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{mode === FormMode.ADD && (
|
{mode === FormMode.ADD && (
|
||||||
<Select
|
<Select
|
||||||
disabled={state.isDisabled}
|
disabled={state.isDisabled}
|
||||||
fullWidth
|
fullWidth
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
const pilot = pilots?.find(
|
const pilot = pilots?.find(
|
||||||
(pilot) => (pilot.id = event.target.value)
|
(pilot) => (pilot.id = event.target.value)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (pilot) {
|
if (pilot) {
|
||||||
methods.setValue('pilotName', pilot.name);
|
methods.setValue('pilotName', pilot.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
methods.setValue('pilotId', event.target.value);
|
methods.setValue('pilotId', event.target.value);
|
||||||
}}
|
}}
|
||||||
options={
|
options={
|
||||||
state.pilotOptions && state.pilotOptions.length > 0
|
state.pilotOptions && state.pilotOptions.length > 0
|
||||||
? state.pilotOptions
|
? state.pilotOptions
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
value={value}
|
value={value}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
{mode !== FormMode.ADD && (
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</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
|
<TextField
|
||||||
disabled={true}
|
disabled={true}
|
||||||
fullWidth
|
fullWidth
|
||||||
value={value}
|
value={state.selectedEntryPilotName}
|
||||||
/>
|
/>
|
||||||
)
|
)}
|
||||||
}}
|
</>
|
||||||
/>
|
);
|
||||||
</Grid>
|
}}
|
||||||
</>
|
/>
|
||||||
}
|
</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>
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
|||||||
Reference in New Issue
Block a user