Skip to content

Commit

Permalink
refactor(robot-context and cookie-setter): 🎉 update cookie logic and …
Browse files Browse the repository at this point in the history
…robot context
  • Loading branch information
gokhangunduz committed Aug 11, 2023
1 parent d603215 commit 31f6a26
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ui",
"version": "0.11.2",
"version": "0.11.3",
"private": true,
"dependencies": {
"@emotion/css": "^11.10.6",
Expand Down
2 changes: 2 additions & 0 deletions src/components/HiddenVDIFrame/HiddenVDIFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function HiddenVDIFrame(): ReactElement {
allow="clipboard-read"
className="absolute -top-[9999px]"
src={responseRobot?.ideIngressEndpoint}
onLoad={() => console.log("IDE LOADED")}
/>
)}
{responseRobot?.vdiIngressEndpoint && (
Expand All @@ -36,6 +37,7 @@ export default function HiddenVDIFrame(): ReactElement {
responseRobot?.vdiIngressEndpoint?.replace("wss://", "https://") +
"health"
}
onLoad={() => console.log("VDI LOADED")}
/>
)}
</Fragment>
Expand Down
20 changes: 20 additions & 0 deletions src/contexts/RobotContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,25 @@ export default ({ children }: any) => {
);
}

function handleForceUpdate(
page:
| "Overview"
| "Teleoperation"
| "Task Management"
| "Visualization"
| "Loading"
| "Settings"
| "Remote Desktop"
| "Development Suite"
| "Code Editor"
) {
setActiveTab("Loading");

setTimeout(() => {
setActiveTab(page);
}, 500);
}

return (
<RobotContext.Provider
value={{
Expand All @@ -233,6 +252,7 @@ export default ({ children }: any) => {
setTopicList,
isSettedCookie,
setIsSettedCookie,
handleForceUpdate,
}}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useRobot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface IuseRobot {
setTopicList: any;
isSettedCookie: boolean | null;
setIsSettedCookie: any;
handleForceUpdate: any;
}

const useRobot = () => {
Expand Down
22 changes: 1 addition & 21 deletions src/pages/RobotPage/RobotPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,6 @@ export default function RobotPage(): ReactElement {
setActiveTab(tab);
}

function handleForceUpdate(
page:
| "Overview"
| "Teleoperation"
| "Task Management"
| "Visualization"
| "Loading"
| "Settings"
| "Remote Desktop"
| "Development Suite"
| "Code Editor"
) {
setActiveTab("Loading");

setTimeout(() => {
setActiveTab(page);
}, 500);
}

return (
<div className="grid grid-cols-1 gap-6">
<div className="col-span-full">
Expand Down Expand Up @@ -72,14 +53,13 @@ export default function RobotPage(): ReactElement {
</TaskManagementContext>
);
case "Visualization":
return <Visualization handleForceUpdate={handleForceUpdate} />;
return <Visualization />;
case "Teleoperation":
return (
<Teleoperation
vdiIngressEndpoint={
urls?.vdi || responseRobot?.vdiIngressEndpoint
}
handleForceUpdate={handleForceUpdate}
/>
);
case "Development Suite":
Expand Down
4 changes: 1 addition & 3 deletions src/pages/RobotPage/Teleoperation/Teleoperation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ import useRobot from "../../../hooks/useRobot";

interface ITeleoperation {
vdiIngressEndpoint: string;
handleForceUpdate: (page: IrobotPages["activeTab"]) => void;
}

export default function Teleoperation({
vdiIngressEndpoint,
handleForceUpdate,
}: ITeleoperation): ReactElement {
const [grid, setGrid] = useState<any>();
const url = useParams();
Expand All @@ -36,7 +34,7 @@ export default function Teleoperation({
const [selectableTopic, setSelectableTopic] = useState<any>([]);
const [selectedTopic, setSelectedTopic] = useState<string>("");
const handleFullScreen = useFullScreenHandle();
const { ros, topicList } = useRobot();
const { ros, topicList, handleForceUpdate } = useRobot();

// GRID
useEffect(() => {
Expand Down
10 changes: 2 additions & 8 deletions src/pages/RobotPage/Visualization/Visualization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ import { GridStack } from "gridstack";
import ROSLIB from "roslib";
import useRobot from "../../../hooks/useRobot";

interface IVisualization {
handleForceUpdate: (page: IrobotPages["activeTab"]) => void;
}

export default function Visualization({
handleForceUpdate,
}: IVisualization): ReactElement {
export default function Visualization(): ReactElement {
const [grid, setGrid] = useState<any>();
const url = useParams();
const localStoragePath = `visualization_${url?.organizationName}_${url.roboticsCloudName}_${url.instanceName}_${url.fleetName}_${url.robotName}`;
const gridLayout =
JSON.parse(localStorage.getItem(localStoragePath) || JSON.stringify([])) ||
[];

const { ros, topicList } = useRobot();
const { ros, topicList, handleForceUpdate } = useRobot();

useEffect(() => {
const grid: any = GridStack.init({
Expand Down

0 comments on commit 31f6a26

Please sign in to comment.