Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added loading text #2132

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 8 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,19 +106,22 @@ const Playground: React.FC<ModelinaPlaygroundProps> = (props) => {
setError(false);
setStatusCode(200);
setErrorMessage('');
setOutputLoading(false);
})
.catch((error) => {
console.error(error);
setError(true);
setErrorMessage('Input is not a correct AsyncAPI document, so it cannot be processed.');
setStatusCode(500);
setOutputLoading(true);
devilkiller-ag marked this conversation as resolved.
Show resolved Hide resolved
});
}
} catch (e: any) {
console.error(e);
setError(true);
setErrorMessage('Input is not a correct AsyncAPI document, so it cannot be processed.');
setStatusCode(400);
setOutputLoading(true);
Shriya-Chauhan marked this conversation as resolved.
Show resolved Hide resolved
}
};

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;
}
Loading