working error handling for theme sharing

This commit is contained in:
Kima
2024-10-10 20:48:21 +02:00
parent f1ba5230fc
commit 939761695f
4 changed files with 72 additions and 27 deletions

View File

@@ -133,16 +133,19 @@ class ShareThemeDialogState extends State<ShareThemeDialog> {
),
onPressed: () async {
// share the fucking theme
SharedGradeColors gradeColors =
var (gradeColors, gradeColorsStatus) =
await shareProvider.shareCurrentGradeColors(context);
SharedTheme? theme = await shareProvider.shareCurrentTheme(
context,
gradeColors: gradeColors,
isPublic: isPublic,
displayName: _title.text,
);
if (theme == null) {
if (gradeColorsStatus == 429) {
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
content: Text("theme_share_ratelimit".i18n,
style: const TextStyle(color: Colors.white)),
backgroundColor: AppColors.of(context).red,
context: context,
));
return;
} else if (gradeColorsStatus != 201) {
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
content: Text("theme_share_failed".i18n,
style: const TextStyle(color: Colors.white)),
@@ -153,6 +156,36 @@ class ShareThemeDialogState extends State<ShareThemeDialog> {
return;
}
var (theme, themeStatus) = await shareProvider.shareCurrentTheme(
context,
gradeColors: gradeColors!,
isPublic: isPublic,
displayName: _title.text,
);
if (themeStatus == 429) {
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
content: Text("theme_share_ratelimit".i18n,
style: const TextStyle(color: Colors.white)),
backgroundColor: AppColors.of(context).red,
context: context,
));
return;
} else if (themeStatus != 201) {
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;
}
print(theme);
print(themeStatus);
// save theme id in settings
// Provider.of<SettingsProvider>(context, listen: false)
// .update(currentThemeId: theme.id);
@@ -162,7 +195,7 @@ class ShareThemeDialogState extends State<ShareThemeDialog> {
// show the share popup
Share.share(
theme.id,
theme!.id,
subject: 'share_subj_theme'.i18n,
);
},

View File

@@ -30,8 +30,8 @@ extension SettingsLocalization on String {
"share_disclaimer":
"By sharing the theme, you agree that the nickname you set and all settings of the theme will be shared publicly.",
"understand": "I understand",
"theme_share_failed":
"An error occurred while sharing the theme. Wait 1 minute and try again.",
"theme_share_failed": "An error occurred while sharing the theme.",
"theme_share_ratelimit": "You can only share 1 theme per minute.",
},
"hu_hu": {
"general": "Általános",
@@ -60,8 +60,8 @@ extension SettingsLocalization on String {
"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.",
"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.",
"theme_share_failed": "Hiba történt a téma megosztása közben.",
"theme_share_ratelimit": "Csak 1 témát oszthatsz meg percenként.",
},
"de_de": {
"general": "Allgemeine",
@@ -91,7 +91,8 @@ extension SettingsLocalization on String {
"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",
"theme_share_failed":
"Beim Teilen des Themas ist ein Fehler aufgetreten. Warten Sie 1 Minute und versuchen Sie es erneut.",
"Beim Teilen des Themas ist ein Fehler aufgetreten.",
"theme_share_ratelimit": "Sie können nur 1 Thema pro Minute teilen.",
},
};