Skip to content

Commit

Permalink
chore: replace daytona-web import source (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: Zoran Zorica <[email protected]>
  • Loading branch information
zzorica authored Sep 30, 2024
1 parent 687a711 commit 5518c8b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from "react";
import { useApi } from "@backstage/core-plugin-api";
import { Box, Button, Card, CardContent, CardHeader, Divider, ListItemText, Typography } from "@material-ui/core";
import DaytonaIcon from "../../assets/DaytonaIcon";
import { daytonaAuthApiRef } from "@daytonaio/daytona-web";
import { daytonaAuthApiRef } from "../../definitions";
import { isError } from '@backstage/errors';

export const AuthCardComponent = () => {
Expand All @@ -14,7 +14,7 @@ export const AuthCardComponent = () => {
await daytonaAuthApi.signIn();
} catch (e) {
setError(isError(e) ? e.message : 'An unspecified error occurred');
}
}
}

return (
Expand All @@ -23,17 +23,17 @@ export const AuthCardComponent = () => {
flexDirection: 'column',
height: 'calc(100% - 10px)', // for pages without content header
marginBottom: '10px',
}}>
<CardHeader
}}>
<CardHeader
title={
<>
<Box display="flex" alignItems="center" marginBottom={2}>
<DaytonaIcon/>
<Box mr={1} width={2}/>
<DaytonaIcon />
<Box mr={1} width={2} />
Daytona Workspaces
</Box>
</Box>
</>
}/>
} />
<Divider />
<CardContent style={{ padding: 0, overflow: 'auto', display: 'block' }}>
<div style={{ display: 'block', textAlign: 'center', padding: '10%' }}>
Expand All @@ -43,17 +43,17 @@ export const AuthCardComponent = () => {
Link your Daytona account to create and manage workspaces.
</span>
</Typography>
<div style={{padding: '3%', }}>
<div style={{ padding: '3%', }}>
<Button variant="contained" color="primary" onClick={handleAuthenticate}>
Authenticate
Authenticate
</Button>
<ListItemText
primary={error && <Typography color="error">{error}</Typography>}
/>
</div>
</div>

</CardContent>
</Card>
);
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import React, { useEffect, useState } from "react";
import { useApi, SessionState } from "@backstage/core-plugin-api";
import { AuthCardComponent } from "../AuthCardComponent/AuthCardComponent";
import { daytonaAuthApiRef } from "@daytonaio/daytona-web";
import { daytonaAuthApiRef } from "../../definitions";
import { WorkspaceListComponent } from "./WorkspaceListComponent";

export const WorkspaceListCard = () => {
const daytonaAuthApi = useApi(daytonaAuthApiRef);
const [isLoggedIn, setIsLoggedIn] = useState(() => {
// Initialize state based on session storage
return window.sessionStorage.getItem('isDaytonaSignedIn') === 'true';
const daytonaAuthApi = useApi(daytonaAuthApiRef);
const [isLoggedIn, setIsLoggedIn] = useState(() => {
// Initialize state based on session storage
return window.sessionStorage.getItem('isDaytonaSignedIn') === 'true';
});
// window.sessionStorage.setItem('isDaytonaSignedIn', 'false');
// const isDaytonaSignedIn = window.sessionStorage.getItem('isDaytonaSignedIn') == 'true';

useEffect(() => {
const authSubscription = daytonaAuthApi.sessionState$().subscribe(state => {
console.log('isDaytonaSignedIn inside useEffect', state);
if (state === SessionState.SignedIn) {
setIsLoggedIn(true);
window.sessionStorage.setItem('isDaytonaSignedIn', 'true');
console.log('isDaytonaSignedIn inside if-block', window.sessionStorage.getItem('isDaytonaSignedIn') == 'true');
} else {
setIsLoggedIn(false);
window.sessionStorage.setItem('isDaytonaSignedIn', 'false');
}
});
// window.sessionStorage.setItem('isDaytonaSignedIn', 'false');
// const isDaytonaSignedIn = window.sessionStorage.getItem('isDaytonaSignedIn') == 'true';
return () => {
authSubscription.unsubscribe();
};
}, [daytonaAuthApi]);

useEffect(() => {
const authSubscription = daytonaAuthApi.sessionState$().subscribe(state => {
console.log('isDaytonaSignedIn inside useEffect', state);
if (state === SessionState.SignedIn) {
setIsLoggedIn(true);
window.sessionStorage.setItem('isDaytonaSignedIn', 'true');
console.log('isDaytonaSignedIn inside if-block', window.sessionStorage.getItem('isDaytonaSignedIn') == 'true');
} else {
setIsLoggedIn(false);
window.sessionStorage.setItem('isDaytonaSignedIn', 'false');
}
});
return () => {
authSubscription.unsubscribe();
};
}, [daytonaAuthApi]);
// const isDaytonaSignedIn = window.sessionStorage.getItem('isDaytonaSignedIn') == 'true';
console.log('isDaytonaSignedIn after useEffect', window.sessionStorage.getItem('isDaytonaSignedIn') == 'true');

// const isDaytonaSignedIn = window.sessionStorage.getItem('isDaytonaSignedIn') == 'true';
console.log('isDaytonaSignedIn after useEffect', window.sessionStorage.getItem('isDaytonaSignedIn') == 'true');

return (
<>
return (
<>
{isLoggedIn ? <WorkspaceListComponent /> : <AuthCardComponent />}
</>
);
}
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import React, { useEffect, useState } from "react";
import { useApi, SessionState } from "@backstage/core-plugin-api";
import { AuthCardComponent } from "../AuthCardComponent";
import { daytonaAuthApiRef } from "@daytonaio/daytona-web";
import { daytonaAuthApiRef } from "../../definitions";
import { WorkspaceOverviewContent } from "./WorkspaceOverviewContent";

export const WorkspaceOverviewCard = () => {
const daytonaAuthApi = useApi(daytonaAuthApiRef);
const [isLoggedIn, setIsLoggedIn] = useState(() => {
// Initialize state based on session storage
return window.sessionStorage.getItem('isDaytonaSignedIn') === 'true';
const daytonaAuthApi = useApi(daytonaAuthApiRef);
const [isLoggedIn, setIsLoggedIn] = useState(() => {
// Initialize state based on session storage
return window.sessionStorage.getItem('isDaytonaSignedIn') === 'true';
});

useEffect(() => {
const authSubscription = daytonaAuthApi.sessionState$().subscribe(state => {
if (state === SessionState.SignedIn) {
setIsLoggedIn(true);
window.sessionStorage.setItem('isDaytonaSignedIn', 'true');
} else {
setIsLoggedIn(false);
}
});
return () => {
authSubscription.unsubscribe();
};
}, [daytonaAuthApi]);

useEffect(() => {
const authSubscription = daytonaAuthApi.sessionState$().subscribe(state => {
if (state === SessionState.SignedIn) {
setIsLoggedIn(true);
window.sessionStorage.setItem('isDaytonaSignedIn', 'true');
} else {
setIsLoggedIn(false);
}
});
return () => {
authSubscription.unsubscribe();
};
}, [daytonaAuthApi]);

return (
<>
return (
<>
{isLoggedIn ? <WorkspaceOverviewContent /> : <AuthCardComponent />}
</>
);
}
</>
);
}
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4995,12 +4995,6 @@
pkginfo "^0.4.1"
uid2 "^1.0.0"

"@daytonaio/daytona-web@link:plugins/daytona-web":
version "0.1.3"
dependencies:
"@backstage/core-app-api" "^1.13.0"
"@backstage/core-plugin-api" "^1.9.3"

"@emotion/babel-plugin@^11.11.0":
version "11.11.0"
resolved "https://registry.yarnpkg.com/@emotion/babel-plugin/-/babel-plugin-11.11.0.tgz#c2d872b6a7767a9d176d007f5b31f7d504bb5d6c"
Expand Down Expand Up @@ -10900,7 +10894,6 @@ apg-lite@^1.0.3:
"@backstage/plugin-user-settings" "^0.8.6"
"@backstage/theme" "^0.5.4"
"@daytonaio/backstage-plugin-daytona" "^0.2.0"
"@daytonaio/daytona-web" "^0.1.0"
"@material-ui/core" "^4.12.2"
"@material-ui/icons" "^4.9.1"
history "^5.0.0"
Expand Down Expand Up @@ -25927,4 +25920,4 @@ zod@^3.22.4:
zwitch@^2.0.0:
version "2.0.4"
resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-2.0.4.tgz#c827d4b0acb76fc3e685a4c6ec2902d51070e9d7"
integrity sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==
integrity sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==

0 comments on commit 5518c8b

Please sign in to comment.