Skip to content

Commit 8d236a3

Browse files
committed
question list table
1 parent 9aff449 commit 8d236a3

17 files changed

+485
-154
lines changed

jupyterlab_leetcode/handlers/leetcode_handler.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,6 @@ async def get(self):
158158
}""",
159159
"variables": {"userSlug": username},
160160
},
161-
"userPublicProfile": {
162-
"query": """query userPublicProfile($username: String!) {
163-
matchedUser(username: $username) {
164-
username
165-
profile {
166-
ranking
167-
}
168-
}
169-
}""",
170-
"variables": {"username": username},
171-
},
172161
},
173162
)
174163

src/components/BrowserCookie.tsx renamed to src/components/BrowserMenu.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { Button, Menu, useMantineTheme } from '@mantine/core';
1515
import { getCookie } from '../services/cookie';
1616

17-
const BROWSERS = [
17+
const Browsers = [
1818
{
1919
name: 'Chrome',
2020
icon: (color: string) => (
@@ -86,7 +86,7 @@ const BROWSERS = [
8686
const normalizeBrowserName = (name: string) =>
8787
name.toLowerCase().replace(/\s+/g, '_');
8888

89-
const BrowserCookie: React.FC<{
89+
const BrowserMenu: React.FC<{
9090
className?: string;
9191
setCookieLoggedIn: (b: string) => void;
9292
}> = ({ className, setCookieLoggedIn }) => {
@@ -146,7 +146,7 @@ const BrowserCookie: React.FC<{
146146
</Menu.Target>
147147
<Menu.Dropdown>
148148
<Menu.Label>With LeetCode logged in</Menu.Label>
149-
{BROWSERS.map(({ name, icon }) => (
149+
{Browsers.map(({ name, icon }) => (
150150
<Menu.Item
151151
key={name}
152152
leftSection={icon(theme.colors.blue[6])}
@@ -160,4 +160,4 @@ const BrowserCookie: React.FC<{
160160
);
161161
};
162162

163-
export default BrowserCookie;
163+
export default BrowserMenu;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import { Stack, Text } from '@mantine/core';
3+
4+
const DifficultyStatistics: React.FC<{ text: string; color: string }> = ({
5+
text,
6+
color
7+
}) => {
8+
return (
9+
<Stack>
10+
<Text>{text.charAt(0).toUpperCase() + text.slice(1)}</Text>
11+
</Stack>
12+
);
13+
};
14+
15+
export default DifficultyStatistics;

src/components/Footer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Anchor, Container, Group } from '@mantine/core';
33
import classes from '../styles/Footer.module.css';
44
import { IconBrandLeetcode } from '@tabler/icons-react';
55

6-
const LINKS = [
6+
const Links = [
77
{
88
link: 'https://github.com/Sorosliu1029/jupyterlab-leetcode',
99
label: 'GitHub'
@@ -18,7 +18,7 @@ const Footer = () => {
1818
<Container className={classes.inner}>
1919
<IconBrandLeetcode size={28} />
2020
<Group className={classes.links}>
21-
{LINKS.map(link => (
21+
{Links.map(link => (
2222
<Anchor<'a'>
2323
c="dimmed"
2424
key={link.label}

src/components/LeetCodeMainArea.tsx renamed to src/components/JupyterMainArea.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import React, { useEffect, useState } from 'react';
22
import { IDocumentManager } from '@jupyterlab/docmanager';
3-
import { JupyterFrontEnd } from '@jupyterlab/application';
43
import LandingPage from './LandingPage';
5-
import LeetCode from './LeetCode';
4+
import LeetCodeMain from './LeetCodeMain';
65
import { getCookie } from '../services/cookie';
76
import { Notification } from '@jupyterlab/apputils';
87

9-
const LeetCodeMainArea: React.FC<{
10-
app: JupyterFrontEnd;
11-
docManager: IDocumentManager;
12-
}> = ({ app, docManager }) => {
8+
const JupyterMainArea: React.FC<{ docManager: IDocumentManager }> = ({
9+
docManager
10+
}) => {
1311
const [cookieLoggedIn, setCookieLoggedIn] = useState('');
1412

1513
useEffect(() => {
@@ -28,11 +26,12 @@ const LeetCodeMainArea: React.FC<{
2826
}
2927
});
3028

29+
// FIXME: flash when refresh
3130
return cookieLoggedIn ? (
32-
<LeetCode app={app} docManager={docManager} />
31+
<LeetCodeMain docManager={docManager} />
3332
) : (
3433
<LandingPage setCookieLoggedIn={b => setCookieLoggedIn(b)} />
3534
);
3635
};
3736

38-
export default LeetCodeMainArea;
37+
export default JupyterMainArea;

src/components/LandingPage.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import React from 'react';
2-
import BrowserCookie from './BrowserCookie';
32

43
import { Button, Container, Group, Text, Tooltip, Anchor } from '@mantine/core';
54
import { IconBrandGithub, IconBrandLinkedin } from '@tabler/icons-react';
65
import classes from '../styles/LandingPage.module.css';
76
import Footer from './Footer';
7+
import BrowserMenu from './BrowserMenu';
88

9-
const LeetCdoeGradient = { from: '#FEA512', to: '#FFDB01' };
9+
export const LeetCodeMainColor = '#FEA512';
10+
export const LeetCodeSecondColor = '#FFDB01';
11+
const LeetCdoeGradient = { from: LeetCodeMainColor, to: LeetCodeSecondColor };
1012

1113
const LandingPage: React.FC<{
1214
setCookieLoggedIn: (b: string) => void;
1315
}> = ({ setCookieLoggedIn }) => {
1416
const options: JSX.Element[] = [
15-
<BrowserCookie
17+
<BrowserMenu
1618
setCookieLoggedIn={setCookieLoggedIn}
1719
className={classes.control}
1820
/>,

src/components/LeetCode.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/components/LeetCodeMain.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React, { useEffect, useState } from 'react';
2+
import { IDocumentManager } from '@jupyterlab/docmanager';
3+
import { Notification } from '@jupyterlab/apputils';
4+
import { Container, Group, Stack } from '@mantine/core';
5+
import { getProfile } from '../services/leetcode';
6+
import { LeetCodeProfile } from '../types/leetcode';
7+
import Profile from './Profile';
8+
import Statistics from './Statistics';
9+
import QuestionList from './QuestionList';
10+
11+
const LeetCodeMain: React.FC<{ docManager: IDocumentManager }> = ({
12+
docManager
13+
}) => {
14+
const [profile, setProfile] = useState<LeetCodeProfile | null>(null);
15+
16+
useEffect(() => {
17+
getProfile()
18+
.then(profile => {
19+
if (!profile.isSignedIn) {
20+
Notification.error('Please sign in to LeetCode.', {
21+
autoClose: 3000
22+
});
23+
return;
24+
}
25+
setProfile(profile);
26+
})
27+
.catch(e => Notification.error(e.message, { autoClose: 3000 }));
28+
}, []);
29+
30+
const openNoteBook = (path: string) => {
31+
docManager.openOrReveal(path);
32+
};
33+
34+
const calcHeight = () => {
35+
const mainEle = document.querySelector('#jll-main');
36+
const profileEle = document.querySelector('#jll-profile');
37+
if (!mainEle || !profileEle) {
38+
return '100%';
39+
}
40+
const mainStyle = window.getComputedStyle(mainEle);
41+
const padding =
42+
parseFloat(mainStyle.paddingTop) + parseFloat(mainStyle.paddingBottom);
43+
return mainEle.clientHeight - padding - profileEle.clientHeight;
44+
};
45+
46+
return (
47+
<Container fluid={true} h={'100%'} p="lg" id="jll-main">
48+
<Stack>
49+
<Group id="jll-profile">
50+
{profile && <Profile profile={profile} />}
51+
{profile && <Statistics username={profile.username} />}
52+
</Group>
53+
<QuestionList openNotebook={openNoteBook} height={calcHeight()} />
54+
</Stack>
55+
</Container>
56+
);
57+
};
58+
59+
export default LeetCodeMain;

src/components/Profile.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import React from 'react';
2+
import { Avatar, Paper, Text } from '@mantine/core';
23
import { LeetCodeProfile } from '../types/leetcode';
34

4-
const Profile: React.FC<{ profile: LeetCodeProfile }> = ({ profile }) => {
5+
const Profile: React.FC<{
6+
profile: LeetCodeProfile;
7+
}> = ({ profile }) => {
58
return (
6-
<div>
7-
<p>Welcome {profile.username}</p>
8-
<img
9-
src={profile.avatar}
10-
alt="Avatar"
11-
style={{ width: '100px', height: '100px' }}
12-
/>
13-
</div>
9+
<Paper
10+
shadow="md"
11+
radius="md"
12+
withBorder
13+
p="sm"
14+
miw={'20%'}
15+
maw={'40%'}
16+
bg="var(--mantine-color-body)"
17+
>
18+
<Avatar src={profile.avatar} size={60} radius={60} mx="auto" />
19+
<Text ta="center" fz="md" fw={500} mt="xs">
20+
{profile.realName}
21+
</Text>
22+
<Text ta="center" c="dimmed" fz="xs">
23+
{profile.username}
24+
</Text>
25+
</Paper>
1426
);
1527
};
1628

0 commit comments

Comments
 (0)