From 4d8953cd220318c0dd0eca51bb6d7fdce04140ae Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 20 Nov 2025 21:58:59 +0800 Subject: [PATCH] :sparkles: Site mode --- lib/models/publication_site.dart | 1 + lib/models/publication_site.freezed.dart | 43 +++++++++++---------- lib/models/publication_site.g.dart | 2 + lib/screens/creators/sites/site_edit.dart | 23 +++++++++++ lib/screens/creators/sites/site_list.g.dart | 2 +- 5 files changed, 50 insertions(+), 21 deletions(-) diff --git a/lib/models/publication_site.dart b/lib/models/publication_site.dart index dcaf101c..5daa379a 100644 --- a/lib/models/publication_site.dart +++ b/lib/models/publication_site.dart @@ -10,6 +10,7 @@ sealed class SnPublicationSite with _$SnPublicationSite { required String slug, required String name, String? description, + int? mode, required String publisherId, required String accountId, required DateTime createdAt, diff --git a/lib/models/publication_site.freezed.dart b/lib/models/publication_site.freezed.dart index ebc50834..fa4ce96a 100644 --- a/lib/models/publication_site.freezed.dart +++ b/lib/models/publication_site.freezed.dart @@ -15,7 +15,7 @@ T _$identity(T value) => value; /// @nodoc mixin _$SnPublicationSite { - String get id; String get slug; String get name; String? get description; String get publisherId; String get accountId; DateTime get createdAt; DateTime get updatedAt; List get pages; + String get id; String get slug; String get name; String? get description; int? get mode; String get publisherId; String get accountId; DateTime get createdAt; DateTime get updatedAt; List get pages; /// Create a copy of SnPublicationSite /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -28,16 +28,16 @@ $SnPublicationSiteCopyWith get copyWith => _$SnPublicationSit @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is SnPublicationSite&&(identical(other.id, id) || other.id == id)&&(identical(other.slug, slug) || other.slug == slug)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&(identical(other.publisherId, publisherId) || other.publisherId == publisherId)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&const DeepCollectionEquality().equals(other.pages, pages)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is SnPublicationSite&&(identical(other.id, id) || other.id == id)&&(identical(other.slug, slug) || other.slug == slug)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&(identical(other.mode, mode) || other.mode == mode)&&(identical(other.publisherId, publisherId) || other.publisherId == publisherId)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&const DeepCollectionEquality().equals(other.pages, pages)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,id,slug,name,description,publisherId,accountId,createdAt,updatedAt,const DeepCollectionEquality().hash(pages)); +int get hashCode => Object.hash(runtimeType,id,slug,name,description,mode,publisherId,accountId,createdAt,updatedAt,const DeepCollectionEquality().hash(pages)); @override String toString() { - return 'SnPublicationSite(id: $id, slug: $slug, name: $name, description: $description, publisherId: $publisherId, accountId: $accountId, createdAt: $createdAt, updatedAt: $updatedAt, pages: $pages)'; + return 'SnPublicationSite(id: $id, slug: $slug, name: $name, description: $description, mode: $mode, publisherId: $publisherId, accountId: $accountId, createdAt: $createdAt, updatedAt: $updatedAt, pages: $pages)'; } @@ -48,7 +48,7 @@ abstract mixin class $SnPublicationSiteCopyWith<$Res> { factory $SnPublicationSiteCopyWith(SnPublicationSite value, $Res Function(SnPublicationSite) _then) = _$SnPublicationSiteCopyWithImpl; @useResult $Res call({ - String id, String slug, String name, String? description, String publisherId, String accountId, DateTime createdAt, DateTime updatedAt, List pages + String id, String slug, String name, String? description, int? mode, String publisherId, String accountId, DateTime createdAt, DateTime updatedAt, List pages }); @@ -65,13 +65,14 @@ class _$SnPublicationSiteCopyWithImpl<$Res> /// Create a copy of SnPublicationSite /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? slug = null,Object? name = null,Object? description = freezed,Object? publisherId = null,Object? accountId = null,Object? createdAt = null,Object? updatedAt = null,Object? pages = null,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? slug = null,Object? name = null,Object? description = freezed,Object? mode = freezed,Object? publisherId = null,Object? accountId = null,Object? createdAt = null,Object? updatedAt = null,Object? pages = null,}) { return _then(_self.copyWith( id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,slug: null == slug ? _self.slug : slug // ignore: cast_nullable_to_non_nullable as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable -as String?,publisherId: null == publisherId ? _self.publisherId : publisherId // ignore: cast_nullable_to_non_nullable +as String?,mode: freezed == mode ? _self.mode : mode // ignore: cast_nullable_to_non_nullable +as int?,publisherId: null == publisherId ? _self.publisherId : publisherId // ignore: cast_nullable_to_non_nullable as String,accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable as String,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as DateTime,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable @@ -158,10 +159,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String slug, String name, String? description, String publisherId, String accountId, DateTime createdAt, DateTime updatedAt, List pages)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String slug, String name, String? description, int? mode, String publisherId, String accountId, DateTime createdAt, DateTime updatedAt, List pages)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _SnPublicationSite() when $default != null: -return $default(_that.id,_that.slug,_that.name,_that.description,_that.publisherId,_that.accountId,_that.createdAt,_that.updatedAt,_that.pages);case _: +return $default(_that.id,_that.slug,_that.name,_that.description,_that.mode,_that.publisherId,_that.accountId,_that.createdAt,_that.updatedAt,_that.pages);case _: return orElse(); } @@ -179,10 +180,10 @@ return $default(_that.id,_that.slug,_that.name,_that.description,_that.publisher /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String id, String slug, String name, String? description, String publisherId, String accountId, DateTime createdAt, DateTime updatedAt, List pages) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String id, String slug, String name, String? description, int? mode, String publisherId, String accountId, DateTime createdAt, DateTime updatedAt, List pages) $default,) {final _that = this; switch (_that) { case _SnPublicationSite(): -return $default(_that.id,_that.slug,_that.name,_that.description,_that.publisherId,_that.accountId,_that.createdAt,_that.updatedAt,_that.pages);} +return $default(_that.id,_that.slug,_that.name,_that.description,_that.mode,_that.publisherId,_that.accountId,_that.createdAt,_that.updatedAt,_that.pages);} } /// A variant of `when` that fallback to returning `null` /// @@ -196,10 +197,10 @@ return $default(_that.id,_that.slug,_that.name,_that.description,_that.publisher /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String slug, String name, String? description, String publisherId, String accountId, DateTime createdAt, DateTime updatedAt, List pages)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String slug, String name, String? description, int? mode, String publisherId, String accountId, DateTime createdAt, DateTime updatedAt, List pages)? $default,) {final _that = this; switch (_that) { case _SnPublicationSite() when $default != null: -return $default(_that.id,_that.slug,_that.name,_that.description,_that.publisherId,_that.accountId,_that.createdAt,_that.updatedAt,_that.pages);case _: +return $default(_that.id,_that.slug,_that.name,_that.description,_that.mode,_that.publisherId,_that.accountId,_that.createdAt,_that.updatedAt,_that.pages);case _: return null; } @@ -211,13 +212,14 @@ return $default(_that.id,_that.slug,_that.name,_that.description,_that.publisher @JsonSerializable() class _SnPublicationSite implements SnPublicationSite { - const _SnPublicationSite({required this.id, required this.slug, required this.name, this.description, required this.publisherId, required this.accountId, required this.createdAt, required this.updatedAt, required final List pages}): _pages = pages; + const _SnPublicationSite({required this.id, required this.slug, required this.name, this.description, this.mode, required this.publisherId, required this.accountId, required this.createdAt, required this.updatedAt, required final List pages}): _pages = pages; factory _SnPublicationSite.fromJson(Map json) => _$SnPublicationSiteFromJson(json); @override final String id; @override final String slug; @override final String name; @override final String? description; +@override final int? mode; @override final String publisherId; @override final String accountId; @override final DateTime createdAt; @@ -243,16 +245,16 @@ Map toJson() { @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnPublicationSite&&(identical(other.id, id) || other.id == id)&&(identical(other.slug, slug) || other.slug == slug)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&(identical(other.publisherId, publisherId) || other.publisherId == publisherId)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&const DeepCollectionEquality().equals(other._pages, _pages)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnPublicationSite&&(identical(other.id, id) || other.id == id)&&(identical(other.slug, slug) || other.slug == slug)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&(identical(other.mode, mode) || other.mode == mode)&&(identical(other.publisherId, publisherId) || other.publisherId == publisherId)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&const DeepCollectionEquality().equals(other._pages, _pages)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,id,slug,name,description,publisherId,accountId,createdAt,updatedAt,const DeepCollectionEquality().hash(_pages)); +int get hashCode => Object.hash(runtimeType,id,slug,name,description,mode,publisherId,accountId,createdAt,updatedAt,const DeepCollectionEquality().hash(_pages)); @override String toString() { - return 'SnPublicationSite(id: $id, slug: $slug, name: $name, description: $description, publisherId: $publisherId, accountId: $accountId, createdAt: $createdAt, updatedAt: $updatedAt, pages: $pages)'; + return 'SnPublicationSite(id: $id, slug: $slug, name: $name, description: $description, mode: $mode, publisherId: $publisherId, accountId: $accountId, createdAt: $createdAt, updatedAt: $updatedAt, pages: $pages)'; } @@ -263,7 +265,7 @@ abstract mixin class _$SnPublicationSiteCopyWith<$Res> implements $SnPublication factory _$SnPublicationSiteCopyWith(_SnPublicationSite value, $Res Function(_SnPublicationSite) _then) = __$SnPublicationSiteCopyWithImpl; @override @useResult $Res call({ - String id, String slug, String name, String? description, String publisherId, String accountId, DateTime createdAt, DateTime updatedAt, List pages + String id, String slug, String name, String? description, int? mode, String publisherId, String accountId, DateTime createdAt, DateTime updatedAt, List pages }); @@ -280,13 +282,14 @@ class __$SnPublicationSiteCopyWithImpl<$Res> /// Create a copy of SnPublicationSite /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? slug = null,Object? name = null,Object? description = freezed,Object? publisherId = null,Object? accountId = null,Object? createdAt = null,Object? updatedAt = null,Object? pages = null,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? slug = null,Object? name = null,Object? description = freezed,Object? mode = freezed,Object? publisherId = null,Object? accountId = null,Object? createdAt = null,Object? updatedAt = null,Object? pages = null,}) { return _then(_SnPublicationSite( id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,slug: null == slug ? _self.slug : slug // ignore: cast_nullable_to_non_nullable as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable -as String?,publisherId: null == publisherId ? _self.publisherId : publisherId // ignore: cast_nullable_to_non_nullable +as String?,mode: freezed == mode ? _self.mode : mode // ignore: cast_nullable_to_non_nullable +as int?,publisherId: null == publisherId ? _self.publisherId : publisherId // ignore: cast_nullable_to_non_nullable as String,accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable as String,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as DateTime,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable diff --git a/lib/models/publication_site.g.dart b/lib/models/publication_site.g.dart index 150f3e9d..4f04a2b2 100644 --- a/lib/models/publication_site.g.dart +++ b/lib/models/publication_site.g.dart @@ -12,6 +12,7 @@ _SnPublicationSite _$SnPublicationSiteFromJson(Map json) => slug: json['slug'] as String, name: json['name'] as String, description: json['description'] as String?, + mode: (json['mode'] as num?)?.toInt(), publisherId: json['publisher_id'] as String, accountId: json['account_id'] as String, createdAt: DateTime.parse(json['created_at'] as String), @@ -28,6 +29,7 @@ Map _$SnPublicationSiteToJson(_SnPublicationSite instance) => 'slug': instance.slug, 'name': instance.name, 'description': instance.description, + 'mode': instance.mode, 'publisher_id': instance.publisherId, 'account_id': instance.accountId, 'created_at': instance.createdAt.toIso8601String(), diff --git a/lib/screens/creators/sites/site_edit.dart b/lib/screens/creators/sites/site_edit.dart index 7ee2449b..5640b801 100644 --- a/lib/screens/creators/sites/site_edit.dart +++ b/lib/screens/creators/sites/site_edit.dart @@ -23,6 +23,7 @@ class SiteForm extends HookConsumerWidget { final slugController = useTextEditingController(); final nameController = useTextEditingController(); final descriptionController = useTextEditingController(); + final modeController = useState(0); // Default to fully managed (0) final isLoading = useState(false); final saveSite = useCallback(() async { @@ -36,6 +37,7 @@ class SiteForm extends HookConsumerWidget { final payload = { 'slug': slugController.text, 'name': nameController.text, + 'mode': modeController.value, if (descriptionController.text.isNotEmpty) 'description': descriptionController.text, }; @@ -106,6 +108,7 @@ class SiteForm extends HookConsumerWidget { slugController.text = fetchedSite.slug; nameController.text = fetchedSite.name; descriptionController.text = fetchedSite.description ?? ''; + modeController.value = fetchedSite.mode ?? 0; } } catch (e) { errorMessage.value = e.toString(); @@ -144,6 +147,7 @@ class SiteForm extends HookConsumerWidget { slugController.text = fetchedSite.slug; nameController.text = fetchedSite.name; descriptionController.text = fetchedSite.description ?? ''; + modeController.value = fetchedSite.mode ?? 0; } catch (e) { errorMessage.value = e.toString(); } finally { @@ -213,6 +217,25 @@ class SiteForm extends HookConsumerWidget { onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(), maxLines: 3, ), + const SizedBox(height: 16), + DropdownButtonFormField( + value: modeController.value, + decoration: const InputDecoration( + labelText: 'Mode', + border: OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(12)), + ), + ), + items: const [ + DropdownMenuItem(value: 0, child: Text('Fully Managed')), + DropdownMenuItem(value: 1, child: Text('Self-Managed')), + ], + onChanged: (value) { + if (value != null) { + modeController.value = value; + } + }, + ), ], ).padding(all: 20); diff --git a/lib/screens/creators/sites/site_list.g.dart b/lib/screens/creators/sites/site_list.g.dart index 7aa33630..687c8b10 100644 --- a/lib/screens/creators/sites/site_list.g.dart +++ b/lib/screens/creators/sites/site_list.g.dart @@ -6,7 +6,7 @@ part of 'site_list.dart'; // RiverpodGenerator // ************************************************************************** -String _$siteListNotifierHash() => r'5cd2d75f13b6e7d4910dc66a24bbd6508fc4175d'; +String _$siteListNotifierHash() => r'1670cadcc0c7ccbd98bc33bbf5b4af21e9cb166c'; /// Copied from Dart SDK class _SystemHash {