-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(external-apps): list external apps in route and load them 🚀
- Loading branch information
1 parent
b54889e
commit 929a139
Showing
11 changed files
with
247 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; | ||
import api from "utils/api"; | ||
import { IApp } from "./interface"; | ||
|
||
interface IAppManagerState { | ||
apps: IApp[]; | ||
loading: boolean; | ||
error?: any; | ||
} | ||
|
||
const initialState: IAppManagerState = { apps: [], loading: true }; | ||
|
||
const getAppsAsync = createAsyncThunk( | ||
"appManager/getAppsAsync", | ||
(_, thunkAPI) => { | ||
return api | ||
.get("/manager/apps/") | ||
.then(({ data }) => data) | ||
.catch((e) => { | ||
thunkAPI.rejectWithValue(e); | ||
}); | ||
} | ||
); | ||
|
||
const authSlice = createSlice({ | ||
name: "appManager", | ||
initialState, | ||
reducers: { | ||
getApps: () => {}, | ||
}, | ||
extraReducers: { | ||
// Add reducers for additional action types here, and handle loading state as needed | ||
[getAppsAsync.fulfilled.type]: (state, action) => { | ||
state.apps.push(action.payload); | ||
state.loading = false; | ||
}, | ||
[getAppsAsync.rejected.type]: (state, action) => { | ||
state.loading = false; | ||
state.error = action.error; | ||
}, | ||
}, | ||
}); | ||
|
||
export const {} = authSlice.actions; | ||
export { getAppsAsync }; | ||
export default authSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as React from "react"; | ||
import AppShell from "apps/shell"; | ||
import styled from "styled-components"; | ||
|
||
import useAnimationEndRender from "utils/hooks/useAnimationEndRender"; | ||
import useScript from "utils/hooks/useScript"; | ||
import If from "atoms/If"; | ||
import Loader from "./loader"; | ||
|
||
const Wrapper = styled.div` | ||
height: 100%; | ||
width: 100%; | ||
overflow: auto; | ||
background: ${({ theme }) => theme.colors.plain}; | ||
`; | ||
|
||
interface IProps { | ||
instanceId: string; | ||
appName: string; | ||
onMouseDown: (event: React.MouseEvent, dragId: string) => void; | ||
dragId: string; | ||
data: Record<string, any>; | ||
} | ||
|
||
const ExternalAppShell = ({ | ||
appName, | ||
instanceId, | ||
onMouseDown, | ||
dragId, | ||
data, | ||
}: IProps) => { | ||
const { render } = useAnimationEndRender({ instanceId }); | ||
const status = useScript( | ||
`http://localhost:8000/api/manager/assests/${data.appId}/main.js`, | ||
true | ||
); | ||
console.log(data.options); | ||
return ( | ||
<AppShell | ||
height={data.options.height} | ||
width={data.options.width} | ||
dragId={dragId} | ||
onMouseDown={onMouseDown} | ||
appName={appName} | ||
instanceId={instanceId} | ||
icon={data.icon} | ||
name={data.name} | ||
> | ||
<If condition={render > 0}> | ||
<If condition={status !== "ready"}> | ||
<Loader status={status} /> | ||
</If> | ||
{/* keep it always ready */} | ||
<Wrapper hidden={status !== "ready"} id={data.appId}></Wrapper> | ||
</If> | ||
</AppShell> | ||
); | ||
}; | ||
|
||
export default React.memo(ExternalAppShell); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as React from "react"; | ||
import styled from "styled-components"; | ||
import { ProgressIndicator } from "@fluentui/react"; | ||
|
||
import { Stack, Text, StackItem } from "atoms/styled"; | ||
import { StatusTypes } from "utils/hooks/useScript"; | ||
|
||
interface IProps { | ||
status: StatusTypes; | ||
} | ||
|
||
const Wrapper = styled(Stack)` | ||
background: ${({ theme }) => theme.colors.plain}; | ||
${StackItem} { | ||
width: 320px; | ||
} | ||
`; | ||
|
||
const ScriptStatus = ({ status }: IProps) => { | ||
return ( | ||
<Wrapper | ||
flexDirection="column" | ||
gap={8} | ||
fullHeight | ||
justifyContent="center" | ||
alignItems="center" | ||
> | ||
<StackItem> | ||
<ProgressIndicator | ||
label="Loading app..." | ||
progressHidden={status === "error"} | ||
/> | ||
</StackItem> | ||
<StackItem> | ||
{status === "error" && ( | ||
<Text>Something went wrong while loading the app.</Text> | ||
)} | ||
</StackItem> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default ScriptStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.