Skip to content

Commit

Permalink
fix: render logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-1806 committed Feb 2, 2024
1 parent 59a3290 commit fdba3d7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 29 deletions.
Binary file not shown.
13 changes: 13 additions & 0 deletions models.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"analyzerName": "intellisense-members",
"languageName": "javascript",
"identity": {
"modelId": "1A3F919CD5B7725108B03C349630A1C82B03",
"outputId": "4A84987F2428442A9EC84563BB2BC063",
"modifiedTimeUtc": "2020-09-28T23:11:53.754Z"
},
"filePath": "1A3F919CD5B7725108B03C349630A1C82B03_4A84987F2428442A9EC84563BB2BC063",
"lastAccessTimeUtc": "2024-02-02T19:18:45.490Z"
}
]
65 changes: 37 additions & 28 deletions src/components/Websocket/Websocket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ import {
GameStatus,
Notification,
} from '@codecharacter-2024/client';
import { RendererUtils } from '@codecharacter-2024/renderer';
import { apiConfig } from '../../api/ApiConfig';
import { Stomp } from '@stomp/stompjs';
import { useEffect, useState } from 'react';
import Toast from 'react-hot-toast';
import { getLogAction } from '../../store/rendererLogs/logSlice';
import { useAppDispatch } from '../../store/hooks';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import { BASE_PATH } from '../../config/config';
import { changeSimulationState } from '../../store/DailyChallenge/dailyChallenge';
import {
changeSimulationState,
dailyChallengePageState,
} from '../../store/DailyChallenge/dailyChallenge';

export const Websocket: React.FunctionComponent = () => {
const currentUserapi = new CurrentUserApi(apiConfig);
const dispatch = useAppDispatch();
const [user, setUser] = useState<CurrentUserProfile>();
const pageType = useAppSelector(dailyChallengePageState);

useEffect(() => {
if (!user) return;
Expand All @@ -27,32 +32,36 @@ export const Websocket: React.FunctionComponent = () => {
wsClient.brokerURL = url;
const handleConnect = () => {
wsClient.subscribe(`/updates/${user.id}`, message => {
const game = JSON.parse(message.body) as Game;
switch (game.status) {
case GameStatus.Executing:
Toast.success('Executing now...');
break;
case GameStatus.Executed:
Toast.success('Executed successfully!');
// TODO: find non-hacky way to do this
dispatch(changeSimulationState(true));
dispatch(
getLogAction({
id: game.id,
callback: () => (window.location.href = './#/dashboard'),
}),
);
break;
case GameStatus.ExecuteError:
Toast.error('Execution error!');
dispatch(changeSimulationState(true));
dispatch(
getLogAction({
id: game.id,
callback: () => (window.location.href = './#/dashboard'),
}),
);
break;
if (pageType === 'Tutorials') {
RendererUtils.loadLog(JSON.parse(message.body).log);
} else {
const game = JSON.parse(message.body) as Game;
switch (game.status) {
case GameStatus.Executing:
Toast.success('Executing now...');
break;
case GameStatus.Executed:
Toast.success('Executed successfully!');
// TODO: find non-hacky way to do this
dispatch(changeSimulationState(true));
dispatch(
getLogAction({
id: game.id,
callback: () => (window.location.href = './#/dashboard'),
}),
);
break;
case GameStatus.ExecuteError:
Toast.error('Execution error!');
dispatch(changeSimulationState(true));
dispatch(
getLogAction({
id: game.id,
callback: () => (window.location.href = './#/dashboard'),
}),
);
break;
}
}
message.ack();
});
Expand Down
2 changes: 1 addition & 1 deletion src/store/DailyChallenge/dailyChallenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const dailyChallengeState = (
): DailyChallengeGetRequest => state.dailyChallenge.dailyChallenge;
export const dailyChallengePageState = (
state: RootState,
): 'Dashboard' | 'DailyChallenge' | 'Tutorials' | undefined =>
): 'Dashboard' | 'DailyChallenge' | 'Tutorials' =>
state.dailyChallenge.pageType;
export const dailyChallengeCompletionState = (
state: RootState,
Expand Down

0 comments on commit fdba3d7

Please sign in to comment.