Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Work on inputs #719

Merged
merged 7 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dev-client/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

import {SoilIdProjectSoilSettingsDepthIntervalPresetChoices} from 'terraso-client-shared/graphqlSchema/graphql';

/** Minimum distance to travel before Mapbox will update user location */
export const PACKAGE_NAME = 'org.terraso.landpks';
export const USER_DISPLACEMENT_MIN_DISTANCE_M = 1;
Expand All @@ -37,4 +39,5 @@ export const GEOSPATIAL_CONTEXT_USER_DISTANCE_CACHE = 5;
export const SITE_NOTE_MIN_LENGTH = 3;
export const LOCALE = 'en-US';

export const DepthPresets = ['landPks', 'nrcs', 'custom', 'none'];
export const DepthPresets: SoilIdProjectSoilSettingsDepthIntervalPresetChoices[] =
['LANDPKS', 'NRCS', 'CUSTOM', 'NONE'];
63 changes: 44 additions & 19 deletions dev-client/src/screens/ProjectInputScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ import {updateProject} from 'terraso-client-shared/project/projectSlice';
import {Icon, IconButton} from 'terraso-mobile-client/components/Icons';
import {Modal} from 'terraso-mobile-client/components/Modal';
import {AddIntervalModal} from 'terraso-mobile-client/components/AddIntervalModal';
import {useMemo, useCallback} from 'react';
import {useMemo, useCallback, useState} from 'react';
import {NativeStackScreenProps} from '@react-navigation/native-stack';
import {ScrollView, Switch} from 'react-native';
import {useInfoPress} from 'terraso-mobile-client/hooks/useInfoPress';
import {DepthPresets} from 'terraso-mobile-client/constants';
import {useNavigation} from 'terraso-mobile-client/navigation/hooks/useNavigation';
import {SoilIdProjectSoilSettingsDepthIntervalPresetChoices} from 'terraso-client-shared/graphqlSchema/graphql';
import {ConfirmModal} from 'terraso-mobile-client/components/ConfirmModal';

type Props = NativeStackScreenProps<TabStackParamList, TabRoutes.INPUTS>;

Expand Down Expand Up @@ -170,6 +172,10 @@ const SoilPitSettings = ({projectId}: {projectId: string}) => {
const settings = useSelector(
state => state.soilId.projectSettings[projectId],
);
const [selectedPreset, setSelectedPreset] =
useState<SoilIdProjectSoilSettingsDepthIntervalPresetChoices>(
settings.depthIntervalPreset,
);
const dispatch = useDispatch();
const existingIntervals = useMemo(
() => settings.depthIntervals.map(interval => interval.depthInterval),
Expand All @@ -183,30 +189,49 @@ const SoilPitSettings = ({projectId}: {projectId: string}) => {
[projectId, dispatch],
);

const onChangeDepthPreset = (value: string) => {
// TODO: need to add/change project depth intervals based on selected value
console.log(value);
};
const onChangeDepthPreset = useCallback(() => {
dispatch(
updateProjectSoilSettings({
projectId,
depthIntervalPreset: selectedPreset,
}),
);
}, [dispatch, projectId, selectedPreset]);

return (
<Box p={4}>
<Text color={'primary.main'}>
{t('projects.inputs.depth_intervals.title')}
</Text>
<Select
mb={5}
width={'60%'}
variant={'underlined'}
selectedValue={DepthPresets[0]}
onValueChange={value => onChangeDepthPreset(value)}>
{DepthPresets.map(preset => (
<Select.Item
label={t(`projects.inputs.depth_intervals.${preset}`)}
value={preset}
key={preset}
/>
))}
</Select>
<ConfirmModal
trigger={onOpen => (
<Select
mb={5}
width={'60%'}
variant={'underlined'}
selectedValue={settings.depthIntervalPreset}
onValueChange={value => {
setSelectedPreset(
value as SoilIdProjectSoilSettingsDepthIntervalPresetChoices,
);
onOpen();
}}>
{DepthPresets.map(preset => (
<Select.Item
label={t(
`projects.inputs.depth_intervals.${preset.toLowerCase()}`,
)}
value={preset}
key={preset}
/>
))}
</Select>
)}
title={t('projects.inputs.depth_intervals.confirm_preset.title')}
body={t('projects.inputs.depth_intervals.confirm_preset.body')}
actionName={t('projects.inputs.depth_intervals.confirm_preset.confirm')}
handleConfirm={onChangeDepthPreset}
/>
{settings.depthIntervals.map(({label, depthInterval}) => (
<Row key={`${depthInterval.start}:${depthInterval.end}`}>
<Text flex={1}>{label}</Text>
Expand Down
9 changes: 7 additions & 2 deletions dev-client/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,15 @@
},
"depth_intervals": {
"title": "Soil Pit Depth Intervals",
"landPks": "LandPKS",
"landpks": "LandPKS",
"nrcs": "NRCS",
"custom": "Custom…",
"none": "None specified"
"none": "None specified",
"confirm_preset": {
"title": "Change depths?",
"body": "Soil pit data that has been entered will be deleted. This action cannot be undone.",
"confirm": "Change"
}
}
},
"team": {
Expand Down