[go: nahoru, domu]

Skip to content

Commit

Permalink
form based 👍
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatXliner committed Feb 28, 2024
1 parent cd39fb6 commit b307a3a
Showing 1 changed file with 94 additions and 83 deletions.
177 changes: 94 additions & 83 deletions apps/WarriorHappy/src/app/match/[matchId].tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useState } from "react";
import { Text, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { useLocalSearchParams } from "expo-router";
import { router, useLocalSearchParams } from "expo-router";
import {
Button,
H5,
Expand Down Expand Up @@ -31,26 +31,23 @@ export default function Match() {
};
console.log("sdakkkk", key);
const utils = api.useUtils();
// staletime infinity = fetch once
const { data, isLoading, isError } = api.scouting.getMatchLog.useQuery(key, {
networkMode: "offlineFirst",
staleTime: Infinity,
});
const rawUpdate = api.scouting.updateMatchLog.useMutation({
networkMode: "offlineFirst",
onSuccess: (data, variables, context) => {
console.log("data", data, variables, context);

utils.scouting.getMatchLog.setData(key, [
{
event_log: variables.eventLog,
},
]);
router.push("/");
// utils.scouting.getMatchLog.invalidateQuery();
},
// onError: (error, variables, context) => {
// An error happened!
// console.log(`rolling back optimistic update with id ${context.id}`);
// },
onMutate: (x) => console.log("syntaxc", x),
// onMutate: (x) => console.log("syntaxc", x),
});
// const [godlyHistory, setGodlyHistory] = useState<{
// auto: UltimateHistory;
Expand Down Expand Up @@ -95,89 +92,103 @@ export default function Match() {
endgame: UltimateHistory;
} | null;
const ready = !isLoading && godlyHistory != null;
const [localEventLog, setLocalEventLog] = useState(
// wont ever be used if it was null
godlyHistory as {
auto: UltimateHistory;
teleop: UltimateHistory;
endgame: UltimateHistory;
},
);

const submit = () => {
rawUpdate.mutate({
...key,
eventLog: localEventLog,
});
};
return (
<SafeAreaView className="mt-[-45px] h-full">
{!ready ? (
<Text>Loading...</Text>
) : (
<Tabs defaultValue="tab1" flexDirection="column">
<Tabs.List gap>
<Tabs.Tab value="tab1">
<SizableText>Auto</SizableText>
</Tabs.Tab>
<View>
<Button theme={"yellow"} onPress={submit}>
SUBMIT
</Button>
<Tabs defaultValue="tab1" flexDirection="column">
<Tabs.List gap>
<Tabs.Tab value="tab1">
<SizableText>Auto</SizableText>
</Tabs.Tab>

<Tabs.Tab value="tab2">
<SizableText>Teleop</SizableText>
</Tabs.Tab>
<Tabs.Tab value="tab3">
<SizableText>Endgame</SizableText>
</Tabs.Tab>
</Tabs.List>
<Tabs.Tab value="tab2">
<SizableText>Teleop</SizableText>
</Tabs.Tab>
<Tabs.Tab value="tab3">
<SizableText>Endgame</SizableText>
</Tabs.Tab>
</Tabs.List>

<Tabs.Content value="tab1" height={"100%"} paddingBottom="15%">
<Auto
ultimateHistory={godlyHistory.auto}
setUltimateHistory={(stuff) => {
console.log("stuff", stuff);
rawUpdate.mutate({
...key,
eventLog: { ...godlyHistory, auto: stuff },
});
}}
/>
<Dangerous
ultimateHistory={godlyHistory.auto}
setUltimateHistory={(stuff) => {
console.log("stuff", stuff);
rawUpdate.mutate({
...key,
eventLog: { ...godlyHistory, auto: stuff },
});
}}
/>
</Tabs.Content>
<Tabs.Content value="tab1" height={"100%"} paddingBottom="15%">
<Auto
ultimateHistory={localEventLog.auto}
setUltimateHistory={(stuff) => {
console.log("stuff", stuff);
setLocalEventLog((x) => {
return { ...x, auto: stuff };
});
}}
/>
<Dangerous
ultimateHistory={localEventLog.auto}
setUltimateHistory={(stuff) => {
console.log("stuff", stuff);
setLocalEventLog((x) => {
return { ...x, auto: stuff };
});
}}
/>
</Tabs.Content>

<Tabs.Content value="tab2" height={"100%"} paddingBottom="15%">
<Teleop
ultimateHistory={godlyHistory.teleop}
setUltimateHistory={(stuff) => {
rawUpdate.mutate({
...key,
eventLog: { ...godlyHistory, teleop: stuff },
});
}}
/>
<Dangerous
ultimateHistory={godlyHistory.teleop}
setUltimateHistory={(stuff) => {
rawUpdate.mutate({
...key,
eventLog: { ...godlyHistory, teleop: stuff },
});
}}
/>
</Tabs.Content>
<Tabs.Content value="tab3" height={"100%"} paddingBottom="15%">
<Endgame
ultimateHistory={godlyHistory.endgame}
setUltimateHistory={(stuff) => {
rawUpdate.mutate({
...key,
eventLog: { ...godlyHistory, endgame: stuff },
});
}}
/>
<Dangerous
ultimateHistory={godlyHistory.endgame}
setUltimateHistory={(stuff) => {
rawUpdate.mutate({
...key,
eventLog: { ...godlyHistory, endgame: stuff },
});
}}
/>
</Tabs.Content>
</Tabs>
<Tabs.Content value="tab2" height={"100%"} paddingBottom="15%">
<Teleop
ultimateHistory={localEventLog.teleop}
setUltimateHistory={(stuff) => {
setLocalEventLog((x) => {
return { ...x, teleop: stuff };
});
}}
/>
<Dangerous
ultimateHistory={localEventLog.teleop}
setUltimateHistory={(stuff) => {
setLocalEventLog((x) => {
return { ...x, teleop: stuff };
});
}}
/>
</Tabs.Content>
<Tabs.Content value="tab3" height={"100%"} paddingBottom="15%">
<Endgame
ultimateHistory={localEventLog.endgame}
setUltimateHistory={(stuff) => {
setLocalEventLog((x) => {
return { ...x, endgame: stuff };
});
}}
/>
<Dangerous
ultimateHistory={localEventLog.endgame}
setUltimateHistory={(stuff) => {
setLocalEventLog((x) => {
return { ...x, endgame: stuff };
});
}}
/>
</Tabs.Content>
</Tabs>
</View>
)}
</SafeAreaView>
);
Expand Down

0 comments on commit b307a3a

Please sign in to comment.