fix: open not chosen when editing synced obs

This commit is contained in:
Ken-ichi Ueda
2024-08-26 14:36:09 -07:00
parent c2232382c5
commit 40fdb86e8a
2 changed files with 28 additions and 16 deletions

View File

@@ -1,53 +1,61 @@
// @flow
import {
RadioButtonSheet
} from "components/SharedComponents";
import type { Node } from "react";
import React from "react";
import React, { useMemo } from "react";
import {
GEOPRIVACY_OBSCURED,
GEOPRIVACY_OPEN,
GEOPRIVACY_PRIVATE
} from "realmModels/Observation";
import useTranslation from "sharedHooks/useTranslation";
type Geoprivacy = null | GEOPRIVACY_OPEN | GEOPRIVACY_OBSCURED | GEOPRIVACY_PRIVATE;
type Props = {
handleClose: Function,
selectedValue?: boolean,
updateGeoprivacyStatus: Function
handleClose: ( ) => void,
selectedValue?: Geoprivacy,
updateGeoprivacyStatus: ( Geoprivacy ) => void
}
const GeoprivacySheet = ( {
handleClose,
selectedValue,
updateGeoprivacyStatus
}: Props ): Node => {
}: Props ) => {
const { t } = useTranslation( );
const radioValues = {
const radioValues = useMemo( () => ( {
open: {
label: t( "Open" ),
text: t( "Anyone-using-iNaturalist-can-see" ),
value: "open"
value: GEOPRIVACY_OPEN
},
obscured: {
label: t( "Obscured" ),
text: t( "The-exact-location-will-be-hidden" ),
value: "obscured"
value: GEOPRIVACY_OBSCURED
},
private: {
label: t( "Private" ),
text: t( "The-location-will-not-be-visible" ),
value: "private"
value: GEOPRIVACY_PRIVATE
}
};
} ), [t] );
return (
<RadioButtonSheet
headerText={t( "GEOPRIVACY" )}
confirm={checkBoxValue => {
updateGeoprivacyStatus( checkBoxValue );
// Don't bother changing anything if we're "changing" from null
// to "open" since they're basically the same
if ( checkBoxValue !== GEOPRIVACY_OPEN || selectedValue !== null ) {
updateGeoprivacyStatus( checkBoxValue );
}
handleClose( );
}}
handleClose={handleClose}
radioValues={radioValues}
selectedValue={selectedValue}
selectedValue={selectedValue || GEOPRIVACY_OPEN}
/>
);
};

View File

@@ -14,6 +14,10 @@ import Taxon from "./Taxon";
import User from "./User";
import Vote from "./Vote";
export const GEOPRIVACY_OPEN = "open";
export const GEOPRIVACY_OBSCURED = "obscured";
export const GEOPRIVACY_PRIVATE = "private";
// noting that methods like .toJSON( ) are only accessible when the model
// class is extended with Realm.Object per this issue:
// https://github.com/realm/realm-js/issues/3600#issuecomment-785828614
@@ -107,7 +111,7 @@ class Observation extends Realm.Object {
return {
...obs,
captive_flag: false,
geoprivacy: "open",
geoprivacy: GEOPRIVACY_OPEN,
owners_identification_from_vision: false,
observed_on: obs?.observed_on,
observed_on_string: obs