@@ -12,6 +12,7 @@ import BrowserDetector from "browser-dtector";
1212import { dictionary } from "../dictionary/dictionary.ts" ;
1313import { dictionaryParser } from "../dictionary/parser.ts" ;
1414import PROJECT_DATA from "../project_data.json" with { type : "json" } ;
15+ import { Result , ResultError } from "./compound.ts" ;
1516import { loadCustomDictionary } from "./dictionary.ts" ;
1617import { checkLocalStorage , setIgnoreError } from "./local_storage.ts" ;
1718import { PositionedError } from "./parser/parser_lib.ts" ;
@@ -23,9 +24,9 @@ import {
2324 resetElementsToDefault ,
2425} from "./settings_frontend.ts" ;
2526import { translate } from "./translator/translator.ts" ;
26- import { ResultError } from "./compound.ts" ;
2727
2828const DICTIONARY_AUTO_PARSE_THRESHOLD = 9000 ;
29+ const PAGE_SIZE = 100 ;
2930
3031// never change this
3132const DICTIONARY_KEY = "dictionary" ;
@@ -76,6 +77,9 @@ function main() {
7677 const errorList = document . getElementById (
7778 "error-list" ,
7879 ) as HTMLParagraphElement ;
80+ const loadMoreButton = document . getElementById (
81+ "load-more-button" ,
82+ ) as HTMLButtonElement ;
7983
8084 const translateButton = document . getElementById (
8185 "translate-button" ,
@@ -184,6 +188,9 @@ function main() {
184188 // this variable also holds error messages
185189 let currentDictionary = lastSavedDictionary ;
186190
191+ // state for output
192+ let output : null | Generator < Result < string > > = null ;
193+
187194 // load custom dictionary
188195 if ( ! currentDictionary . isError ( ) ) {
189196 loadCustomDictionary ( currentDictionary . unwrap ( ) [ 0 ] ) ;
@@ -240,25 +247,39 @@ function main() {
240247 updateOutput ( ) ;
241248 }
242249 } ) ;
250+ loadMoreButton . addEventListener ( "click" , moreOutput ) ;
243251 function updateOutput ( ) {
244252 outputList . innerHTML = "" ;
245253 errorList . innerHTML = "" ;
246254 errorDisplay . innerText = "" ;
247- const iterableResult = translate ( inputTextBox . value ) ;
255+ loadMoreButton . style . display = "" ;
256+ output = translate ( inputTextBox . value ) . iterable ( ) ;
257+ moreOutput ( ) ;
258+ }
259+ function moreOutput ( ) {
248260 const errors : Array < ResultError > = [ ] ;
249261 let yielded = false ;
250- for ( const result of iterableResult . iterable ( ) ) {
251- switch ( result . type ) {
252- case "value" : {
253- yielded = true ;
254- const list = document . createElement ( "li" ) ;
255- list . innerHTML = result . value ;
256- outputList . appendChild ( list ) ;
257- break ;
262+ let i = 0 ;
263+ while ( i < PAGE_SIZE ) {
264+ const next = output ! . next ( ) ;
265+ if ( ! next . done ) {
266+ const result = next . value ;
267+ switch ( result . type ) {
268+ case "value" : {
269+ yielded = true ;
270+ const list = document . createElement ( "li" ) ;
271+ list . innerHTML = result . value ;
272+ outputList . appendChild ( list ) ;
273+ i ++ ;
274+ break ;
275+ }
276+ case "error" :
277+ errors . push ( result . error ) ;
278+ break ;
258279 }
259- case "error" :
260- errors . push ( result . error ) ;
261- break ;
280+ } else {
281+ loadMoreButton . style . display = "none" ;
282+ break ;
262283 }
263284 }
264285 if ( ! yielded ) {
0 commit comments