Skip to content

Commit 38763ac

Browse files
committed
add LeetCodeWidget
1 parent cd53d53 commit 38763ac

File tree

7 files changed

+48
-39
lines changed

7 files changed

+48
-39
lines changed

jupyterlab_leetcode/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,18 @@
55
# in editable mode with pip. It is highly recommended to install
66
# the package from a stable release or in editable mode: https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs
77
import warnings
8+
89
warnings.warn("Importing 'jupyterlab_leetcode' outside a proper installation.")
910
__version__ = "dev"
1011
from .handlers import setup_handlers
1112

1213

1314
def _jupyter_labextension_paths():
14-
return [{
15-
"src": "labextension",
16-
"dest": "jupyterlab-leetcode"
17-
}]
15+
return [{"src": "labextension", "dest": "jupyterlab-leetcode"}]
1816

1917

2018
def _jupyter_server_extension_points():
21-
return [{
22-
"module": "jupyterlab_leetcode"
23-
}]
19+
return [{"module": "jupyterlab_leetcode"}]
2420

2521

2622
def _load_jupyter_server_extension(server_app):

jupyterlab_leetcode/handlers.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import json
22

3+
import tornado
34
from jupyter_server.base.handlers import APIHandler
45
from jupyter_server.utils import url_path_join
5-
import tornado
6+
67

78
class RouteHandler(APIHandler):
89
# The following decorator should be present on all verb methods (head, get, post,
910
# patch, put, delete, options) to ensure only authorized user can request the
1011
# Jupyter server
1112
@tornado.web.authenticated
1213
def get(self):
13-
self.finish(json.dumps({
14-
"data": "This is /jupyterlab-leetcode/get-example endpoint!"
15-
}))
14+
self.finish(
15+
json.dumps(
16+
{
17+
"data": "This is /jupyterlab-leetcode/get-example endpoint!",
18+
}
19+
)
20+
)
1621

1722

1823
def setup_handlers(web_app):

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"watch:labextension": "jupyter labextension watch ."
5858
},
5959
"dependencies": {
60-
"@jupyterlab/application": "^4.0.0",
60+
"@jupyterlab/application": "^4.4.3",
61+
"@jupyterlab/apputils": "^4.5.3",
6162
"@jupyterlab/coreutils": "^6.0.0",
6263
"@jupyterlab/services": "^7.0.0",
6364
"@jupyterlab/settingregistry": "^4.0.0"

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ classifiers = [
2424
]
2525
dependencies = [
2626
"jupyter_server>=2.4.0,<3"
27+
# TODO: fill this
2728
]
2829
dynamic = ["version", "description", "authors", "urls", "keywords"]
2930

src/index.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import {
33
JupyterFrontEndPlugin
44
} from '@jupyterlab/application';
55

6-
import { ISettingRegistry } from '@jupyterlab/settingregistry';
7-
8-
import { requestAPI } from './handler';
6+
import LeetCodeWidget from './widget';
97

108
/**
119
* Initialization data for the jupyterlab-leetcode extension.
@@ -14,30 +12,13 @@ const plugin: JupyterFrontEndPlugin<void> = {
1412
id: 'jupyterlab-leetcode:plugin',
1513
description: 'Integrate LeetCode into beloved Jupyter.',
1614
autoStart: true,
17-
optional: [ISettingRegistry],
18-
activate: (app: JupyterFrontEnd, settingRegistry: ISettingRegistry | null) => {
15+
requires: [],
16+
optional: [],
17+
activate: (app: JupyterFrontEnd) => {
1918
console.log('JupyterLab extension jupyterlab-leetcode is activated!');
2019

21-
if (settingRegistry) {
22-
settingRegistry
23-
.load(plugin.id)
24-
.then(settings => {
25-
console.log('jupyterlab-leetcode settings loaded:', settings.composite);
26-
})
27-
.catch(reason => {
28-
console.error('Failed to load settings for jupyterlab-leetcode.', reason);
29-
});
30-
}
31-
32-
requestAPI<any>('get-example')
33-
.then(data => {
34-
console.log(data);
35-
})
36-
.catch(reason => {
37-
console.error(
38-
`The jupyterlab_leetcode server extension appears to be missing.\n${reason}`
39-
);
40-
});
20+
const leetcodeWidget: LeetCodeWidget = new LeetCodeWidget();
21+
app.shell.add(leetcodeWidget, 'right', { rank: 599 });
4122
}
4223
};
4324

src/widget.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ReactWidget } from '@jupyterlab/ui-components';
2+
import React from 'react';
3+
4+
const LeetCodeComponent = (): JSX.Element => {
5+
return (
6+
<div>
7+
<p>Welcome to JupyterLab LeetCode Widget.</p>
8+
</div>
9+
);
10+
};
11+
12+
class LeetCodeWidget extends ReactWidget {
13+
constructor() {
14+
super();
15+
this.id = 'JupyterlabLeetcodeWidget';
16+
this.addClass('jupyterlab-leetcode-widget');
17+
}
18+
19+
protected render(): JSX.Element {
20+
return <LeetCodeComponent />;
21+
}
22+
}
23+
24+
export default LeetCodeWidget;

yarn.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ __metadata:
20072007
languageName: node
20082008
linkType: hard
20092009

2010-
"@jupyterlab/application@npm:^4.0.0, @jupyterlab/application@npm:^4.4.3":
2010+
"@jupyterlab/application@npm:^4.4.3":
20112011
version: 4.4.3
20122012
resolution: "@jupyterlab/application@npm:4.4.3"
20132013
dependencies:
@@ -6810,7 +6810,8 @@ __metadata:
68106810
version: 0.0.0-use.local
68116811
resolution: "jupyterlab-leetcode@workspace:."
68126812
dependencies:
6813-
"@jupyterlab/application": ^4.0.0
6813+
"@jupyterlab/application": ^4.4.3
6814+
"@jupyterlab/apputils": ^4.5.3
68146815
"@jupyterlab/builder": ^4.0.0
68156816
"@jupyterlab/coreutils": ^6.0.0
68166817
"@jupyterlab/services": ^7.0.0

0 commit comments

Comments
 (0)