Prevent sets dissapearing after updating - 1.146

Previously we would always update the created
field by making a new Date object, even if
the user didn't pick a new date. On some
devices this might slightly change the time
of the day, meaning it jumps somewhere else
on the home page.
This commit is contained in:
Brandon Presley 2023-07-27 13:24:32 +12:00
parent e628d345ca
commit 158dd61668
3 changed files with 21 additions and 16 deletions

View File

@ -30,9 +30,10 @@ export default function EditSet() {
const [weight, setWeight] = useState(set.weight?.toString()) const [weight, setWeight] = useState(set.weight?.toString())
const [newImage, setNewImage] = useState(set.image) const [newImage, setNewImage] = useState(set.image)
const [unit, setUnit] = useState(set.unit) const [unit, setUnit] = useState(set.unit)
const [created, setCreated] = useState( const [created, setCreated] = useState<Date>(
set.created ? new Date(set.created) : new Date(), set.created ? new Date(set.created) : new Date(),
) )
const [createdDirty, setCreatedDirty] = useState(false)
const [showRemove, setShowRemove] = useState(false) const [showRemove, setShowRemove] = useState(false)
const [removeImage, setRemoveImage] = useState(false) const [removeImage, setRemoveImage] = useState(false)
const weightRef = useRef<TextInput>(null) const weightRef = useRef<TextInput>(null)
@ -70,35 +71,38 @@ export default function EditSet() {
value.weight > set.weight || value.weight > set.weight ||
(value.reps > set.reps && value.weight === set.weight) (value.reps > set.reps && value.weight === set.weight)
) { ) {
toast("Great work King! That's a new record.") toast('Great work King! That\'s a new record.')
} }
}, },
[startTimer, set, settings], [startTimer, set, settings],
) )
const handleSubmit = async () => { const handleSubmit = async () => {
console.log(`${EditSet.name}.handleSubmit:`, { set, uri: newImage, name })
if (!name) return if (!name) return
let image = newImage
if (!newImage && !removeImage) {
image = await setRepo.findOne({ where: { name } }).then((s) => s?.image)
}
console.log(`${EditSet.name}.handleSubmit:`, { image }) const newSet: Partial<GymSet> = {
const now = await getNow()
const saved = await setRepo.save({
id: set.id, id: set.id,
name, name,
created: created?.toISOString() || now,
reps: Number(reps), reps: Number(reps),
weight: Number(weight), weight: Number(weight),
unit, unit,
image,
minutes: Number(set.minutes ?? 3), minutes: Number(set.minutes ?? 3),
seconds: Number(set.seconds ?? 30), seconds: Number(set.seconds ?? 30),
sets: set.sets ?? 3, sets: set.sets ?? 3,
hidden: false, hidden: false,
}) }
newSet.image = newImage
if (!newImage && !removeImage) {
newSet.image = await setRepo.findOne({ where: { name } }).then((s) =>
s?.image
)
}
if (createdDirty) newSet.created = created.toISOString()
if (typeof set.id !== 'number') newSet.created = await getNow()
const saved = await setRepo.save(newSet)
if (typeof set.id !== 'number') added(saved) if (typeof set.id !== 'number') added(saved)
navigation.goBack() navigation.goBack()
} }
@ -123,6 +127,7 @@ export default function EditSet() {
onChange: (_, date) => { onChange: (_, date) => {
if (date === created) return if (date === created) return
setCreated(date) setCreated(date)
setCreatedDirty(true)
DateTimePickerAndroid.open({ DateTimePickerAndroid.open({
value: date, value: date,
onChange: (__, time) => setCreated(time), onChange: (__, time) => setCreated(time),

View File

@ -85,8 +85,8 @@ android {
applicationId "com.massive" applicationId "com.massive"
minSdkVersion rootProject.ext.minSdkVersion minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 36171 versionCode 36172
versionName "1.145" versionName "1.146"
} }
signingConfigs { signingConfigs {
release { release {

View File

@ -1,6 +1,6 @@
{ {
"name": "massive", "name": "massive",
"version": "1.145", "version": "1.146",
"private": true, "private": true,
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"scripts": { "scripts": {