Skip to content

Commit d229982

Browse files
committed
use react-select for ArticlePicker
1 parent 8d1274b commit d229982

File tree

17 files changed

+469
-328
lines changed

17 files changed

+469
-328
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.vscode/
2+
node_modules/
3+
14
# extensions examples
25
examples/
36

extension/dist/background.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extension/dist/content_script.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
29.8 KB
Binary file not shown.
25.3 KB
Binary file not shown.

extension/package-lock.json

Lines changed: 229 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extension/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"dev": "webpack --watch",
9-
"dev-local": "WIKIGAME_SERVER_URL=http://localhost:9454 webpack --watch",
8+
"dev": "GENERATE_SOURCE_MAP=true webpack --watch",
9+
"dev-local": "GENERATE_SOURCE_MAP=true WIKIGAME_SERVER_URL=http://localhost:9454 webpack --watch",
1010
"build": "webpack --mode production",
1111
"build-local": "WIKIGAME_SERVER_URL=http://localhost:9454 webpack --mode production",
1212
"pack": "webpack --mode production && echo 'Creating zip and crx file...' && crx pack dist -o dist/wikigame-v$npm_package_version.crx * && cd dist && zip -x *.crx -r wikigame-v$npm_package_version.zip *",
@@ -34,6 +34,7 @@
3434
"ramda": "^0.27.1",
3535
"react": "^16.13.1",
3636
"react-dom": "^16.13.1",
37+
"react-select": "^3.1.0",
3738
"react-toastify": "^6.0.9",
3839
"regenerator-runtime": "^0.13.7",
3940
"socket.io-client": "^2.3.1"

extension/src/background/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,24 @@ chrome.runtime.onMessage.addListener(
256256
if (!ack || !ack.success) {
257257
if (ack.message) {
258258
sendNotification('error', ack.message);
259-
259+
260260
// we call update to reset any obsolete fields
261261
updateData({}, updated => {
262262
sendMessage('update', updated);
263+
// For now, this is only for resetting loading state in ArticlePicker
264+
sendResponse({error: ack.message});
263265
});
264266
}
265267
} else if (ack.data) {
266268
updateData(ack.data, updated => {
267269
sendMessage('update', updated);
270+
sendResponse(null);
268271
});
272+
} else {
273+
sendResponse(null);
269274
}
270275
});
276+
return true;
271277
} else if (message.type === 'start') {
272278
console.log('start!');
273279

extension/src/content_script/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
33

44
import { ToastContainer, toast } from 'react-toastify';
55
import 'react-toastify/dist/ReactToastify.css';
6-
import './style.css';
6+
import './styles/style.css';
77

88
import * as util from './util';
99
import * as wiki from './wiki';

extension/src/content_script/sidebar.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,29 @@ function LobbySidebar(props) {
1919
const {currentRound, rules, leaderboard, lastRound, host, username, players } = data;
2020
const isHost = host === username;
2121

22-
const onStartArticleChange = title => {
23-
console.log('onStartArticleChange', title);
22+
const onUpdate = (toUpdate, callback) => {
2423
if (!isHost) return;
2524
chrome.runtime.sendMessage({
2625
type: 'update',
27-
data: { currentRound: { start: title } },
26+
data: toUpdate,
27+
}, reply => {
28+
if (callback) callback(reply);
2829
});
2930
};
3031

31-
const onTargetArticleChange = title => {
32+
const onStartArticleChange = (title, callback) => {
33+
console.log('onStartArticleChange', title);
34+
onUpdate({ currentRound: { start: title } }, callback);
35+
};
36+
37+
const onTargetArticleChange = (title, callback) => {
3238
console.log('onTargetArticleChange', title);
33-
if (!isHost) return;
34-
chrome.runtime.sendMessage({
35-
type: 'update',
36-
data: { currentRound: { target: title } },
37-
});
39+
onUpdate({ currentRound: { target: title } }, callback);
3840
};
3941

40-
const onRulesChange = newRules => {
42+
const onRulesChange = (newRules, callback) => {
4143
console.log('onRulesChange', newRules);
42-
if (!isHost) return;
43-
chrome.runtime.sendMessage({
44-
type: 'update',
45-
data: { rules: newRules },
46-
});
44+
onUpdate({ rules: newRules }, callback);
4745
};
4846

4947
const onStartRound = () => {
@@ -56,15 +54,14 @@ function LobbySidebar(props) {
5654
chrome.runtime.sendMessage({ type: 'start' });
5755
};
5856

59-
const onTransferHost = (newHost) => {
57+
const onTransferHost = (newHost, callback) => {
6058
console.log('onTransferHost', newHost);
61-
if (!isHost) return;
62-
if (!players.includes(newHost)) return;
59+
if (!isHost || !players.includes(newHost)) {
60+
if (callback) callback();
61+
return;
62+
}
6363
if (window.confirm(`You're about to transfer host to ${newHost}. Are you sure?`)) {
64-
chrome.runtime.sendMessage({
65-
type: 'update',
66-
data: { host: newHost },
67-
});
64+
onUpdate({host: newHost}, callback);
6865
}
6966
};
7067

@@ -111,7 +108,6 @@ function GameSidebar(props) {
111108

112109
// enforce rules
113110
useEffect(() => {
114-
console.log('enforce rules!');
115111
if (currentState.finished) return;
116112

117113
// remove search bar
@@ -188,6 +184,7 @@ function GameSidebar(props) {
188184
<Rules
189185
rules={rules}
190186
disabled={true}
187+
roundStarted={true}
191188
/>
192189
</div>
193190
);

0 commit comments

Comments
 (0)