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

Planscreen player #131

Merged
merged 11 commits into from
Apr 9, 2024
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
- name: Install Prettier
run: yarn add prettier --dev
- name: Check code formatting
run: yarn pretty --check
run: yarn pretty:check
37 changes: 37 additions & 0 deletions add_user_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import random
import time
import math
import firebase_admin
from firebase_admin import firestore

app = firebase_admin.initialize_app()
db = firestore.client()

# Define the assigned_data array
assigned_data = [
{"drillId": "YtCsaxzscFScnpZYmnKI", "assignedTime": "1712600157", "completed": False},
{"drillId": "YtCsaxzscFScnpZYmnKI", "assignedTime": "1712531560", "completed": False},
{"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712531460", "completed": False},
{"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712531360", "completed": True},
{"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712531260", "completed": False},
{"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712470455", "completed": False},
{"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712470355", "completed": True},
{"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712470255", "completed": False},
{"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712384055", "completed": False},
{"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1709709255", "completed": False},
{"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1709622855", "completed": False},
]

# Get a reference to the user collection
users_collection = db.collection("teams").document("1").collection("users")


print(users_collection.stream())


# Loop through each document in the collection and update the assigned_data field
for doc in users_collection.stream():
print(doc)
doc_ref = users_collection.document(doc.id)
doc_ref.update({'assigned_data': assigned_data})
print(f"Document {doc.id} updated successfully.")
1 change: 1 addition & 0 deletions app/(auth)/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function SignUp() {
// hardcoded "player" role for now, add role selection to profile settings in future PR
role: "player",
uid: userRef,
assigned_data: [],
});

setCurrentUserId(userCredential.user.uid);
Expand Down
4 changes: 4 additions & 0 deletions app/content/drill/[id]/description.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { useDrillInfo } from "~/hooks/useDrillInfo";

export default function Description() {
const drillId = useLocalSearchParams()["id"];
const assignedTime = useLocalSearchParams()["assignedTime"];

console.log("WAS IT ASSIGNED2", assignedTime);

const [activeIndex, setActiveIndex] = useState(0);
const [modalVisible, setModalVisible] = useState(false);
Expand Down Expand Up @@ -144,6 +147,7 @@ export default function Description() {
<Link
href={{
pathname: `/segments/drill/${drillId}/submission`,
params: { assignedTime: assignedTime },
}}
asChild
>
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 @@ -14,8 +14,9 @@ import { useDrillInfo } from "~/hooks/useDrillInfo";
export default function Index() {
const [value, setValue] = React.useState("description");
const navigation = useNavigation();
const drillId = useLocalSearchParams()["id"];
const { id: drillId, assignedTime: assignedTime } = useLocalSearchParams();

console.log("WAS IT ASSIGNED", assignedTime);
const {
data: drillInfo,
error: drillInfoError,
Expand Down
212 changes: 206 additions & 6 deletions app/content/plan/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,214 @@
import { PaperProvider, Text } from "react-native-paper";
import { router } from "expo-router";
import React, { useEffect, useState } from "react";
import {
RefreshControl,
SectionList,
TouchableOpacity,
View,
} from "react-native";
import { Appbar, List, PaperProvider, Text } from "react-native-paper";
import { SafeAreaView } from "react-native-safe-area-context";

//This is for the list of drills
import Loading from "~/components/loading";
import { currentAuthContext } from "~/context/Auth";
import { useDrillInfo } from "~/hooks/useDrillInfo";
import { useUserInfo } from "~/hooks/useUserInfo";

import { useQueryClient } from "@tanstack/react-query";

import { formatDate } from "../../../Utility";

const DrillList = () => {
const { currentUserId, currentTeamId } = currentAuthContext();

const {
data: drillInfo,
error: drillInfoError,
isLoading: drillInfoIsLoading,
} = useDrillInfo();

const {
data: userInfo,
userError: userInfoError,
userIsLoading: userIsLoading,
} = useUserInfo(currentUserId);

const queryClient = useQueryClient();

const [assignedData, setAssignedData] = useState([]);
const [refreshing, setRefreshing] = React.useState(false);

const onRefresh = React.useCallback(() => {
const refresh = async () => {
setRefreshing(true);
await queryClient.invalidateQueries([
"user",
{ teamId: currentTeamId, userId: currentUserId },
]);
setRefreshing(false);
};
refresh();
}, [currentTeamId, currentUserId, queryClient]);

console.log("USER DATA", userInfo);

// Set the assigned_data state when the user data is loaded
useEffect(() => {
if (!userIsLoading && userInfo && userInfo.assigned_data) {
setAssignedData(userInfo.assigned_data);
}
}, [userIsLoading, userInfo]);

if (userIsLoading || drillInfoIsLoading) {
return <Loading />;
}

const today = formatDate(Date.now() / 1000);
// Group the assigned drills by date
const groupedData = assignedData.reduce((acc, curr) => {
const date = formatDate(curr.assignedTime);
const dateKey = date === today ? "Today" : date;

if (!acc[dateKey]) {
acc[dateKey] = [];
}
if (curr.completed) {
acc[dateKey].push(curr);
} else {
acc[dateKey].unshift(curr);
}

return acc;
}, {});

// Sort the dates in descending order
const sortedDates = Object.keys(groupedData).sort(
(a, b) => new Date(b) - new Date(a),
);

// Render the list of drills
return sortedDates.length === 0 ? (
<Text style={{ fontSize: 30, fontWeight: "bold", textAlign: "center" }}>
No drills assigned
</Text>
) : (
<SectionList
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
}
sections={sortedDates.map((date) => ({
title: date,
data: groupedData[date],
}))}
keyExtractor={(item, index) => `${item.assignedTime}-${item.drillId}`}
renderItem={({ item: assignment }) => (
<TouchableOpacity
key={`${assignment.assignedTime}-${assignment.drillId}`}
disabled={assignment.completed}
onPress={() => {
router.push({
pathname: `content/drill/${assignment.drillId}`,
params: {
id: `${assignment.drillId}`,
assignedTime: assignment.assignedTime,
},
});
}}
>
<View style={{ marginLeft: 20, marginRight: 20 }}>
<View
style={{
borderWidth: 1,
borderColor: "rgba(0,0,0,0.2)",
alignItems: "center",
justifyContent: "space-between",
width: "100%",
height: 65,
backgroundColor: `${!assignment.completed ? "#fff" : "#89E894"}`,
borderRadius: 20,
marginBottom: 10,
paddingLeft: 30,
paddingRight: 30,
paddingTop: 5,
paddingBottom: 5,
}}
>
<Text style={{ fontSize: 20 }}>
{drillInfo[assignment.drillId]["prettyDrillType"]}
</Text>
<Text style={{ fontSize: 17, fontStyle: "italic" }}>
{drillInfo[assignment.drillId]["subType"]}
</Text>
</View>
</View>
</TouchableOpacity>
)}
renderSectionHeader={({ section: { title } }) => (
<Text
style={{
fontSize: 25,
fontWeight: "bold",
textAlign: "center",
marginTop: 10,
}}
>
{title}
</Text>
)}
stickySectionHeadersEnabled={false}
/>
);
};

/*
const convertTimestampToDate = (timestamp) => {
const date = new Date(timestamp * 1000);
FrankreedX marked this conversation as resolved.
Show resolved Hide resolved
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
};
*/
const CoachView = () => {
const {
data: drillInfo,
error: drillInfoError,
isLoading: drillInfoIsLoading,
} = useDrillInfo();

const [expanded, setExpanded] = React.useState(true);

const handlePress = () => setExpanded(!expanded);
if (drillInfoIsLoading) {
return <Loading />;
}
return (
<List.Section>
<List.Accordion
title="Select Drills"
left={(props) => <List.Icon {...props} icon="folder" />}
>
{drillInfo &&
Object.values(drillInfo).map((drill) => (
<List.Item title={drill.drillType} />
))}
</List.Accordion>
</List.Section>
);
};

export default function Index() {
const { data: userInfo, userIsLoading, userError } = useUserInfo();

console.log("USER INFO IN PLAN BEGGINING", userInfo);
return (
<PaperProvider>
<SafeAreaView
style={{ flex: 1, justifyContent: "center", alignItems: "center" }}
>
<Text>Plan Index</Text>
<SafeAreaView style={{ flex: 1 }} edges={["right", "top", "left"]}>
<Appbar.Header statusBarHeight={0} style={{ backgroundColor: "FFF" }}>
<Appbar.Content title={"Assigned Drills"} titleStyle={{}} />
</Appbar.Header>

<DrillList />
</SafeAreaView>
</PaperProvider>
);
Expand Down
2 changes: 1 addition & 1 deletion app/segments/drill/[id]/submission/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Result from "./result";
import { useDrillInfo } from "~/hooks/useDrillInfo";

export default function Index() {
const { id } = useLocalSearchParams();
const { id, assignedTime } = useLocalSearchParams();

const [outputData, setOutputData] = useState([]);
const [toggleResult, setToggleResult] = useState(false);
Expand Down
Loading
Loading