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