redisign multiple payouts for better ux and small fixes

This commit is contained in:
Arseni
2026-02-12 18:48:57 +03:00
parent ea68d161d6
commit 45d3c3145c
19 changed files with 226 additions and 262 deletions

View File

@@ -19,17 +19,11 @@ class WebCsvInputService implements CsvInputService {
Future<PickedCsvFile?> pickCsv() async {
final input = html.FileUploadInputElement()
..accept = '.csv,text/csv'
..multiple = false;
..multiple = false
..style.display = 'none';
final completer = Completer<html.File?>();
input.onChange.listen((_) {
completer.complete(
input.files?.isNotEmpty == true ? input.files!.first : null,
);
});
input.click();
final file = await completer.future;
html.document.body?.append(input);
final file = await _pickFile(input);
if (file == null) return null;
final reader = html.FileReader();
@@ -50,4 +44,52 @@ class WebCsvInputService implements CsvInputService {
final content = await readCompleter.future;
return PickedCsvFile(name: file.name, content: content);
}
Future<html.File?> _pickFile(html.FileUploadInputElement input) async {
final completer = Completer<html.File?>();
void completeWith(html.File? file) {
if (!completer.isCompleted) completer.complete(file);
}
StreamSubscription<html.Event>? changeSub;
StreamSubscription<html.Event>? inputSub;
StreamSubscription<html.Event>? focusSub;
Timer? timeout;
void cleanup() {
changeSub?.cancel();
inputSub?.cancel();
focusSub?.cancel();
timeout?.cancel();
input.remove();
}
void tryComplete() {
final file = input.files?.isNotEmpty == true ? input.files!.first : null;
if (file != null) {
completeWith(file);
}
}
changeSub = input.onChange.listen((_) => tryComplete());
inputSub = input.onInput.listen((_) => tryComplete());
focusSub = html.window.onFocus.listen((_) async {
if (completer.isCompleted) return;
for (var i = 0; i < 6; i++) {
tryComplete();
if (completer.isCompleted) return;
await Future<void>.delayed(const Duration(milliseconds: 120));
}
if (!completer.isCompleted && (input.value ?? '').isEmpty) {
completeWith(null);
}
});
timeout = Timer(const Duration(minutes: 2), () => completeWith(null));
completer.future.whenComplete(cleanup);
input.click();
return completer.future;
}
}