From 3621ea77441146f5cd3d714142140dd56fbe6b9b Mon Sep 17 00:00:00 2001 From: Texas0295 Date: Sun, 21 Sep 2025 15:23:08 +0800 Subject: [PATCH] support default file pool selection - add defaultPoolId to AppSettings + persistence - extend SettingsScreen with pool dropdown - update uploadAttachment to use defaultPoolId with fallback Signed-off-by: Texas0295 --- assets/i18n/en-US.json | 2 + assets/i18n/zh-CN.json | 2 + assets/i18n/zh-TW.json | 3 ++ lib/pods/config.dart | 12 +++++ lib/pods/config.freezed.dart | 45 ++++++++++--------- lib/pods/config.g.dart | 2 +- lib/screens/chat/room.g.dart | 2 +- lib/screens/notification.g.dart | 4 +- lib/screens/settings.dart | 65 +++++++++++++++++++++++++++- lib/widgets/post/compose_shared.dart | 7 +-- 10 files changed, 116 insertions(+), 28 deletions(-) diff --git a/assets/i18n/en-US.json b/assets/i18n/en-US.json index df3e0db7..43c89616 100644 --- a/assets/i18n/en-US.json +++ b/assets/i18n/en-US.json @@ -30,6 +30,8 @@ "fieldEmailAddressMustBeValid": "The email address must be valid.", "logout": "Logout", "updateYourProfile": "Profile Settings", + "settingsDefaultPool": "Default file pool", + "settingsDefaultPoolHelper": "Select the default storage pool for file uploads", "accountBasicInfo": "Basic Info", "accountProfile": "Your Profile", "saveChanges": "Save Changes", diff --git a/assets/i18n/zh-CN.json b/assets/i18n/zh-CN.json index 91bae0c4..69004ba2 100644 --- a/assets/i18n/zh-CN.json +++ b/assets/i18n/zh-CN.json @@ -123,6 +123,8 @@ "addPhoto": "添加照片", "addFile": "添加文件", "uploadFile": "上传文件", + "settingsDefaultPool": "选择文件池", + "settingsDefaultPoolHelper": "为文件上传选择一个默认池", "createDirectMessage": "创建新私人消息", "gotoDirectMessage": "前往私信", "react": "反应", diff --git a/assets/i18n/zh-TW.json b/assets/i18n/zh-TW.json index 8dac4c3e..e3d6f836 100644 --- a/assets/i18n/zh-TW.json +++ b/assets/i18n/zh-TW.json @@ -123,6 +123,9 @@ "addPhoto": "添加照片", "addFile": "添加文件", "uploadFile": "上傳文件", + "settingsDefaultPool": "選擇文件池", + "settingsDefaultPoolHelper": "爲文件上傳選擇一個默認池", + "createDirectMessage": "創建新私人消息", "gotoDirectMessage": "前往私信", "react": "反應", diff --git a/lib/pods/config.dart b/lib/pods/config.dart index 52def773..0c6eb49a 100644 --- a/lib/pods/config.dart +++ b/lib/pods/config.dart @@ -25,6 +25,7 @@ const kAppSoundEffects = 'app_sound_effects'; const kAppAprilFoolFeatures = 'app_april_fool_features'; const kAppWindowSize = 'app_window_size'; const kAppEnterToSend = 'app_enter_to_send'; +const kAppDefaultPoolId = 'app_default_pool_id'; const kFeaturedPostsCollapsedId = 'featured_posts_collapsed_id'; // Key for storing the ID of the collapsed featured post @@ -65,6 +66,7 @@ sealed class AppSettings with _$AppSettings { required String? customFonts, required int? appColorScheme, // The color stored via the int type required Size? windowSize, // The window size for desktop platforms + required String? defaultPoolId, }) = _AppSettings; } @@ -84,6 +86,7 @@ class AppSettingsNotifier extends _$AppSettingsNotifier { customFonts: prefs.getString(kAppCustomFonts), appColorScheme: prefs.getInt(kAppColorSchemeStoreKey), windowSize: _getWindowSizeFromPrefs(prefs), + defaultPoolId: prefs.getString(kAppDefaultPoolId), ); } @@ -103,6 +106,15 @@ class AppSettingsNotifier extends _$AppSettingsNotifier { } return null; } + void setDefaultPoolId(String? value) { + final prefs = ref.read(sharedPreferencesProvider); + if (value != null) { + prefs.setString(kAppDefaultPoolId, value); + } else { + prefs.remove(kAppDefaultPoolId); + } + state = state.copyWith(defaultPoolId: value); + } void setAutoTranslate(bool value) { final prefs = ref.read(sharedPreferencesProvider); diff --git a/lib/pods/config.freezed.dart b/lib/pods/config.freezed.dart index aa460bb0..95dd93a9 100644 --- a/lib/pods/config.freezed.dart +++ b/lib/pods/config.freezed.dart @@ -15,7 +15,8 @@ T _$identity(T value) => value; mixin _$AppSettings { bool get autoTranslate; bool get dataSavingMode; bool get soundEffects; bool get aprilFoolFeatures; bool get enterToSend; bool get appBarTransparent; bool get showBackgroundImage; String? get customFonts; int? get appColorScheme;// The color stored via the int type - Size? get windowSize; + Size? get windowSize;// The window size for desktop platforms + String? get defaultPoolId; /// Create a copy of AppSettings /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -26,16 +27,16 @@ $AppSettingsCopyWith get copyWith => _$AppSettingsCopyWithImpl Object.hash(runtimeType,autoTranslate,dataSavingMode,soundEffects,aprilFoolFeatures,enterToSend,appBarTransparent,showBackgroundImage,customFonts,appColorScheme,windowSize); +int get hashCode => Object.hash(runtimeType,autoTranslate,dataSavingMode,soundEffects,aprilFoolFeatures,enterToSend,appBarTransparent,showBackgroundImage,customFonts,appColorScheme,windowSize,defaultPoolId); @override String toString() { - return 'AppSettings(autoTranslate: $autoTranslate, dataSavingMode: $dataSavingMode, soundEffects: $soundEffects, aprilFoolFeatures: $aprilFoolFeatures, enterToSend: $enterToSend, appBarTransparent: $appBarTransparent, showBackgroundImage: $showBackgroundImage, customFonts: $customFonts, appColorScheme: $appColorScheme, windowSize: $windowSize)'; + return 'AppSettings(autoTranslate: $autoTranslate, dataSavingMode: $dataSavingMode, soundEffects: $soundEffects, aprilFoolFeatures: $aprilFoolFeatures, enterToSend: $enterToSend, appBarTransparent: $appBarTransparent, showBackgroundImage: $showBackgroundImage, customFonts: $customFonts, appColorScheme: $appColorScheme, windowSize: $windowSize, defaultPoolId: $defaultPoolId)'; } @@ -46,7 +47,7 @@ abstract mixin class $AppSettingsCopyWith<$Res> { factory $AppSettingsCopyWith(AppSettings value, $Res Function(AppSettings) _then) = _$AppSettingsCopyWithImpl; @useResult $Res call({ - bool autoTranslate, bool dataSavingMode, bool soundEffects, bool aprilFoolFeatures, bool enterToSend, bool appBarTransparent, bool showBackgroundImage, String? customFonts, int? appColorScheme, Size? windowSize + bool autoTranslate, bool dataSavingMode, bool soundEffects, bool aprilFoolFeatures, bool enterToSend, bool appBarTransparent, bool showBackgroundImage, String? customFonts, int? appColorScheme, Size? windowSize, String? defaultPoolId }); @@ -63,7 +64,7 @@ class _$AppSettingsCopyWithImpl<$Res> /// Create a copy of AppSettings /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? autoTranslate = null,Object? dataSavingMode = null,Object? soundEffects = null,Object? aprilFoolFeatures = null,Object? enterToSend = null,Object? appBarTransparent = null,Object? showBackgroundImage = null,Object? customFonts = freezed,Object? appColorScheme = freezed,Object? windowSize = freezed,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? autoTranslate = null,Object? dataSavingMode = null,Object? soundEffects = null,Object? aprilFoolFeatures = null,Object? enterToSend = null,Object? appBarTransparent = null,Object? showBackgroundImage = null,Object? customFonts = freezed,Object? appColorScheme = freezed,Object? windowSize = freezed,Object? defaultPoolId = freezed,}) { return _then(_self.copyWith( autoTranslate: null == autoTranslate ? _self.autoTranslate : autoTranslate // ignore: cast_nullable_to_non_nullable as bool,dataSavingMode: null == dataSavingMode ? _self.dataSavingMode : dataSavingMode // ignore: cast_nullable_to_non_nullable @@ -75,7 +76,8 @@ as bool,showBackgroundImage: null == showBackgroundImage ? _self.showBackgroundI as bool,customFonts: freezed == customFonts ? _self.customFonts : customFonts // ignore: cast_nullable_to_non_nullable as String?,appColorScheme: freezed == appColorScheme ? _self.appColorScheme : appColorScheme // ignore: cast_nullable_to_non_nullable as int?,windowSize: freezed == windowSize ? _self.windowSize : windowSize // ignore: cast_nullable_to_non_nullable -as Size?, +as Size?,defaultPoolId: freezed == defaultPoolId ? _self.defaultPoolId : defaultPoolId // ignore: cast_nullable_to_non_nullable +as String?, )); } @@ -157,10 +159,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( bool autoTranslate, bool dataSavingMode, bool soundEffects, bool aprilFoolFeatures, bool enterToSend, bool appBarTransparent, bool showBackgroundImage, String? customFonts, int? appColorScheme, Size? windowSize)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( bool autoTranslate, bool dataSavingMode, bool soundEffects, bool aprilFoolFeatures, bool enterToSend, bool appBarTransparent, bool showBackgroundImage, String? customFonts, int? appColorScheme, Size? windowSize, String? defaultPoolId)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _AppSettings() when $default != null: -return $default(_that.autoTranslate,_that.dataSavingMode,_that.soundEffects,_that.aprilFoolFeatures,_that.enterToSend,_that.appBarTransparent,_that.showBackgroundImage,_that.customFonts,_that.appColorScheme,_that.windowSize);case _: +return $default(_that.autoTranslate,_that.dataSavingMode,_that.soundEffects,_that.aprilFoolFeatures,_that.enterToSend,_that.appBarTransparent,_that.showBackgroundImage,_that.customFonts,_that.appColorScheme,_that.windowSize,_that.defaultPoolId);case _: return orElse(); } @@ -178,10 +180,10 @@ return $default(_that.autoTranslate,_that.dataSavingMode,_that.soundEffects,_tha /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( bool autoTranslate, bool dataSavingMode, bool soundEffects, bool aprilFoolFeatures, bool enterToSend, bool appBarTransparent, bool showBackgroundImage, String? customFonts, int? appColorScheme, Size? windowSize) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( bool autoTranslate, bool dataSavingMode, bool soundEffects, bool aprilFoolFeatures, bool enterToSend, bool appBarTransparent, bool showBackgroundImage, String? customFonts, int? appColorScheme, Size? windowSize, String? defaultPoolId) $default,) {final _that = this; switch (_that) { case _AppSettings(): -return $default(_that.autoTranslate,_that.dataSavingMode,_that.soundEffects,_that.aprilFoolFeatures,_that.enterToSend,_that.appBarTransparent,_that.showBackgroundImage,_that.customFonts,_that.appColorScheme,_that.windowSize);} +return $default(_that.autoTranslate,_that.dataSavingMode,_that.soundEffects,_that.aprilFoolFeatures,_that.enterToSend,_that.appBarTransparent,_that.showBackgroundImage,_that.customFonts,_that.appColorScheme,_that.windowSize,_that.defaultPoolId);} } /// A variant of `when` that fallback to returning `null` /// @@ -195,10 +197,10 @@ return $default(_that.autoTranslate,_that.dataSavingMode,_that.soundEffects,_tha /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( bool autoTranslate, bool dataSavingMode, bool soundEffects, bool aprilFoolFeatures, bool enterToSend, bool appBarTransparent, bool showBackgroundImage, String? customFonts, int? appColorScheme, Size? windowSize)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( bool autoTranslate, bool dataSavingMode, bool soundEffects, bool aprilFoolFeatures, bool enterToSend, bool appBarTransparent, bool showBackgroundImage, String? customFonts, int? appColorScheme, Size? windowSize, String? defaultPoolId)? $default,) {final _that = this; switch (_that) { case _AppSettings() when $default != null: -return $default(_that.autoTranslate,_that.dataSavingMode,_that.soundEffects,_that.aprilFoolFeatures,_that.enterToSend,_that.appBarTransparent,_that.showBackgroundImage,_that.customFonts,_that.appColorScheme,_that.windowSize);case _: +return $default(_that.autoTranslate,_that.dataSavingMode,_that.soundEffects,_that.aprilFoolFeatures,_that.enterToSend,_that.appBarTransparent,_that.showBackgroundImage,_that.customFonts,_that.appColorScheme,_that.windowSize,_that.defaultPoolId);case _: return null; } @@ -210,7 +212,7 @@ return $default(_that.autoTranslate,_that.dataSavingMode,_that.soundEffects,_tha class _AppSettings implements AppSettings { - const _AppSettings({required this.autoTranslate, required this.dataSavingMode, required this.soundEffects, required this.aprilFoolFeatures, required this.enterToSend, required this.appBarTransparent, required this.showBackgroundImage, required this.customFonts, required this.appColorScheme, required this.windowSize}); + const _AppSettings({required this.autoTranslate, required this.dataSavingMode, required this.soundEffects, required this.aprilFoolFeatures, required this.enterToSend, required this.appBarTransparent, required this.showBackgroundImage, required this.customFonts, required this.appColorScheme, required this.windowSize, required this.defaultPoolId}); @override final bool autoTranslate; @@ -224,6 +226,8 @@ class _AppSettings implements AppSettings { @override final int? appColorScheme; // The color stored via the int type @override final Size? windowSize; +// The window size for desktop platforms +@override final String? defaultPoolId; /// Create a copy of AppSettings /// with the given fields replaced by the non-null parameter values. @@ -235,16 +239,16 @@ _$AppSettingsCopyWith<_AppSettings> get copyWith => __$AppSettingsCopyWithImpl<_ @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _AppSettings&&(identical(other.autoTranslate, autoTranslate) || other.autoTranslate == autoTranslate)&&(identical(other.dataSavingMode, dataSavingMode) || other.dataSavingMode == dataSavingMode)&&(identical(other.soundEffects, soundEffects) || other.soundEffects == soundEffects)&&(identical(other.aprilFoolFeatures, aprilFoolFeatures) || other.aprilFoolFeatures == aprilFoolFeatures)&&(identical(other.enterToSend, enterToSend) || other.enterToSend == enterToSend)&&(identical(other.appBarTransparent, appBarTransparent) || other.appBarTransparent == appBarTransparent)&&(identical(other.showBackgroundImage, showBackgroundImage) || other.showBackgroundImage == showBackgroundImage)&&(identical(other.customFonts, customFonts) || other.customFonts == customFonts)&&(identical(other.appColorScheme, appColorScheme) || other.appColorScheme == appColorScheme)&&(identical(other.windowSize, windowSize) || other.windowSize == windowSize)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _AppSettings&&(identical(other.autoTranslate, autoTranslate) || other.autoTranslate == autoTranslate)&&(identical(other.dataSavingMode, dataSavingMode) || other.dataSavingMode == dataSavingMode)&&(identical(other.soundEffects, soundEffects) || other.soundEffects == soundEffects)&&(identical(other.aprilFoolFeatures, aprilFoolFeatures) || other.aprilFoolFeatures == aprilFoolFeatures)&&(identical(other.enterToSend, enterToSend) || other.enterToSend == enterToSend)&&(identical(other.appBarTransparent, appBarTransparent) || other.appBarTransparent == appBarTransparent)&&(identical(other.showBackgroundImage, showBackgroundImage) || other.showBackgroundImage == showBackgroundImage)&&(identical(other.customFonts, customFonts) || other.customFonts == customFonts)&&(identical(other.appColorScheme, appColorScheme) || other.appColorScheme == appColorScheme)&&(identical(other.windowSize, windowSize) || other.windowSize == windowSize)&&(identical(other.defaultPoolId, defaultPoolId) || other.defaultPoolId == defaultPoolId)); } @override -int get hashCode => Object.hash(runtimeType,autoTranslate,dataSavingMode,soundEffects,aprilFoolFeatures,enterToSend,appBarTransparent,showBackgroundImage,customFonts,appColorScheme,windowSize); +int get hashCode => Object.hash(runtimeType,autoTranslate,dataSavingMode,soundEffects,aprilFoolFeatures,enterToSend,appBarTransparent,showBackgroundImage,customFonts,appColorScheme,windowSize,defaultPoolId); @override String toString() { - return 'AppSettings(autoTranslate: $autoTranslate, dataSavingMode: $dataSavingMode, soundEffects: $soundEffects, aprilFoolFeatures: $aprilFoolFeatures, enterToSend: $enterToSend, appBarTransparent: $appBarTransparent, showBackgroundImage: $showBackgroundImage, customFonts: $customFonts, appColorScheme: $appColorScheme, windowSize: $windowSize)'; + return 'AppSettings(autoTranslate: $autoTranslate, dataSavingMode: $dataSavingMode, soundEffects: $soundEffects, aprilFoolFeatures: $aprilFoolFeatures, enterToSend: $enterToSend, appBarTransparent: $appBarTransparent, showBackgroundImage: $showBackgroundImage, customFonts: $customFonts, appColorScheme: $appColorScheme, windowSize: $windowSize, defaultPoolId: $defaultPoolId)'; } @@ -255,7 +259,7 @@ abstract mixin class _$AppSettingsCopyWith<$Res> implements $AppSettingsCopyWith factory _$AppSettingsCopyWith(_AppSettings value, $Res Function(_AppSettings) _then) = __$AppSettingsCopyWithImpl; @override @useResult $Res call({ - bool autoTranslate, bool dataSavingMode, bool soundEffects, bool aprilFoolFeatures, bool enterToSend, bool appBarTransparent, bool showBackgroundImage, String? customFonts, int? appColorScheme, Size? windowSize + bool autoTranslate, bool dataSavingMode, bool soundEffects, bool aprilFoolFeatures, bool enterToSend, bool appBarTransparent, bool showBackgroundImage, String? customFonts, int? appColorScheme, Size? windowSize, String? defaultPoolId }); @@ -272,7 +276,7 @@ class __$AppSettingsCopyWithImpl<$Res> /// Create a copy of AppSettings /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? autoTranslate = null,Object? dataSavingMode = null,Object? soundEffects = null,Object? aprilFoolFeatures = null,Object? enterToSend = null,Object? appBarTransparent = null,Object? showBackgroundImage = null,Object? customFonts = freezed,Object? appColorScheme = freezed,Object? windowSize = freezed,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? autoTranslate = null,Object? dataSavingMode = null,Object? soundEffects = null,Object? aprilFoolFeatures = null,Object? enterToSend = null,Object? appBarTransparent = null,Object? showBackgroundImage = null,Object? customFonts = freezed,Object? appColorScheme = freezed,Object? windowSize = freezed,Object? defaultPoolId = freezed,}) { return _then(_AppSettings( autoTranslate: null == autoTranslate ? _self.autoTranslate : autoTranslate // ignore: cast_nullable_to_non_nullable as bool,dataSavingMode: null == dataSavingMode ? _self.dataSavingMode : dataSavingMode // ignore: cast_nullable_to_non_nullable @@ -284,7 +288,8 @@ as bool,showBackgroundImage: null == showBackgroundImage ? _self.showBackgroundI as bool,customFonts: freezed == customFonts ? _self.customFonts : customFonts // ignore: cast_nullable_to_non_nullable as String?,appColorScheme: freezed == appColorScheme ? _self.appColorScheme : appColorScheme // ignore: cast_nullable_to_non_nullable as int?,windowSize: freezed == windowSize ? _self.windowSize : windowSize // ignore: cast_nullable_to_non_nullable -as Size?, +as Size?,defaultPoolId: freezed == defaultPoolId ? _self.defaultPoolId : defaultPoolId // ignore: cast_nullable_to_non_nullable +as String?, )); } diff --git a/lib/pods/config.g.dart b/lib/pods/config.g.dart index 1d9731cc..7af42646 100644 --- a/lib/pods/config.g.dart +++ b/lib/pods/config.g.dart @@ -7,7 +7,7 @@ part of 'config.dart'; // ************************************************************************** String _$appSettingsNotifierHash() => - r'cd18bff2614a94e3523634e6c577cefad0367eba'; + r'a623ad859b71f42d0527b7f8b75bd37a6fd5d5c7'; /// See also [AppSettingsNotifier]. @ProviderFor(AppSettingsNotifier) diff --git a/lib/screens/chat/room.g.dart b/lib/screens/chat/room.g.dart index 079eae90..7836dfdd 100644 --- a/lib/screens/chat/room.g.dart +++ b/lib/screens/chat/room.g.dart @@ -6,7 +6,7 @@ part of 'room.dart'; // RiverpodGenerator // ************************************************************************** -String _$messagesNotifierHash() => r'fc3b66dfb8dd3fc55d142dae5c5e7bdc67eca5d4'; +String _$messagesNotifierHash() => r'82a91344328ec44dfe934c80a4a770431d864bff'; /// Copied from Dart SDK class _SystemHash { diff --git a/lib/screens/notification.g.dart b/lib/screens/notification.g.dart index 28604162..381a30f4 100644 --- a/lib/screens/notification.g.dart +++ b/lib/screens/notification.g.dart @@ -7,7 +7,7 @@ part of 'notification.dart'; // ************************************************************************** String _$notificationUnreadCountNotifierHash() => - r'0763b66bd64e5a9b7c317887e109ab367515dfa4'; + r'08c773809958d96a7ce82acf04af1f9e0b23e119'; /// See also [NotificationUnreadCountNotifier]. @ProviderFor(NotificationUnreadCountNotifier) @@ -28,7 +28,7 @@ final notificationUnreadCountNotifierProvider = typedef _$NotificationUnreadCountNotifier = AutoDisposeAsyncNotifier; String _$notificationListNotifierHash() => - r'5099466db475bbcf1ab6b514eb072f1dc4c6f930'; + r'260046e11f45b0d67ab25bcbdc8604890d71ccc7'; /// See also [NotificationListNotifier]. @ProviderFor(NotificationListNotifier) diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index c818d5ac..dcce6205 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -20,6 +20,7 @@ import 'package:material_symbols_icons/symbols.dart'; import 'package:path_provider/path_provider.dart'; import 'package:styled_widget/styled_widget.dart'; import 'package:island/pods/config.dart'; +import 'package:island/pods/pool_provider.dart'; class SettingsScreen extends HookConsumerWidget { const SettingsScreen({super.key}); @@ -33,7 +34,7 @@ class SettingsScreen extends HookConsumerWidget { final isDesktop = !kIsWeb && (Platform.isWindows || Platform.isMacOS || Platform.isLinux); final isWide = isWideScreen(context); - + final poolsAsync = ref.watch(poolsProvider); final docBasepath = useState(null); useEffect(() { @@ -367,6 +368,68 @@ class SettingsScreen extends HookConsumerWidget { ), ), ), + poolsAsync.when( + data: (pools) { + return ListTile( + isThreeLine: true, + minLeadingWidth: 48, + title: Text('settingsDefaultPool').tr(), + contentPadding: const EdgeInsets.only(left: 24, right: 17), + leading: const Icon(Symbols.cloud), + subtitle: Text( + settings.defaultPoolId != null + ? pools + .firstWhereOrNull( + (p) => p.id == settings.defaultPoolId, + ) + ?.description ?? + 'settingsDefaultPoolHelper'.tr() + : 'settingsDefaultPoolHelper'.tr(), + style: Theme.of(context).textTheme.bodySmall, + ), + trailing: DropdownButtonHideUnderline( + child: DropdownButton2( + isExpanded: true, + items: + pools.map((p) { + return DropdownMenuItem( + value: p.id, + child: Text(p.name).fontSize(14), + ); + }).toList(), + value: + settings.defaultPoolId ?? + (pools.isNotEmpty ? pools.first.id : null), + onChanged: (value) { + ref + .read(appSettingsNotifierProvider.notifier) + .setDefaultPoolId(value); + showSnackBar('settingsApplied'.tr()); + }, + buttonStyleData: const ButtonStyleData( + padding: EdgeInsets.symmetric(horizontal: 16, vertical: 5), + height: 40, + width: 220, + ), + menuItemStyleData: const MenuItemStyleData(height: 40), + ), + ), + ); + }, + loading: + () => const ListTile( + minLeadingWidth: 48, + title: Text('Loading pools...'), + leading: CircularProgressIndicator(), + ), + error: + (err, st) => ListTile( + minLeadingWidth: 48, + title: Text('settingsDefaultPool').tr(), + subtitle: Text('Error: $err'), + leading: const Icon(Icons.error, color: Colors.red), + ), + ), ]; final behaviorSettings = [ diff --git a/lib/widgets/post/compose_shared.dart b/lib/widgets/post/compose_shared.dart index 1684ce9f..c30df65a 100644 --- a/lib/widgets/post/compose_shared.dart +++ b/lib/widgets/post/compose_shared.dart @@ -505,7 +505,7 @@ class ComposeLogic { WidgetRef ref, ComposeState state, int index, { - String? poolId, + String? poolId, // For Unit Test }) async { final attachment = state.attachments.value[index]; if (attachment.isOnCloud) return; @@ -522,14 +522,15 @@ class ComposeLogic { SnCloudFile? cloudFile; + final settings = ref.watch(appSettingsNotifierProvider); + final selectedPoolId = poolId ?? settings.defaultPoolId ?? '500e5ed8-bd44-4359-bc0a-ec85e2adf447'; if (attachment.type == UniversalFileType.file) { cloudFile = await putFileToPool( fileData: attachment, atk: token, baseUrl: baseUrl, - // TODO: Generic Pool ID (Now: Solian Network Driver) - poolId: poolId ?? '500e5ed8-bd44-4359-bc0a-ec85e2adf447', + poolId: selectedPoolId, filename: attachment.data.name ?? 'General file', mimetype: attachment.data.mimeType ??