Skip to content

Commit

Permalink
feat: added loading text (#2132)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shriya-Chauhan authored Dec 2, 2024
1 parent 12ea332 commit b7f45a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
11 changes: 9 additions & 2 deletions modelina-website/src/components/contexts/PlaygroundContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ interface PlaygroundContextProps {
setHasLoadedQuery: Dispatch<SetStateAction<boolean>>;
renderModels: React.ReactNode | null;
setRenderModels: (models: React.ReactNode) => void;
outputLoading: boolean;
setOutputLoading: Dispatch<SetStateAction<boolean>>;
}

const PlaygroundContext = createContext<PlaygroundContextProps | undefined>(undefined);
Expand Down Expand Up @@ -104,6 +106,7 @@ export const PlaygroundContextProvider: React.FC<{
const [isLoaded, setIsLoaded] = useState(false);
const [hasLoadedQuery, setHasLoadedQuery] = useState(false);
const [renderModels, setRenderModels] = React.useState<React.ReactNode | null>(null);
const [outputLoading, setOutputLoading] = useState(true);

const contextValue = useMemo(
() => ({
Expand All @@ -130,7 +133,9 @@ export const PlaygroundContextProvider: React.FC<{
hasLoadedQuery,
setHasLoadedQuery,
renderModels,
setRenderModels
setRenderModels,
outputLoading,
setOutputLoading
}),
[
config,
Expand All @@ -156,7 +161,9 @@ export const PlaygroundContextProvider: React.FC<{
hasLoadedQuery,
setHasLoadedQuery,
renderModels,
setRenderModels
setRenderModels,
outputLoading,
setOutputLoading
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const GeneratedModelsComponent: React.FC<GeneratedModelsComponentProps> = ({ sho
const context = useContext(PlaygroundGeneratedContext);
const [selectedModel, setSelectedModel] = useState<string>('');
const { setRenderModels, generatorCode, showGeneratorCode, setShowGeneratorCode } = usePlaygroundContext();
const { outputLoading } = usePlaygroundContext();

const toShow = () => {
let selectedCode = '';
Expand Down Expand Up @@ -90,11 +91,17 @@ const GeneratedModelsComponent: React.FC<GeneratedModelsComponentProps> = ({ sho
return (
<div className='h-full'>
<div className='col-span-2 h-full rounded-b bg-code-editor-dark font-bold text-white shadow-lg'>
<MonacoEditorWrapper
{
outputLoading ?
<div className = 'loading-text'>
<div>Loading...</div>
</div> :
<MonacoEditorWrapper
options={{ readOnly: true }}
language={context?.language}
value={showGeneratorCode ? generatorCode : selectedCode}
/>
}
</div>
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion modelina-website/src/components/playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const Playground: React.FC<ModelinaPlaygroundProps> = (props) => {
isLoaded,
setIsLoaded,
hasLoadedQuery,
setHasLoadedQuery
setHasLoadedQuery,
outputLoading,
setOutputLoading
} = usePlaygroundContext();

// To avoid hydration error
Expand All @@ -53,6 +55,8 @@ const Playground: React.FC<ModelinaPlaygroundProps> = (props) => {
* Tell the socket io server that we want some code
*/
const generateNewCode = (inputArgs: string) => {
setOutputLoading(true);

try {
const message: GenerateMessage = {
...config,
Expand Down Expand Up @@ -102,6 +106,7 @@ const Playground: React.FC<ModelinaPlaygroundProps> = (props) => {
setError(false);
setStatusCode(200);
setErrorMessage('');
setOutputLoading(false);
})
.catch((error) => {
console.error(error);
Expand Down
10 changes: 10 additions & 0 deletions modelina-website/src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ abbr[title] {
scroll-margin-top: 155px;
}
}

.loading-text {
position: relative;
width: 100%;
height: 100%;
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}

0 comments on commit b7f45a6

Please sign in to comment.