Skip to content

Commit

Permalink
feat: Propose import on Lineup edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Oct 23, 2024
1 parent ddaa3e0 commit 4e10a6d
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 78 deletions.
8 changes: 5 additions & 3 deletions wrestling_scoreboard_client/lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"apiProvider": "API-Anbieter",
"importFromApiProvider": "Synchronisiere mit API-Anbieter",
"warningImportFromApiProvider": "Diese Aktion importiert Objekte dieser Organisation und versucht diese zu integrieren. Bist du sicher, dass du fortfahren möchtest?",
"recommendFirstImportFromApiProvider": "Der letzte Import konnte nicht bestimmt werden. Möchtest du die Daten importieren?",
"recommendImportFromApiProvider": "Der letzte Import war am {date} um {time} Uhr. Möchtest du die Daten aktualisieren?",
"@recommendImportFromApiProvider": {
"proposeFirstImportFromApiProvider": "Der letzte Import konnte nicht bestimmt werden. Möchtest du die Daten importieren?",
"proposeImportFromApiProvider": "Der letzte Import war am {date} um {time} Uhr. Möchtest du die Daten aktualisieren?",
"@proposeImportFromApiProvider": {
"placeholders": {
"date": {
"type": "DateTime",
Expand All @@ -38,6 +38,7 @@
}
}
},
"proposeApiImportDuration": "Dauer für den Vorschlag eines API-Imports",
"reportProvider": "Report-Anbieter",
"database": "Datenbank",
"exportDatabase": "Datenbank exportieren",
Expand Down Expand Up @@ -232,6 +233,7 @@
"injuryDuration": "Dauer der Verletzungszeit",
"bleedingInjuryDuration": "Dauer der Verletzungszeit mit Blut",
"periodCount": "Anzahl der Kampfabschnitte",
"days": "Days",

"referee": "Kampfrichter",
"refereeAbbr": "SR",
Expand Down
8 changes: 5 additions & 3 deletions wrestling_scoreboard_client/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"apiProvider": "API Provider",
"importFromApiProvider": "Sync with API provider",
"warningImportFromApiProvider": "This action imports objects of this organization and tries to integrate them. Are you sure, you want to continue?",
"recommendFirstImportFromApiProvider": "Cannot determine the last import. Would you like import the data?",
"recommendImportFromApiProvider": "The last import was on {date} at {time}. Would you like to update the data?",
"@recommendImportFromApiProvider": {
"proposeFirstImportFromApiProvider": "Cannot determine the last import. Would you like import the data?",
"proposeImportFromApiProvider": "The last import was on {date} at {time}. Would you like to update the data?",
"@proposeImportFromApiProvider": {
"placeholders": {
"date": {
"type": "DateTime",
Expand All @@ -41,6 +41,7 @@
}
}
},
"proposeApiImportDuration": "Duration for proposing an API import",
"reportProvider": "Report Provider",
"database": "Database",
"exportDatabase": "Export database",
Expand Down Expand Up @@ -235,6 +236,7 @@
"injuryDuration": "Injury duration",
"bleedingInjuryDuration": "Bleeding injury duration",
"periodCount": "Number of periods",
"days": "Days",

"referee": "Referee",
"refereeAbbr": "REF",
Expand Down
9 changes: 9 additions & 0 deletions wrestling_scoreboard_client/lib/localization/duration.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

extension DurationLocalization on Duration {
String formatDaysHoursMinutes(BuildContext context) {
final localizations = AppLocalizations.of(context)!;
return '$inDays ${localizations.days}, ${inHours.remainder(24).toString().padLeft(2, '0')}:${inMinutes.remainder(60).toString().padLeft(2, '0')}';
}

String formatMinutesAndSeconds() {
return '$inMinutes:${inSeconds.remainder(60).toString().padLeft(2, '0')}';
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Preferences {
/// Network timeout in milliseconds.
static const keyNetworkTimeout = 'network-timeout';

static const keyProposeApiImportDuration = 'propose-api-import-duration';

static const keyBellSound = 'bell-sound';
static const keyFontFamily = 'font-family';
static const keyFavorites = 'favorites';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,22 @@ class OrgAuthNotifier extends _$OrgAuthNotifier {
}
}

@Riverpod(keepAlive: true)
class ProposeApiImportDurationNotifier extends _$ProposeApiImportDurationNotifier {
@override
Raw<Future<Duration>> build() async {
var proposeApiImportDurationSecs = await Preferences.getInt(Preferences.keyProposeApiImportDuration);
return proposeApiImportDurationSecs != null
? Duration(seconds: proposeApiImportDurationSecs)
: const Duration(days: 2);
}

Future<void> setState(Duration? val) async {
Preferences.setInt(Preferences.keyProposeApiImportDuration, val?.inSeconds);
state = Future.value(val);
}
}

@Riverpod(keepAlive: true)
class JwtNotifier extends _$JwtNotifier {
@override
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 41 additions & 8 deletions wrestling_scoreboard_client/lib/view/screens/more/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,47 @@ class CustomSettingsScreen extends ConsumerWidget {
);
},
),
Restricted(
privilege: UserPrivilege.write,
child: LoadingBuilder<Duration>(
future: ref.watch(proposeApiImportDurationNotifierProvider),
builder: (context, proposeApiImportDuration) {
return SettingsSection(
title: localizations.services,
action: TextButton(
onPressed: () async {
proposeApiImportDuration = const Duration(days: 2);
await ref
.read(proposeApiImportDurationNotifierProvider.notifier)
.setState(proposeApiImportDuration);
},
child: Text(localizations.reset),
),
children: [
ListTile(
leading: const Icon(Icons.timelapse),
title: Text(localizations.proposeApiImportDuration),
subtitle: Text(proposeApiImportDuration.formatDaysHoursMinutes(context)),
onTap: () async {
final val = await showDialog<Duration?>(
context: context,
builder: (BuildContext context) {
// TODO: Allow days in duration picker
return DurationDialog(
initialValue: proposeApiImportDuration,
maxValue: const Duration(days: 365),
);
},
);
if (val != null) {
await ref.read(proposeApiImportDurationNotifierProvider.notifier).setState(val);
}
},
),
],
);
}),
),
LoadingBuilder<Duration>(
future: ref.watch(networkTimeoutNotifierProvider),
builder: (context, networkTimeout) {
Expand Down Expand Up @@ -293,14 +334,6 @@ class CustomSettingsScreen extends ConsumerWidget {
);
},
),
// SettingsSection(
// title: localizations.services,
// action: TextButton(
// onPressed: () {},
// child: Text(localizations.reset),
// ),
// children: [],
// ),
Restricted(
privilege: UserPrivilege.admin,
child: SettingsSection(
Expand Down
Loading

0 comments on commit 4e10a6d

Please sign in to comment.