feat(app): Rename and Schedule this run move into the run detail's more menu
This commit is contained in:
@@ -32,27 +32,19 @@ class RunTitleAction extends StatefulWidget {
|
||||
|
||||
class _RunTitleActionState extends State<RunTitleAction> {
|
||||
bool _dialogOpen = false;
|
||||
bool _saving = false;
|
||||
|
||||
bool _usesCupertino(BuildContext context) {
|
||||
final material = Localizations.of<MaterialLocalizations>(
|
||||
context,
|
||||
MaterialLocalizations,
|
||||
);
|
||||
return material == null;
|
||||
}
|
||||
bool _usesCupertino(BuildContext context) => _cupertinoLocale(context);
|
||||
|
||||
Future<void> _open() async {
|
||||
final id = runTitleId(widget.run);
|
||||
if (id == null || _dialogOpen) return;
|
||||
if (_dialogOpen) return;
|
||||
_dialogOpen = true;
|
||||
try {
|
||||
await showRunTitlePrompt(
|
||||
context: context,
|
||||
runId: id,
|
||||
initialTitle: storedRunTitle(widget.run),
|
||||
cupertino: _usesCupertino(context),
|
||||
onSubmit: (title) => _submit(id, title),
|
||||
await openRunTitleEditor(
|
||||
context,
|
||||
run: widget.run,
|
||||
gateway: widget.gateway,
|
||||
onRunChanged: widget.onRunChanged,
|
||||
owns: (id) => mounted && runTitleId(widget.run) == id,
|
||||
);
|
||||
} finally {
|
||||
_dialogOpen = false;
|
||||
@@ -60,23 +52,6 @@ class _RunTitleActionState extends State<RunTitleAction> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<ActionRefusal?> _submit(num id, String title) async {
|
||||
if (_saving) return const ActionRefusal(actionAlreadySending);
|
||||
_saving = true;
|
||||
try {
|
||||
final run = await RunsRepository(widget.gateway).setRunTitle(id, title);
|
||||
if (!mounted) return null;
|
||||
if (_owns(id)) widget.onRunChanged(run);
|
||||
return null;
|
||||
} catch (error) {
|
||||
return ActionRefusal(describeTitleError(error));
|
||||
} finally {
|
||||
_saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool _owns(num id) => mounted && runTitleId(widget.run) == id;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (runTitleId(widget.run) == null) return const SizedBox.shrink();
|
||||
@@ -96,6 +71,44 @@ class _RunTitleActionState extends State<RunTitleAction> {
|
||||
}
|
||||
}
|
||||
|
||||
bool _cupertinoLocale(BuildContext context) =>
|
||||
Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) ==
|
||||
null;
|
||||
|
||||
/// Opens the rename prompt for [run]; only Save sends `set_run_title`, and the
|
||||
/// server's returned detail reaches [onRunChanged] while [owns] still holds
|
||||
/// for that run id. Shared by the button and the run detail's more menu.
|
||||
Future<void> openRunTitleEditor(
|
||||
BuildContext context, {
|
||||
required JsonMap run,
|
||||
required ApiGateway gateway,
|
||||
required ValueChanged<JsonMap> onRunChanged,
|
||||
required bool Function(num id) owns,
|
||||
}) async {
|
||||
final id = runTitleId(run);
|
||||
if (id == null) return;
|
||||
var saving = false;
|
||||
await showRunTitlePrompt(
|
||||
context: context,
|
||||
runId: id,
|
||||
initialTitle: storedRunTitle(run),
|
||||
cupertino: _cupertinoLocale(context),
|
||||
onSubmit: (title) async {
|
||||
if (saving) return const ActionRefusal(actionAlreadySending);
|
||||
saving = true;
|
||||
try {
|
||||
final updated = await RunsRepository(gateway).setRunTitle(id, title);
|
||||
if (owns(id)) onRunChanged(updated);
|
||||
return null;
|
||||
} catch (error) {
|
||||
return ActionRefusal(describeTitleError(error));
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// The run id used by the rename request, or null for a malformed run.
|
||||
num? runTitleId(JsonMap run) {
|
||||
final id = run['id'];
|
||||
|
||||
Reference in New Issue
Block a user