Skip to content

Commit 7268786

Browse files
committed
refactor(drinks-machine): modularize backend and fix 20ml calibration
1 parent 7d632a0 commit 7268786

File tree

14 files changed

+799
-807
lines changed

14 files changed

+799
-807
lines changed

client/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const App: React.FC = () => {
2222
<Route path="/" element={<CarPage />} />
2323
<Route path="/irrigation" element={<Irrigation />} />
2424
<Route path="/drinks" element={<DrinksPage />} />
25-
<Route path="/drinks/:tabRouter" element={<DrinksPage />} />
25+
<Route path="/drinks/:tabId" element={<DrinksPage />} />
2626
<Route path="*" element={<Irrigation />} />
2727
</Routes>
2828
</main>

client/src/pages/car/hooks/use-robot-dashboard.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import { IDashboardState, IRobotSendStatus } from '../models/model';
33
import { useRemoteControl } from '@/context/remote-control-context';
44
import { ROBOT_CONFIG } from '../config/robot-config';
55

6+
// Incoming data from WebSocket might have different keys than our internal model
7+
interface RobotTelemetryPayload extends Partial<IRobotSendStatus> {
8+
giroscopeValues?: number[];
9+
giroscope?: string;
10+
}
11+
612
type DashboardAction =
7-
| { type: 'UPDATE_ROBOT_DATA'; payload: Partial<IRobotSendStatus> }
8-
| { type: 'SYNC_REMOTE_DATA'; payload: any }
13+
| { type: 'UPDATE_ROBOT_DATA'; payload: RobotTelemetryPayload }
14+
| { type: 'SYNC_REMOTE_DATA'; payload: any } // Remote data structure is complex, keeping any or could use IRemoteControlReceiveStatus
915
| { type: 'SET_ROBOT_ORIENTATION'; payload: { pitch: number; roll: number } }
1016
| { type: 'TOGGLE_LED_MOCK' };
1117

@@ -30,10 +36,8 @@ const dashboardReducer = (state: IDashboardState, action: DashboardAction): IDas
3036
robot: {
3137
...state.robot,
3238
...action.payload,
33-
// If the payload has giroscopeValues, we map it to robotGyroscopeValues
34-
//@ts-ignore
39+
// Map legacy keys if present
3540
robotGyroscopeValues: action.payload.giroscopeValues ?? action.payload.robotGyroscopeValues ?? state.robot.robotGyroscopeValues,
36-
//@ts-ignore
3741
robotGyroscope: action.payload.giroscope ?? action.payload.robotGyroscope ?? state.robot.robotGyroscope,
3842
}
3943
};
@@ -61,7 +65,7 @@ export const useRobotDashboard = (isMock: boolean) => {
6165
const { remoteState } = useRemoteControl();
6266
const [dashboardState, dispatch] = useReducer(dashboardReducer, initialState);
6367

64-
const updateRobotTelemetry = (data: any) => {
68+
const updateRobotTelemetry = (data: RobotTelemetryPayload) => {
6569
dispatch({ type: 'UPDATE_ROBOT_DATA', payload: data });
6670
};
6771

client/src/pages/drinks/hooks/use-drinks-page.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState, useEffect } from "react";
22
import { ICocktail, TabType } from "@/pages/drinks/models/drinks-model";
33
import { drinksService } from "@/pages/drinks/services/drinks.service";
4+
import { useNavigate, useParams } from "react-router-dom";
45

56
// Sub-hooks
67
import { useCocktails } from "./use-cocktails";
@@ -10,7 +11,19 @@ import { useSocketSync } from "./use-socket-sync";
1011
import { isSimulationMode } from "@/utils/simulation";
1112

1213
export const useDrinksPage = () => {
13-
const [activeTab, setActiveTab] = useState<TabType>("drinks");
14+
const navigate = useNavigate();
15+
const { tabId } = useParams<{ tabId: string }>();
16+
17+
// Map URL param to TabType (defaults to 'drinks')
18+
const getTabFromUrl = (): TabType => {
19+
switch (tabId) {
20+
case 'cocktails-config': return 'config';
21+
case 'pumps-config': return 'manual';
22+
default: return 'drinks';
23+
}
24+
};
25+
26+
const activeTab = getTabFromUrl();
1427
const [selectedCocktailForConfirm, setSelectedCocktailForConfirm] = useState<ICocktail | null>(null);
1528

1629
// Simulation Mode Detection
@@ -65,7 +78,16 @@ export const useDrinksPage = () => {
6578
}, [isMock]);
6679

6780
const handleTabChange = (tab: TabType) => {
68-
setActiveTab(tab);
81+
switch (tab) {
82+
case 'config':
83+
navigate('/drinks/cocktails-config');
84+
break;
85+
case 'manual':
86+
navigate('/drinks/pumps-config');
87+
break;
88+
default:
89+
navigate('/drinks');
90+
}
6991
};
7092

7193
const sendCommand = async (direction: string) => {

client/src/pages/drinks/pages/cocktails-config-tab/cocktails-config-tab-page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const CocktailsConfigTabPage: React.FC<ICocktailsConfigTabPageProps> = ({
7676
<Dialog open={isResetDialogOpen} onClose={() => setIsResetDialogOpen(false)}>
7777
<DialogTitle>{t('drinks.config.resetConfirmTitle')}</DialogTitle>
7878
<DialogContent>
79-
<DialogContentText>
79+
<DialogContentText sx={{ color: "var(--text-main)" }}>
8080
{t('drinks.config.resetConfirmText')}
8181
</DialogContentText>
8282
</DialogContent>

client/src/pages/drinks/pages/pumps-config-tab/components/cards/pump-config-card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const PumpConfigCard: React.FC<PumpConfigCardProps> = ({ bottle, onUpdate
5252
<WaterDropIcon sx={{ color: "var(--accent)" }} />
5353
<Box>
5454
<Typography className="tech-text" sx={{ color: "var(--accent)", fontWeight: 700, fontSize: "0.9rem" }}>
55-
{bottle.title}
55+
{t(`drinks.pumps.${bottle.title.toLowerCase().replace(" ", "_")}`, { defaultValue: bottle.title })}
5656
</Typography>
5757
<Typography sx={{ color: "var(--text-muted)", fontSize: "0.75rem" }}>
5858
{t(`drinks.liquids.${bottle.liquid.toLowerCase()}`, { defaultValue: bottle.liquid })}
@@ -100,7 +100,7 @@ export const PumpConfigCard: React.FC<PumpConfigCardProps> = ({ bottle, onUpdate
100100
<Box>
101101
<Box display="flex" justifyContent="space-between" alignItems="center" mb={1}>
102102
<Typography className="tech-text" sx={{ fontSize: "0.8rem", color: "var(--text-muted)" }}>
103-
{t('drinks.config.time')}
103+
{t('drinks.config.time')} (Sec / 20ml)
104104
</Typography>
105105
<Typography sx={{ color: "var(--accent)", fontWeight: 700 }}>
106106
{time.toFixed(1)}s

0 commit comments

Comments
 (0)