-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create update meilisearch data task page
- Loading branch information
Showing
8 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:logging/logging.dart'; | ||
import '../components/number_field.dart'; | ||
import '../globals.dart'; | ||
|
||
final _log = Logger("NewUpdateTagTranslationTaskPage"); | ||
|
||
class NewUpdateMeiliSearchDataTaskPage extends StatefulWidget { | ||
const NewUpdateMeiliSearchDataTaskPage({this.gid, super.key}); | ||
|
||
final int? gid; | ||
|
||
static const routeName = "/dialog/new_update_meili_search_data_task"; | ||
|
||
@override | ||
State<NewUpdateMeiliSearchDataTaskPage> createState() => | ||
_NewUpdateMeiliSearchDataTaskPage(); | ||
} | ||
|
||
class _NewUpdateMeiliSearchDataTaskPage | ||
extends State<NewUpdateMeiliSearchDataTaskPage> { | ||
final _formKey = GlobalKey<FormState>(); | ||
bool _ok = false; | ||
bool _isCreating = false; | ||
CancelToken? _cancel; | ||
int? _gid; | ||
|
||
@override | ||
void initState() { | ||
_gid = widget.gid; | ||
super.initState(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_cancel?.cancel(); | ||
super.dispose(); | ||
} | ||
|
||
Future<void> create() async { | ||
try { | ||
_cancel = CancelToken(); | ||
setState(() { | ||
_isCreating = true; | ||
}); | ||
(await api.createUpdateMeiliSearchDataTask(gid: _gid, cancel: _cancel)) | ||
.unwrap(); | ||
_ok = true; | ||
if (!_cancel!.isCancelled) { | ||
setState(() { | ||
_isCreating = false; | ||
}); | ||
} | ||
} catch (e) { | ||
if (!_cancel!.isCancelled) { | ||
_log.warning("Failed to create import task:", e); | ||
setState(() { | ||
_isCreating = false; | ||
}); | ||
} | ||
} | ||
} | ||
|
||
Widget _buildWithVecticalPadding(Widget child) { | ||
return Container( | ||
padding: const EdgeInsets.symmetric(vertical: 8), | ||
child: child, | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
tryInitApi(context); | ||
if (_ok) { | ||
WidgetsBinding.instance!.addPostFrameCallback((_) { | ||
context.canPop() ? context.pop() : context.go("/task_manager"); | ||
}); | ||
_ok = false; | ||
} | ||
final i18n = AppLocalizations.of(context)!; | ||
final maxWidth = MediaQuery.of(context).size.width; | ||
return Container( | ||
padding: maxWidth < 400 | ||
? const EdgeInsets.symmetric(vertical: 20, horizontal: 5) | ||
: const EdgeInsets.all(20), | ||
width: maxWidth < 810 ? null : 800, | ||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10)), | ||
child: SingleChildScrollView( | ||
child: Form( | ||
key: _formKey, | ||
child: Column( | ||
children: [ | ||
Stack( | ||
alignment: Alignment.center, | ||
children: [ | ||
Text( | ||
i18n.createUpdateMeiliSearchDataTask, | ||
style: Theme.of(context).textTheme.headlineSmall, | ||
), | ||
Align( | ||
alignment: Alignment.centerRight, | ||
child: IconButton( | ||
onPressed: () => context.canPop() | ||
? context.pop() | ||
: context.go("/task_manager"), | ||
icon: const Icon(Icons.close), | ||
)), | ||
], | ||
), | ||
_buildWithVecticalPadding(NumberFormField( | ||
min: 0, | ||
initialValue: _gid, | ||
decoration: InputDecoration( | ||
border: const OutlineInputBorder(), | ||
labelText: i18n.gid, | ||
helperText: i18n.updateMeiliSearchDataGidHelp, | ||
helperMaxLines: 3, | ||
), | ||
onChanged: (gid) { | ||
_gid = gid; | ||
}, | ||
)), | ||
_buildWithVecticalPadding(ElevatedButton( | ||
onPressed: _isCreating | ||
? null | ||
: () { | ||
create(); | ||
}, | ||
child: Text(i18n.create))), | ||
], | ||
)))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters