From 43ab66654042a274fd7f29b099913cdfc4daa2ce Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Mon, 6 Nov 2023 15:27:11 +1300 Subject: [PATCH] =?UTF-8?q?Make=20it=20easier=20to=20read=20old=20sets=20o?= =?UTF-8?q?n=20ViewSetList=20-=201.168=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now sets alternate background color based on the day they were entered. --- SetItem.tsx | 4 ++- ViewSetList.tsx | 54 ++++++++++++++++++++++++++-------------- android/app/build.gradle | 4 +-- package.json | 2 +- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/SetItem.tsx b/SetItem.tsx index b85bba9..51c1cca 100644 --- a/SetItem.tsx +++ b/SetItem.tsx @@ -15,12 +15,14 @@ export default function SetItem({ ids, setIds, disablePress, + customBg, }: { item: GymSet; settings: Settings; ids: number[]; setIds: (value: number[]) => void; disablePress?: boolean; + customBg?: string; }) { const dark = useDark(); const navigation = useNavigation>(); @@ -71,7 +73,7 @@ export default function SetItem({ title={item.name} description={`${item.reps} x ${item.weight}${item.unit || "kg"}`} onLongPress={longPress} - style={{ backgroundColor }} + style={{ backgroundColor: customBg || backgroundColor }} left={left} right={right} /> diff --git a/ViewSetList.tsx b/ViewSetList.tsx index ba6bc68..5baa7ed 100644 --- a/ViewSetList.tsx +++ b/ViewSetList.tsx @@ -1,7 +1,7 @@ import { RouteProp, useRoute } from "@react-navigation/native"; -import { useCallback, useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import { FlatList } from "react-native"; -import { List } from "react-native-paper"; +import { List, useTheme } from "react-native-paper"; import { Like } from "typeorm"; import { StackParams } from "./AppStack"; import SetItem from "./SetItem"; @@ -11,39 +11,57 @@ import { setRepo, settingsRepo } from "./db"; import GymSet from "./gym-set"; import Settings from "./settings"; +interface ColorSet extends GymSet { + color?: string; +} + export default function ViewSetList() { - const [sets, setSets] = useState(); + const [sets, setSets] = useState(); const [settings, setSettings] = useState(); + const { colors } = useTheme(); const { params } = useRoute>(); useEffect(() => { settingsRepo.findOne({ where: {} }).then(setSettings); const reset = async () => { - const newSets = await setRepo.find({ + const newSets: ColorSet[] = await setRepo.find({ where: { name: Like(`%${params.name}%`), hidden: 0 as any }, - take: LIMIT * 2, + take: LIMIT, skip: 0, order: { created: "DESC" }, }); + + let prevDate = null; + let color = colors.elevation.level3; + + for (let i = 0; i < newSets.length; i++) { + let currDate = new Date(newSets[i].created).toDateString(); + if (currDate !== prevDate) + color = + color === colors.elevation.level3 + ? colors.elevation.level0 + : colors.elevation.level3; + newSets[i].color = color; + prevDate = currDate; + } + setSets(newSets); }; reset(); - }, [params.name]); + }, [params.name, colors]); - const renderItem = useCallback( - ({ item }: { item: GymSet }) => ( - null} - disablePress - /> - ), - [settings] + const renderItem = ({ item }: { item: ColorSet; index: number }) => ( + null} + disablePress + customBg={item.color} + /> ); const getContent = () => { diff --git a/android/app/build.gradle b/android/app/build.gradle index e55b553..bc9f3be 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -85,8 +85,8 @@ android { applicationId "com.massive" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 36193 - versionName "1.167" + versionCode 36194 + versionName "1.168" } signingConfigs { release { diff --git a/package.json b/package.json index 1e377d4..49825c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "massive", - "version": "1.167", + "version": "1.168", "private": true, "license": "GPL-3.0-only", "scripts": {