Snapshot
Browse files
frontend/public/index.css
CHANGED
@@ -121,13 +121,13 @@ details > summary {
|
|
121 |
color: red;
|
122 |
}
|
123 |
|
124 |
-
span.
|
125 |
background-color: #222222;
|
126 |
color: white;
|
127 |
padding: 2px;
|
128 |
}
|
129 |
|
130 |
-
span.
|
131 |
background-color: #dd1111;
|
132 |
}
|
133 |
|
|
|
121 |
color: red;
|
122 |
}
|
123 |
|
124 |
+
span.word-chip {
|
125 |
background-color: #222222;
|
126 |
color: white;
|
127 |
padding: 2px;
|
128 |
}
|
129 |
|
130 |
+
span.word-chip.flagged {
|
131 |
background-color: #dd1111;
|
132 |
}
|
133 |
|
frontend/src/components/{app.tsx β App.tsx}
RENAMED
@@ -1,5 +1,6 @@
|
|
1 |
import React, { useState } from "react"
|
2 |
-
import {
|
|
|
3 |
|
4 |
interface Word {
|
5 |
text: string
|
@@ -14,24 +15,6 @@ async function checkText(text: string): Promise<Word[]> {
|
|
14 |
return data.words
|
15 |
}
|
16 |
|
17 |
-
async function checkText0(text: string): Promise<Word[]> {
|
18 |
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
19 |
-
|
20 |
-
const words = text.split(/\b/)
|
21 |
-
return words.map(word => ({
|
22 |
-
text: word,
|
23 |
-
logprob: -word.length,
|
24 |
-
replacements: word.length < 4 ? [] : ["foo", "bar"]
|
25 |
-
}))
|
26 |
-
}
|
27 |
-
|
28 |
-
// Add a new Spinner component
|
29 |
-
const Spinner = () => (
|
30 |
-
<div className="spinner-overlay">
|
31 |
-
<div className="spinner"></div>
|
32 |
-
</div>
|
33 |
-
);
|
34 |
-
|
35 |
export default function App() {
|
36 |
const [threshold, setThreshold] = useState(-5.0)
|
37 |
const [context, setContext] = useState("")
|
@@ -62,14 +45,13 @@ export default function App() {
|
|
62 |
}
|
63 |
}
|
64 |
|
65 |
-
const handleReplace = async (index: number,
|
66 |
const updatedWords = [...words]
|
67 |
-
updatedWords[index].text =
|
68 |
updatedWords[index].logprob = 0
|
69 |
updatedWords[index].replacements = []
|
70 |
setWords(updatedWords)
|
71 |
setText(updatedWords.map(w => w.text).join(""))
|
72 |
-
// setMode("edit")
|
73 |
await check()
|
74 |
}
|
75 |
|
@@ -88,13 +70,13 @@ export default function App() {
|
|
88 |
{isLoading && <Spinner />}
|
89 |
<div className="result">
|
90 |
{words.map((word, index) => (
|
91 |
-
<
|
92 |
key={index}
|
93 |
-
|
94 |
logprob={word.logprob}
|
95 |
threshold={threshold}
|
96 |
replacements={word.replacements}
|
97 |
-
onReplace={(
|
98 |
/>
|
99 |
))}
|
100 |
</div>
|
|
|
1 |
import React, { useState } from "react"
|
2 |
+
import { WordChip } from "./WordChip"
|
3 |
+
import Spinner from "./Spinner"
|
4 |
|
5 |
interface Word {
|
6 |
text: string
|
|
|
15 |
return data.words
|
16 |
}
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
export default function App() {
|
19 |
const [threshold, setThreshold] = useState(-5.0)
|
20 |
const [context, setContext] = useState("")
|
|
|
45 |
}
|
46 |
}
|
47 |
|
48 |
+
const handleReplace = async (index: number, newWord: string) => {
|
49 |
const updatedWords = [...words]
|
50 |
+
updatedWords[index].text = newWord
|
51 |
updatedWords[index].logprob = 0
|
52 |
updatedWords[index].replacements = []
|
53 |
setWords(updatedWords)
|
54 |
setText(updatedWords.map(w => w.text).join(""))
|
|
|
55 |
await check()
|
56 |
}
|
57 |
|
|
|
70 |
{isLoading && <Spinner />}
|
71 |
<div className="result">
|
72 |
{words.map((word, index) => (
|
73 |
+
<WordChip
|
74 |
key={index}
|
75 |
+
word={word.text}
|
76 |
logprob={word.logprob}
|
77 |
threshold={threshold}
|
78 |
replacements={word.replacements}
|
79 |
+
onReplace={(newWord) => handleReplace(index, newWord)}
|
80 |
/>
|
81 |
))}
|
82 |
</div>
|
frontend/src/components/Spinner.tsx
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from "react"
|
2 |
+
|
3 |
+
const Spinner = () => (
|
4 |
+
<div className="spinner-overlay">
|
5 |
+
<div className="spinner"></div>
|
6 |
+
</div>
|
7 |
+
);
|
8 |
+
|
9 |
+
export default Spinner;
|
frontend/src/components/{TokenChip.tsx β WordChip.tsx}
RENAMED
@@ -1,17 +1,17 @@
|
|
1 |
import React, { useState, useEffect, useRef } from "react"
|
2 |
|
3 |
-
export const
|
4 |
-
|
5 |
logprob,
|
6 |
threshold,
|
7 |
replacements,
|
8 |
onReplace
|
9 |
}: {
|
10 |
-
|
11 |
logprob: number,
|
12 |
threshold: number,
|
13 |
replacements: string[],
|
14 |
-
onReplace: (
|
15 |
}) => {
|
16 |
const [isExpanded, setIsExpanded] = useState(false);
|
17 |
const dropdownRef = useRef<HTMLSelectElement>(null);
|
@@ -36,26 +36,24 @@ export const TokenChip = ({
|
|
36 |
}
|
37 |
|
38 |
const handleReplacement = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
39 |
-
const
|
40 |
-
|
41 |
-
onReplace(newToken)
|
42 |
-
}
|
43 |
setIsExpanded(false);
|
44 |
}
|
45 |
|
46 |
return (
|
47 |
<span
|
48 |
title={logprob.toFixed(2)}
|
49 |
-
className={`
|
50 |
style={{ position: "relative", cursor: logprob < threshold ? "pointer" : "default" }}
|
51 |
onClick={handleClick}
|
52 |
>
|
53 |
-
{
|
54 |
{isExpanded && (
|
55 |
<select
|
56 |
ref={dropdownRef}
|
57 |
onChange={handleReplacement}
|
58 |
-
value={
|
59 |
style={{
|
60 |
position: "absolute",
|
61 |
top: "100%",
|
@@ -65,8 +63,8 @@ export const TokenChip = ({
|
|
65 |
size={replacements.length}
|
66 |
autoFocus
|
67 |
>
|
68 |
-
{replacements.map((
|
69 |
-
<option key={
|
70 |
))}
|
71 |
</select>
|
72 |
)}
|
|
|
1 |
import React, { useState, useEffect, useRef } from "react"
|
2 |
|
3 |
+
export const WordChip = ({
|
4 |
+
word,
|
5 |
logprob,
|
6 |
threshold,
|
7 |
replacements,
|
8 |
onReplace
|
9 |
}: {
|
10 |
+
word: string,
|
11 |
logprob: number,
|
12 |
threshold: number,
|
13 |
replacements: string[],
|
14 |
+
onReplace: (newWord: string) => void
|
15 |
}) => {
|
16 |
const [isExpanded, setIsExpanded] = useState(false);
|
17 |
const dropdownRef = useRef<HTMLSelectElement>(null);
|
|
|
36 |
}
|
37 |
|
38 |
const handleReplacement = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
39 |
+
const newWord = event.target.value
|
40 |
+
onReplace(newWord)
|
|
|
|
|
41 |
setIsExpanded(false);
|
42 |
}
|
43 |
|
44 |
return (
|
45 |
<span
|
46 |
title={logprob.toFixed(2)}
|
47 |
+
className={`word-chip ${logprob < threshold ? "flagged" : ""}`}
|
48 |
style={{ position: "relative", cursor: logprob < threshold ? "pointer" : "default" }}
|
49 |
onClick={handleClick}
|
50 |
>
|
51 |
+
{word}
|
52 |
{isExpanded && (
|
53 |
<select
|
54 |
ref={dropdownRef}
|
55 |
onChange={handleReplacement}
|
56 |
+
value={word}
|
57 |
style={{
|
58 |
position: "absolute",
|
59 |
top: "100%",
|
|
|
63 |
size={replacements.length}
|
64 |
autoFocus
|
65 |
>
|
66 |
+
{replacements.map((r, i) => (
|
67 |
+
<option key={i} value={r}>{r}</option>
|
68 |
))}
|
69 |
</select>
|
70 |
)}
|
frontend/src/index.tsx
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import React from "react"
|
2 |
import { createRoot } from "react-dom/client"
|
3 |
-
import App from "./components/
|
4 |
|
5 |
const app = document.getElementById("app")
|
6 |
|
|
|
1 |
import React from "react"
|
2 |
import { createRoot } from "react-dom/client"
|
3 |
+
import App from "./components/App"
|
4 |
|
5 |
const app = document.getElementById("app")
|
6 |
|