added theme share error handling for ratelimit response

This commit is contained in:
Kima 2024-10-10 18:11:41 +02:00
parent a50f449f7c
commit f1ba5230fc
4 changed files with 35 additions and 8 deletions

View File

@ -235,7 +235,7 @@ class FilcAPI {
} }
// sharing // sharing
static Future<void> addSharedTheme(SharedTheme theme) async { static Future<int> addSharedTheme(SharedTheme theme) async {
try { try {
theme.json.remove('json'); theme.json.remove('json');
theme.json['is_public'] = theme.isPublic.toString(); theme.json['is_public'] = theme.isPublic.toString();
@ -267,13 +267,17 @@ class FilcAPI {
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, headers: {'Content-Type': 'application/x-www-form-urlencoded'},
); );
if (res.statusCode != 201) { // if (res.statusCode != 201) {
throw "HTTP ${res.statusCode}: ${res.body}"; // throw "HTTP ${res.statusCode}: ${res.body}";
} // }
log('Shared theme successfully with ID: ${theme.id}'); log('Shared theme successfully with ID: ${theme.id}');
return res.statusCode;
} on Exception catch (error, stacktrace) { } on Exception catch (error, stacktrace) {
log("ERROR: FilcAPI.addSharedTheme: $error $stacktrace"); log("ERROR: FilcAPI.addSharedTheme: $error $stacktrace");
return 696;
} }
} }

View File

@ -19,7 +19,7 @@ class ShareProvider extends ChangeNotifier {
// } // }
// themes // themes
Future<SharedTheme> shareCurrentTheme( Future<SharedTheme?> shareCurrentTheme(
BuildContext context, { BuildContext context, {
bool isPublic = false, bool isPublic = false,
bool shareNick = true, bool shareNick = true,
@ -56,9 +56,13 @@ class ShareProvider extends ChangeNotifier {
}; };
SharedTheme theme = SharedTheme.fromJson(themeJson, gradeColors); SharedTheme theme = SharedTheme.fromJson(themeJson, gradeColors);
FilcAPI.addSharedTheme(theme); int shareResult = await FilcAPI.addSharedTheme(theme);
if (shareResult == 200) {
return theme; return theme;
} else {
return null;
}
} }
Future<SharedTheme?> getThemeById(BuildContext context, Future<SharedTheme?> getThemeById(BuildContext context,

View File

@ -5,8 +5,10 @@ import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
// import 'package:refilc/models/settings.dart'; // import 'package:refilc/models/settings.dart';
import 'package:refilc/models/shared_theme.dart'; import 'package:refilc/models/shared_theme.dart';
import 'package:refilc/theme/colors/colors.dart';
import 'package:refilc_kreta_api/providers/share_provider.dart'; import 'package:refilc_kreta_api/providers/share_provider.dart';
import 'package:refilc_mobile_ui/common/action_button.dart'; import 'package:refilc_mobile_ui/common/action_button.dart';
import 'package:refilc_mobile_ui/common/custom_snack_bar.dart';
import 'package:refilc_mobile_ui/common/splitted_panel/splitted_panel.dart'; import 'package:refilc_mobile_ui/common/splitted_panel/splitted_panel.dart';
import 'package:share_plus/share_plus.dart'; import 'package:share_plus/share_plus.dart';
import 'submenu_screen.i18n.dart'; import 'submenu_screen.i18n.dart';
@ -133,13 +135,24 @@ class ShareThemeDialogState extends State<ShareThemeDialog> {
// share the fucking theme // share the fucking theme
SharedGradeColors gradeColors = SharedGradeColors gradeColors =
await shareProvider.shareCurrentGradeColors(context); await shareProvider.shareCurrentGradeColors(context);
SharedTheme theme = await shareProvider.shareCurrentTheme( SharedTheme? theme = await shareProvider.shareCurrentTheme(
context, context,
gradeColors: gradeColors, gradeColors: gradeColors,
isPublic: isPublic, isPublic: isPublic,
displayName: _title.text, displayName: _title.text,
); );
if (theme == null) {
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
content: Text("theme_share_failed".i18n,
style: const TextStyle(color: Colors.white)),
backgroundColor: AppColors.of(context).red,
context: context,
));
return;
}
// save theme id in settings // save theme id in settings
// Provider.of<SettingsProvider>(context, listen: false) // Provider.of<SettingsProvider>(context, listen: false)
// .update(currentThemeId: theme.id); // .update(currentThemeId: theme.id);

View File

@ -30,6 +30,8 @@ extension SettingsLocalization on String {
"share_disclaimer": "share_disclaimer":
"By sharing the theme, you agree that the nickname you set and all settings of the theme will be shared publicly.", "By sharing the theme, you agree that the nickname you set and all settings of the theme will be shared publicly.",
"understand": "I understand", "understand": "I understand",
"theme_share_failed":
"An error occurred while sharing the theme. Wait 1 minute and try again.",
}, },
"hu_hu": { "hu_hu": {
"general": "Általános", "general": "Általános",
@ -58,6 +60,8 @@ extension SettingsLocalization on String {
"share_disclaimer": "share_disclaimer":
"A téma megosztásával elfogadod, hogy az általad beállított becenév és a téma minden beállítása nyilvánosan megosztásra kerüljön.", "A téma megosztásával elfogadod, hogy az általad beállított becenév és a téma minden beállítása nyilvánosan megosztásra kerüljön.",
"understand": "Értem", "understand": "Értem",
"theme_share_failed":
"Hiba történt a téma megosztása közben. Várj 1 percet, majd próbáld újra.",
}, },
"de_de": { "de_de": {
"general": "Allgemeine", "general": "Allgemeine",
@ -86,6 +90,8 @@ extension SettingsLocalization on String {
"share_disclaimer": "share_disclaimer":
"Durch das Teilen des Themes erklären Sie sich damit einverstanden, dass der von Ihnen festgelegte Spitzname und alle Einstellungen des Themes öffentlich geteilt werden.", "Durch das Teilen des Themes erklären Sie sich damit einverstanden, dass der von Ihnen festgelegte Spitzname und alle Einstellungen des Themes öffentlich geteilt werden.",
"understand": "Ich verstehe", "understand": "Ich verstehe",
"theme_share_failed":
"Beim Teilen des Themas ist ein Fehler aufgetreten. Warten Sie 1 Minute und versuchen Sie es erneut.",
}, },
}; };