Make it easier to read old sets on ViewSetList - 1.168 🚀
Now sets alternate background color based on the day they were entered.
This commit is contained in:
parent
1a2d7a27a0
commit
43ab666540
|
@ -15,12 +15,14 @@ export default function SetItem({
|
||||||
ids,
|
ids,
|
||||||
setIds,
|
setIds,
|
||||||
disablePress,
|
disablePress,
|
||||||
|
customBg,
|
||||||
}: {
|
}: {
|
||||||
item: GymSet;
|
item: GymSet;
|
||||||
settings: Settings;
|
settings: Settings;
|
||||||
ids: number[];
|
ids: number[];
|
||||||
setIds: (value: number[]) => void;
|
setIds: (value: number[]) => void;
|
||||||
disablePress?: boolean;
|
disablePress?: boolean;
|
||||||
|
customBg?: string;
|
||||||
}) {
|
}) {
|
||||||
const dark = useDark();
|
const dark = useDark();
|
||||||
const navigation = useNavigation<NavigationProp<StackParams>>();
|
const navigation = useNavigation<NavigationProp<StackParams>>();
|
||||||
|
@ -71,7 +73,7 @@ export default function SetItem({
|
||||||
title={item.name}
|
title={item.name}
|
||||||
description={`${item.reps} x ${item.weight}${item.unit || "kg"}`}
|
description={`${item.reps} x ${item.weight}${item.unit || "kg"}`}
|
||||||
onLongPress={longPress}
|
onLongPress={longPress}
|
||||||
style={{ backgroundColor }}
|
style={{ backgroundColor: customBg || backgroundColor }}
|
||||||
left={left}
|
left={left}
|
||||||
right={right}
|
right={right}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { RouteProp, useRoute } from "@react-navigation/native";
|
import { RouteProp, useRoute } from "@react-navigation/native";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { FlatList } from "react-native";
|
import { FlatList } from "react-native";
|
||||||
import { List } from "react-native-paper";
|
import { List, useTheme } from "react-native-paper";
|
||||||
import { Like } from "typeorm";
|
import { Like } from "typeorm";
|
||||||
import { StackParams } from "./AppStack";
|
import { StackParams } from "./AppStack";
|
||||||
import SetItem from "./SetItem";
|
import SetItem from "./SetItem";
|
||||||
|
@ -11,39 +11,57 @@ import { setRepo, settingsRepo } from "./db";
|
||||||
import GymSet from "./gym-set";
|
import GymSet from "./gym-set";
|
||||||
import Settings from "./settings";
|
import Settings from "./settings";
|
||||||
|
|
||||||
|
interface ColorSet extends GymSet {
|
||||||
|
color?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default function ViewSetList() {
|
export default function ViewSetList() {
|
||||||
const [sets, setSets] = useState<GymSet[]>();
|
const [sets, setSets] = useState<ColorSet[]>();
|
||||||
const [settings, setSettings] = useState<Settings>();
|
const [settings, setSettings] = useState<Settings>();
|
||||||
|
const { colors } = useTheme();
|
||||||
const { params } = useRoute<RouteProp<StackParams, "ViewSetList">>();
|
const { params } = useRoute<RouteProp<StackParams, "ViewSetList">>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
settingsRepo.findOne({ where: {} }).then(setSettings);
|
settingsRepo.findOne({ where: {} }).then(setSettings);
|
||||||
|
|
||||||
const reset = async () => {
|
const reset = async () => {
|
||||||
const newSets = await setRepo.find({
|
const newSets: ColorSet[] = await setRepo.find({
|
||||||
where: { name: Like(`%${params.name}%`), hidden: 0 as any },
|
where: { name: Like(`%${params.name}%`), hidden: 0 as any },
|
||||||
take: LIMIT * 2,
|
take: LIMIT,
|
||||||
skip: 0,
|
skip: 0,
|
||||||
order: { created: "DESC" },
|
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);
|
setSets(newSets);
|
||||||
};
|
};
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}, [params.name]);
|
}, [params.name, colors]);
|
||||||
|
|
||||||
const renderItem = useCallback(
|
const renderItem = ({ item }: { item: ColorSet; index: number }) => (
|
||||||
({ item }: { item: GymSet }) => (
|
<SetItem
|
||||||
<SetItem
|
settings={settings}
|
||||||
settings={settings}
|
item={item}
|
||||||
item={item}
|
key={item.id}
|
||||||
key={item.id}
|
ids={[]}
|
||||||
ids={[]}
|
setIds={() => null}
|
||||||
setIds={() => null}
|
disablePress
|
||||||
disablePress
|
customBg={item.color}
|
||||||
/>
|
/>
|
||||||
),
|
|
||||||
[settings]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const getContent = () => {
|
const getContent = () => {
|
||||||
|
|
|
@ -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 36193
|
versionCode 36194
|
||||||
versionName "1.167"
|
versionName "1.168"
|
||||||
}
|
}
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
release {
|
release {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "massive",
|
"name": "massive",
|
||||||
"version": "1.167",
|
"version": "1.168",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in New Issue