Skip to content

Commit b05cc8d

Browse files
authored
Merge branch 'master' into leaderboard
2 parents 2d0b960 + 8fa0650 commit b05cc8d

File tree

9 files changed

+289
-285
lines changed

9 files changed

+289
-285
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
"@types/xml2js": "^0.4.11",
136136
"babel-jest": "^29.7.0",
137137
"buffer": "^6.0.3",
138-
"canvas": "^2.11.2",
138+
"canvas": "^3.1.0",
139139
"constants-browserify": "^1.0.0",
140140
"coveralls": "^3.1.1",
141141
"cross-env": "^7.0.3",
@@ -162,7 +162,7 @@
162162
"stream-browserify": "^3.0.0",
163163
"stream-http": "^3.2.0",
164164
"timers-browserify": "^2.0.12",
165-
"typescript": "^5.5.3",
165+
"typescript": "^5.8.2",
166166
"typescript-eslint": "^8.1.0",
167167
"url": "^0.11.1",
168168
"webpack-bundle-analyzer": "^4.9.0"

src/features/game/dialogue/GameDialogueGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class DialogueGenerator {
1414
*/
1515
public constructor(dialogueContent: DialogueObject) {
1616
this.dialogueContent = dialogueContent;
17-
this.currPart = dialogueContent.keys().next().value;
17+
this.currPart = dialogueContent.keys().next().value || '';
1818
this.currLineNum = 0;
1919
}
2020

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Card, Classes, Elevation, NonIdealState, Spinner, SpinnerSize } from '@blueprintjs/core';
2+
import classNames from 'classnames';
3+
import React, { useEffect } from 'react';
4+
import { useTranslation } from 'react-i18next';
5+
import { useDispatch } from 'react-redux';
6+
import { useLocation, useNavigate } from 'react-router';
7+
import SessionActions from 'src/commons/application/actions/SessionActions';
8+
import { parseQuery } from 'src/commons/utils/QueryHelper';
9+
import classes from 'src/styles/Login.module.scss';
10+
11+
const LoginVscodeCallback: React.FC = () => {
12+
const navigate = useNavigate();
13+
const dispatch = useDispatch();
14+
const location = useLocation();
15+
const { t } = useTranslation('login');
16+
17+
const { access_token: accessToken, refresh_token: refreshToken } = parseQuery(location.search);
18+
19+
useEffect(() => {
20+
if (accessToken && refreshToken) {
21+
dispatch(
22+
SessionActions.setTokens({
23+
accessToken: accessToken,
24+
refreshToken: refreshToken
25+
})
26+
);
27+
dispatch(SessionActions.fetchUserAndCourse());
28+
navigate('/welcome');
29+
}
30+
// eslint-disable-next-line react-hooks/exhaustive-deps
31+
}, []);
32+
33+
return (
34+
<div className={classNames(classes['Login'], Classes.DARK)}>
35+
<Card elevation={Elevation.FOUR}>
36+
<div>
37+
<NonIdealState
38+
description={t('Logging In')}
39+
icon={<Spinner size={SpinnerSize.LARGE} />}
40+
/>
41+
</div>
42+
</Card>
43+
</div>
44+
);
45+
};
46+
47+
// react-router lazy loading
48+
// https://reactrouter.com/en/main/route/lazy
49+
export const Component = LoginVscodeCallback;
50+
Component.displayName = 'LoginVscodeCallback';
51+
52+
export default LoginVscodeCallback;

src/pages/sicp/subcomponents/chatbot/ChatBox.tsx

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
3232
const [chatId, setChatId] = useState<string>();
3333
const [messages, setMessages] = useState<ChatMessage[]>([INITIAL_MESSAGE]);
3434
const [userInput, setUserInput] = useState('');
35+
const [maxContentSize, setMaxContentSize] = useState(1000);
3536
const tokens = useTokens();
3637

3738
const handleUserInput = (event: React.ChangeEvent<HTMLInputElement>) => {
@@ -56,7 +57,7 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
5657
.finally(() => {
5758
setIsLoading(false);
5859
});
59-
}, [chatId, tokens, userInput]);
60+
}, [chatId, tokens, userInput, maxContentSize]);
6061

6162
const keyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(
6263
e => {
@@ -71,8 +72,11 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
7172
initChat(tokens, getSection(), getText()).then(resp => {
7273
const message = resp.response;
7374
const conversationId = resp.conversationId;
75+
const maxMessageSize = resp.maxContentSize;
7476
setMessages([message]);
77+
setMaxContentSize(maxMessageSize);
7578
setChatId(conversationId);
79+
setUserInput('');
7680
});
7781
}, [getSection, getText, tokens]);
7882

@@ -100,22 +104,29 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
100104
))}
101105
{isLoading && <p>loading...</p>}
102106
</div>
103-
<input
104-
type="text"
105-
disabled={isLoading}
106-
className={classes['user-input']}
107-
placeholder={isLoading ? 'Waiting for response...' : 'Type your message here...'}
108-
value={userInput}
109-
onChange={handleUserInput}
110-
onKeyDown={keyDown}
111-
/>
112-
<div className={classes['button-container']}>
113-
<Button disabled={isLoading} className={classes['button-send']} onClick={sendMessage}>
114-
Send
115-
</Button>
116-
<Button className={classes['button-clean']} onClick={resetChat}>
117-
Clean
118-
</Button>
107+
<div className={classes['control-container']}>
108+
<input
109+
type="text"
110+
disabled={isLoading}
111+
className={classes['user-input']}
112+
placeholder={isLoading ? 'Waiting for response...' : 'Type your message here...'}
113+
value={userInput}
114+
onChange={handleUserInput}
115+
onKeyDown={keyDown}
116+
maxLength={maxContentSize}
117+
/>
118+
<div className={classes['input-count-container']}>
119+
<div className={classes['input-count']}>{`${userInput.length}/${maxContentSize}`}</div>
120+
</div>
121+
122+
<div className={classes['button-container']}>
123+
<Button disabled={isLoading} className={classes['button-send']} onClick={sendMessage}>
124+
Send
125+
</Button>
126+
<Button className={classes['button-clean']} onClick={resetChat}>
127+
Clean
128+
</Button>
129+
</div>
119130
</div>
120131
</div>
121132
);

src/pages/sicp/subcomponents/chatbot/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type ChatMessage = {
66
type InitChatResponse = {
77
response: ChatMessage;
88
conversationId: string;
9+
maxContentSize: number;
910
};
1011

1112
type ContinueChatResponse = {

src/routes/routerConfig.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { GuardedRoute } from './routeGuard';
2525
const Login = () => import('../pages/login/Login');
2626
const LoginPage = () => import('../pages/login/LoginPage');
2727
const LoginCallback = () => import('../pages/login/LoginCallback');
28+
const LoginVscodeCallback = () => import('../pages/login/LoginVscodeCallback');
2829
const NusLogin = () => import('../pages/login/NusLogin');
2930
const Contributors = () => import('../pages/contributors/Contributors');
3031
const GitHubCallback = () => import('../pages/githubCallback/GitHubCallback');
@@ -128,7 +129,10 @@ export const getFullAcademyRouterConfig = ({
128129
{
129130
path: 'login',
130131
lazy: Login,
131-
children: [{ path: 'callback', lazy: LoginCallback }]
132+
children: [
133+
{ path: 'callback', lazy: LoginCallback },
134+
{ path: 'vscode_callback', lazy: LoginVscodeCallback }
135+
]
132136
},
133137
{ path: 'welcome', lazy: Welcome, loader: welcomeLoader },
134138
{ path: 'courses', element: <Navigate to="/" /> },

src/styles/Chatbot.module.scss

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
z-index: 1000;
77
}
88

9+
.chat-container {
10+
position: relative;
11+
width: 400px;
12+
height: 450px;
13+
border-radius: 5px;
14+
background-color: #f1f1f1;
15+
padding: 16px;
16+
z-index: 1000;
17+
}
18+
19+
.control-container {
20+
display: flex;
21+
flex-direction: column;
22+
& > :first-child {
23+
margin-top: 10px;
24+
}
25+
}
26+
927
.bot-area {
1028
position: relative;
1129
}
@@ -50,16 +68,6 @@
5068
border-radius: 50%;
5169
}
5270

53-
.chat-container {
54-
position: relative;
55-
width: 400px;
56-
height: 450px;
57-
border-radius: 5px;
58-
background-color: #f1f1f1;
59-
padding: 16px;
60-
z-index: 1000;
61-
}
62-
6371
.chat-message {
6472
height: 80%;
6573
border: 1px solid #ddd;
@@ -82,11 +90,12 @@
8290
background-color: #a3a3a4;
8391
color: #fff;
8492
font-size: 15px;
85-
text-align: right;
93+
text-align: left;
8694
padding: 10px;
8795
line-height: 1.5;
8896
border-radius: 10px;
8997
display: block;
98+
margin-bottom: 5px;
9099
}
91100

92101
.assistant {
@@ -98,6 +107,7 @@
98107
line-height: 1.5;
99108
border-radius: 10px;
100109
display: block;
110+
margin-bottom: 10px;
101111
}
102112

103113
.button-container {
@@ -130,3 +140,18 @@
130140
border-radius: 10px;
131141
vertical-align: top;
132142
}
143+
144+
.input-count-container {
145+
justify-content: flex-end;
146+
display: flex;
147+
align-items: center;
148+
height: 20px;
149+
}
150+
.input-count {
151+
font-size: 10px;
152+
color: #666;
153+
margin: 0;
154+
height: 100%;
155+
display: flex;
156+
align-items: center;
157+
}

src/styles/_achievementdashboard.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@
629629
color: white;
630630
display: flex;
631631
flex-direction: column;
632-
height: $view-height / 3;
632+
height: calc($view-height / 3);
633633
justify-content: center;
634634
margin: 1em auto;
635635
width: $view-width;

0 commit comments

Comments
 (0)