Skip to content
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

Frankreed/Bar chart is 60fps consistent now #129

Merged
merged 11 commits into from
Apr 9, 2024
10 changes: 9 additions & 1 deletion Utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,16 @@ export function lookUpExpectedPutts(proxHole) {
}

export function getIconByKey(key) {
const icons = [{ carry: "arrow-up" }, { sideLanding: "arrow-left-right" }];
const icons = [
{ carry: "arrow-up" },
{ sideLanding: "arrow-left-right" },
{ strokes: "golf-tee" },
];

const iconObject = icons.find((icon) => icon[key]);
return iconObject ? iconObject[key] : null;
}

export const getCombinedDrillTitle = (drillInfo) => {
return `${drillInfo.prettyDrillType} | ${drillInfo.subType}`;
};
3 changes: 0 additions & 3 deletions app/content/_layout.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Tabs } from "expo-router";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import { currentAuthContext } from "~/context/Auth";

export default () => {
const { currentUserId } = currentAuthContext();
console.log("user", currentUserId);
return (
<Tabs options={{ headerShown: false }}>
<Tabs.Screen
Expand Down
57 changes: 29 additions & 28 deletions app/content/drill/[id]/description.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@ export default function Description() {
);
};

const images = [
require("~/assets/drill-description-image.jpg"),
require("~/assets/adaptive-icon.png"),
require("~/assets/icon.png"),
require("~/assets/splash.png"),
require("~/assets/favicon.png"),
];
const images = [];

const hasImages = !!images.length;

const windowWidth = Dimensions.get("window").width;
const windowHeight = Dimensions.get("window").height;
Expand All @@ -90,28 +86,33 @@ export default function Description() {
Description
</Text>
<Text variant="bodySmall">{drillInfo["description"]}</Text>
<View style={{ marginTop: 10 }}>
<View
style={{
flexDirection: "row",
flexWrap: "wrap",
justifyContent: "space-between",
}}
>
{images.map((image, index) => (
<TouchableOpacity key={index} onPress={() => openModal(index)}>
<Image
style={{
width: windowWidth / 3 - 10,
height: windowWidth / 3 - 10,
marginBottom: 15,
}}
source={image}
/>
</TouchableOpacity>
))}
{hasImages && (
<View style={{ marginTop: 10 }}>
<View
style={{
flexDirection: "row",
flexWrap: "wrap",
justifyContent: "space-between",
}}
>
{images.map((image, index) => (
<TouchableOpacity
key={index}
onPress={() => openModal(index)}
>
<Image
style={{
width: windowWidth / 3 - 10,
height: windowWidth / 3 - 10,
marginBottom: 15,
}}
source={image}
/>
</TouchableOpacity>
))}
</View>
</View>
</View>
)}
</ScrollView>

<Modal
Expand Down
3 changes: 2 additions & 1 deletion app/content/drill/[id]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SafeAreaView } from "react-native-safe-area-context";
import ErrorComponent from "~/components/errorComponent";
import Loading from "~/components/loading";
import { useDrillInfo } from "~/hooks/useDrillInfo";
import { getCombinedDrillTitle } from "~/Utility";

export default function Index() {
const [value, setValue] = React.useState("description");
Expand Down Expand Up @@ -48,7 +49,7 @@ export default function Index() {
}}
color={"#F24E1E"}
/>
<Appbar.Content title={drillInfo["drillType"]} />
<Appbar.Content title={getCombinedDrillTitle(drillInfo)} />
</Appbar.Header>

{/* Tab system */}
Expand Down
13 changes: 10 additions & 3 deletions app/content/drill/[id]/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ export default function Leaderboard() {
error: leaderboardError,
} = useLeaderboard({ drillId });

const preCalcLeaderboardExists =
preCalcLeaderboard && Object.keys(preCalcLeaderboard).length > 0;

useEffect(() => {
setManualAttemptCalc(
!drillIsLoading && // so that mainOutputAttempt is calculated
!leaderboardIsLoading && //leaderboard must've finished loading
(!preCalcLeaderboard || //and not exist
(!preCalcLeaderboardExists || //and not exist
preCalcLeaderboard[Object.keys(preCalcLeaderboard)[0]][
mainOutputAttempt
] === undefined), //or exist but does not have the required field
Expand Down Expand Up @@ -83,7 +86,7 @@ export default function Leaderboard() {
: customMainOutputAttempt;

const leaderboardAttempts = preCalcLeaderboard || {};
if (!preCalcLeaderboard && attempts) {
if (!preCalcLeaderboardExists && attempts) {
//just in case...
for (const id in attempts) {
const entry = attempts[id];
Expand Down Expand Up @@ -125,6 +128,10 @@ export default function Leaderboard() {
leaderboardAttempts[b][mainOutputAttempt]["value"],
);

if (orderedLeaderboard.length < 1) {
return <Text>No attempts have been made yet.</Text>;
}

return (
<ScrollView>
<List.Section style={{ marginLeft: 20 }}>
Expand All @@ -139,7 +146,7 @@ export default function Leaderboard() {
asChild
>
<List.Item
title={userInfo[userId]["name"]}
title={userInfo[userId] ? userInfo[userId]["name"] : "Unknown"}
left={() => <Avatar.Text size={24} label="XD" />}
right={() => (
<View style={{ flexDirection: "row", alignItems: "center" }}>
Expand Down
19 changes: 17 additions & 2 deletions app/content/drill/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SafeAreaView } from "react-native-safe-area-context";
import ErrorComponent from "~/components/errorComponent";
import Loading from "~/components/loading";
import { useDrillInfo } from "~/hooks/useDrillInfo";
import { getCombinedDrillTitle } from "~/Utility";

export default function Index() {
const navigation = useNavigation();
Expand All @@ -24,6 +25,20 @@ export default function Index() {
return <ErrorComponent message={drillInfoError} />;
}

const drills = Object.values(drillInfo);

drills.sort((a, b) => {
const titleA = getCombinedDrillTitle(a).toUpperCase();
const titleB = getCombinedDrillTitle(b).toUpperCase();
if (titleA < titleB) {
return -1;
}
if (titleA > titleB) {
return 1;
}
return 0;
});

return (
<PaperProvider>
<SafeAreaView>
Expand All @@ -33,7 +48,7 @@ export default function Index() {

<ScrollView contentContainerStyle={styles.scrollView}>
<List.Section>
{Object.values(drillInfo).map((drill) => (
{Object.values(drills).map((drill) => (
<Link
key={drill.did}
href={{
Expand All @@ -43,7 +58,7 @@ export default function Index() {
style={{ paddingVertical: 8 }}
>
<List.Item
title={drill.drillType}
title={getCombinedDrillTitle(drill)}
description={drill.description}
titleStyle={styles.title}
descriptionStyle={styles.description}
Expand Down
Loading
Loading