diff --git a/houston/src/pages/Report.tsx b/houston/src/pages/Report.tsx index 0556df9..97c15e9 100644 --- a/houston/src/pages/Report.tsx +++ b/houston/src/pages/Report.tsx @@ -6,7 +6,7 @@ import L from 'leaflet'; import Button from '@mui/material-next/Button'; import { red, blue, green, yellow, purple, grey } from '@mui/material/colors'; import { post_targets, pull_targets } from "../utilities/pull_targets.ts"; -import { MatchedTarget, IdentifiedTarget, Bottle, ODLCColor, ODLCShape, GPSCoord, oDLCShapeToJSON, oDLCColorToJSON, BottleDropIndex, bottleDropIndexToJSON } from '../protos/obc.pb'; +import { MatchedTarget, IdentifiedTarget, Bottle, ODLCColor, ODLCShape, GPSCoord, oDLCShapeToJSON, oDLCColorToJSON, BottleDropIndex } from '../protos/obc.pb'; type UpdateItemFunction = () => void; @@ -41,26 +41,64 @@ function Image({item, matchedItems, updateMatched}: ImageProps) { if (value !== null) { bottleIndex = value; } + + console.log('start bottleIndex', bottleIndex); const tempMatched = matchedItems; + console.log('start tempMatched', tempMatched) + const removeItemIndex = matchedItems.findIndex((itemX) => itemX.Target?.id === item.id); - const updateTargetIndex = matchedItems.findIndex((itemX) => itemX.Bottle?.Index ? bottleDropIndexToJSON(itemX.Bottle.Index) === bottleIndex : null); + console.log('start removeItemIndex', removeItemIndex) + + const updateTargetIndex = matchedItems.findIndex((itemX) => { + if (itemX.Bottle === undefined) { + return false; + } + + console.log("itemX", itemX.Bottle.Index); - if (updateTargetIndex != removeItemIndex) { - console.log("updateTargetIndex", updateTargetIndex); - console.log("tempMatched2", tempMatched); - const temp = tempMatched[updateTargetIndex].Target; - tempMatched[updateTargetIndex].Target = item; + // hack because for some reason the indices are being sent as letters as they are in the enum + // instead of the 1-5 values - // console.log("tempMatched1", tempMatched[removeItemIndex].Target); - console.log("tempMatched", tempMatched[updateTargetIndex]); - if (removeItemIndex !== -1){ - tempMatched[removeItemIndex].Target = temp; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return ((itemX.Bottle.Index as any) == bottleIndex); + }); + + console.log('start updateTargetIndex', updateTargetIndex); + + // this mess is so bad but at every point it made sense to add a tiny little hack + // so it would just work + if (updateTargetIndex == -1) { + if (bottleIndex >= 'A' && bottleIndex <= 'F') { + const target = { + "Bottle": { + "Index": bottleIndex + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any; // love typescript + tempMatched.push(target as MatchedTarget); + } else { + alert("cannot find a bottle with that index"); + return; + } + } else { + if (updateTargetIndex != removeItemIndex) { + console.log("updateTargetIndex", updateTargetIndex); + console.log("tempMatched2", tempMatched); + const temp = tempMatched[updateTargetIndex].Target; + tempMatched[updateTargetIndex].Target = item; + + // console.log("tempMatched1", tempMatched[removeItemIndex].Target); + console.log("tempMatched", tempMatched[updateTargetIndex]); + if (removeItemIndex !== -1){ + tempMatched[removeItemIndex].Target = temp; + } } } + const res = await post_targets(tempMatched); if (res) { diff --git a/houston/src/utilities/pull_targets.ts b/houston/src/utilities/pull_targets.ts index 5148b46..364529f 100644 --- a/houston/src/utilities/pull_targets.ts +++ b/houston/src/utilities/pull_targets.ts @@ -1,4 +1,4 @@ -import { BottleDropIndex, IdentifiedTarget, ManualTargetMatch, MatchedTarget } from '../protos/obc.pb'; +import { IdentifiedTarget, ManualTargetMatch, MatchedTarget } from '../protos/obc.pb'; /** * @@ -54,20 +54,22 @@ export async function post_targets(targets: MatchedTarget[]) { }; targets.forEach((target) => { - switch (target.Bottle?.Index) { - case BottleDropIndex.A: + // eslint-disable-next-line @typescript-eslint/no-explicit-any + switch (target.Bottle?.Index as any) { + // hack because these are strings instead of num values for some reason + case "A": matchings.bottleAId = target.Target?.id || -1; break; - case BottleDropIndex.B: + case "B": matchings.bottleBId = target.Target?.id || -1; break; - case BottleDropIndex.C: + case "C": matchings.bottleCId = target.Target?.id || -1; break; - case BottleDropIndex.D: + case "D": matchings.bottleDId = target.Target?.id || -1; break; - case BottleDropIndex.E: + case "E": matchings.bottleEId = target.Target?.id || -1; break; default: @@ -75,6 +77,16 @@ export async function post_targets(targets: MatchedTarget[]) { } }); + // -1 value gets set to 0 because 0 is the null value, but 0 is a real value we want to + // send, so we artificially increment by 1. + // that way when the OBC sees 1 it knows it is actually referring to target 0, and if it + // sees 0 then it knows that it was referring to a target you aren't rematching + matchings.bottleAId++; + matchings.bottleBId++; + matchings.bottleCId++; + matchings.bottleDId++; + matchings.bottleEId++; + const data = await fetch('/api/targets/matched', { method: 'POST', headers: {