-
Notifications
You must be signed in to change notification settings - Fork 113
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
🏗️ Major Refactor to Remove Label Button Services #1086
Changes from 1 commit
3b5e169
dc28f99
8f76ecf
8712380
f7716cf
4d48aee
3855a03
40d3f75
49ff385
a34c219
c262f6a
9009517
fb46586
af5948b
d96ff8d
22b80f9
081b142
956f2d9
5110845
1f952f7
1b01692
5eb8d8f
24b34ee
55c313d
a60b1e2
d3e6af2
69b18cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Prettier was not running on these files because they had syntax errors from bad merge conflicts. Fixes syntax on these and runs Prettier to clean up
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,32 @@ | |
In the default configuration, these are the "Mode" and "Purpose" buttons. | ||
Next to the buttons is a small checkmark icon, which marks inferrel labels as confirmed */ | ||
|
||
import React, { useContext, useEffect, useState, useMemo } from "react"; | ||
import { getAngularService } from "../../angular-react-helper"; | ||
import { View, Modal, ScrollView, Pressable, useWindowDimensions } from "react-native"; | ||
import { IconButton, Text, Dialog, useTheme, RadioButton, Button, TextInput } from "react-native-paper"; | ||
import DiaryButton from "../../components/DiaryButton"; | ||
import { useTranslation } from "react-i18next"; | ||
import LabelTabContext from "../../diary/LabelTabContext"; | ||
import { displayErrorMsg, logDebug } from "../../plugin/logger"; | ||
import { getLabelInputDetails, getLabelInputs, inferFinalLabels, labelInputDetailsForTrip, labelKeyToRichMode, readableLabelToKey, verifiabilityForTrip } from "./confirmHelper"; | ||
import useAppConfig from "../../useAppConfig"; | ||
import React, { useContext, useEffect, useState, useMemo } from 'react'; | ||
import { getAngularService } from '../../angular-react-helper'; | ||
import { View, Modal, ScrollView, Pressable, useWindowDimensions } from 'react-native'; | ||
import { | ||
IconButton, | ||
Text, | ||
Dialog, | ||
useTheme, | ||
RadioButton, | ||
Button, | ||
TextInput, | ||
} from 'react-native-paper'; | ||
import DiaryButton from '../../components/DiaryButton'; | ||
import { useTranslation } from 'react-i18next'; | ||
import LabelTabContext from '../../diary/LabelTabContext'; | ||
import { displayErrorMsg, logDebug } from '../../plugin/logger'; | ||
import { | ||
getLabelInputDetails, | ||
getLabelInputs, | ||
inferFinalLabels, | ||
labelInputDetailsForTrip, | ||
labelKeyToRichMode, | ||
readableLabelToKey, | ||
verifiabilityForTrip, | ||
} from './confirmHelper'; | ||
import useAppConfig from '../../useAppConfig'; | ||
|
||
const MultilabelButtonGroup = ({ trip, buttonsInline = false }) => { | ||
const { colors } = useTheme(); | ||
|
@@ -78,40 +94,52 @@ const MultilabelButtonGroup = ({ trip, buttonsInline = false }) => { | |
} | ||
|
||
const tripInputDetails = labelInputDetailsForTrip(timelineLabelMap[trip._id.$oid], appConfig); | ||
return (<> | ||
<View style={{flexDirection: 'row', alignItems: 'center'}}> | ||
<View style={{flex: 1, flexDirection: buttonsInline ? 'row' : 'column', columnGap: 8}}> | ||
{Object.keys(tripInputDetails).map((key, i) => { | ||
const input = tripInputDetails[key]; | ||
const inputIsConfirmed = timelineLabelMap[trip._id.$oid]?.[input.name]; | ||
const inputIsInferred = inferFinalLabels(trip, timelineLabelMap[trip._id.$oid])[input.name]; | ||
let fillColor, textColor, borderColor; | ||
if (inputIsConfirmed) { | ||
fillColor = colors.primary; | ||
} else if (inputIsInferred) { | ||
fillColor = colors.secondaryContainer; | ||
borderColor = colors.secondary; | ||
textColor = colors.onSecondaryContainer; | ||
} | ||
const btnText = inputIsConfirmed?.text || inputIsInferred?.text || input.choosetext; | ||
return ( | ||
<> | ||
<View style={{ flexDirection: 'row', alignItems: 'center' }}> | ||
<View style={{ flex: 1, flexDirection: buttonsInline ? 'row' : 'column', columnGap: 8 }}> | ||
{Object.keys(tripInputDetails).map((key, i) => { | ||
const input = tripInputDetails[key]; | ||
const inputIsConfirmed = timelineLabelMap[trip._id.$oid]?.[input.name]; | ||
const inputIsInferred = inferFinalLabels(trip, timelineLabelMap[trip._id.$oid])[ | ||
input.name | ||
]; | ||
let fillColor, textColor, borderColor; | ||
if (inputIsConfirmed) { | ||
fillColor = colors.primary; | ||
} else if (inputIsInferred) { | ||
fillColor = colors.secondaryContainer; | ||
borderColor = colors.secondary; | ||
textColor = colors.onSecondaryContainer; | ||
} | ||
const btnText = inputIsConfirmed?.text || inputIsInferred?.text || input.choosetext; | ||
|
||
return ( | ||
<View key={i} style={{flex: 1}}> | ||
<Text>{t(input.labeltext)}</Text> | ||
<DiaryButton fillColor={fillColor} borderColor={borderColor} | ||
textColor={textColor} onPress={(e) => setModalVisibleFor(input.name)}> | ||
{ t(btnText) } | ||
</DiaryButton> | ||
</View> | ||
) | ||
})} | ||
</View> | ||
{verifiabilityForTrip(trip, timelineLabelMap[trip._id.$oid]) == 'can-verify' && ( | ||
<View style={{marginTop: 16}}> | ||
<IconButton icon='check-bold' mode='outlined' size={18} onPress={verifyTrip} | ||
containerColor={colors.secondaryContainer} | ||
style={{width: 24, height: 24, margin: 3, borderColor: colors.secondary}} /> | ||
return ( | ||
<View key={i} style={{ flex: 1 }}> | ||
<Text>{t(input.labeltext)}</Text> | ||
<DiaryButton | ||
fillColor={fillColor} | ||
borderColor={borderColor} | ||
textColor={textColor} | ||
onPress={(e) => setModalVisibleFor(input.name)}> | ||
{t(btnText)} | ||
</DiaryButton> | ||
</View> | ||
); | ||
})} | ||
</View> | ||
{verifiabilityForTrip(trip, timelineLabelMap[trip._id.$oid]) == 'can-verify' && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did we ever figure out the performance difference between calling functions and using fields in the TSX? As I said earlier, I am concerned that the overhead of a function call for each trip every time we scroll, for example. Does React handle this properly with caching? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Theoretically, in a React project I think the difference should be negligible because React components are designed to only re-render when their state, or any stateful props, are explicitly updated. That's why React doesn't like mutations - if a value changes by any other way, the React component will not reflect the change because it doesn't know to re-render itself. One caveat here though: the way |
||
<View style={{ marginTop: 16 }}> | ||
<IconButton | ||
icon="check-bold" | ||
mode="outlined" | ||
size={18} | ||
onPress={verifyTrip} | ||
containerColor={colors.secondaryContainer} | ||
style={{ width: 24, height: 24, margin: 3, borderColor: colors.secondary }} | ||
/> | ||
</View> | ||
)} | ||
{trip.verifiability === 'can-verify' && ( | ||
<View style={{ marginTop: 16 }}> | ||
<IconButton | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto