diff --git a/assets/i18n/en-US.json b/assets/i18n/en-US.json index bd3c2ca..c4fcf0c 100644 --- a/assets/i18n/en-US.json +++ b/assets/i18n/en-US.json @@ -27,6 +27,13 @@ "logout": "Logout", "updateYourProfile": "Edit Profile", "accountBasicInfo": "Basic Info", - "accountProfile": "Profile", - "saveChanges": "Save Changes" + "saveChanges": "Save Changes", + "publishers": "Publishers", + "managedPublisher": "Managed Publishers", + "createPublisher": "Create a Publisher", + "editPublisher": "Edit a Publisher", + "syncPublisher": "Use Account Data", + "create": "Create", + "edit": "Edit", + "delete": "Delete" } diff --git a/lib/models/post.dart b/lib/models/post.dart index 3ffb269..832db4a 100644 --- a/lib/models/post.dart +++ b/lib/models/post.dart @@ -16,7 +16,7 @@ abstract class SnPost with _$SnPost { required int visibility, required String content, required int type, - required dynamic meta, + required Map? meta, required int viewsUnique, required int viewsTotal, required int upvotes, @@ -50,8 +50,8 @@ abstract class SnPublisher with _$SnPublisher { required String name, required String nick, required String bio, - required SnCloudFile picture, - required SnCloudFile background, + required SnCloudFile? picture, + required SnCloudFile? background, required int accountId, required DateTime createdAt, required DateTime updatedAt, diff --git a/lib/models/post.freezed.dart b/lib/models/post.freezed.dart index c52c0bf..f023334 100644 --- a/lib/models/post.freezed.dart +++ b/lib/models/post.freezed.dart @@ -16,7 +16,7 @@ T _$identity(T value) => value; /// @nodoc mixin _$SnPost { - int get id; String get title; String get description; dynamic get language; dynamic get editedAt; DateTime get publishedAt; int get visibility; String get content; int get type; dynamic get meta; int get viewsUnique; int get viewsTotal; int get upvotes; int get downvotes; dynamic get threadedPostId; dynamic get threadedPost; dynamic get repliedPostId; dynamic get repliedPost; dynamic get forwardedPostId; dynamic get forwardedPost; List get attachments; SnPublisher get publisher; List get reactions; List get tags; List get categories; List get collections; bool get empty; DateTime get createdAt; DateTime get updatedAt; dynamic get deletedAt; + int get id; String get title; String get description; dynamic get language; dynamic get editedAt; DateTime get publishedAt; int get visibility; String get content; int get type; Map? get meta; int get viewsUnique; int get viewsTotal; int get upvotes; int get downvotes; dynamic get threadedPostId; dynamic get threadedPost; dynamic get repliedPostId; dynamic get repliedPost; dynamic get forwardedPostId; dynamic get forwardedPost; List get attachments; SnPublisher get publisher; List get reactions; List get tags; List get categories; List get collections; bool get empty; DateTime get createdAt; DateTime get updatedAt; dynamic get deletedAt; /// Create a copy of SnPost /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -49,7 +49,7 @@ abstract mixin class $SnPostCopyWith<$Res> { factory $SnPostCopyWith(SnPost value, $Res Function(SnPost) _then) = _$SnPostCopyWithImpl; @useResult $Res call({ - int id, String title, String description, dynamic language, dynamic editedAt, DateTime publishedAt, int visibility, String content, int type, dynamic meta, int viewsUnique, int viewsTotal, int upvotes, int downvotes, dynamic threadedPostId, dynamic threadedPost, dynamic repliedPostId, dynamic repliedPost, dynamic forwardedPostId, dynamic forwardedPost, List attachments, SnPublisher publisher, List reactions, List tags, List categories, List collections, bool empty, DateTime createdAt, DateTime updatedAt, dynamic deletedAt + int id, String title, String description, dynamic language, dynamic editedAt, DateTime publishedAt, int visibility, String content, int type, Map? meta, int viewsUnique, int viewsTotal, int upvotes, int downvotes, dynamic threadedPostId, dynamic threadedPost, dynamic repliedPostId, dynamic repliedPost, dynamic forwardedPostId, dynamic forwardedPost, List attachments, SnPublisher publisher, List reactions, List tags, List categories, List collections, bool empty, DateTime createdAt, DateTime updatedAt, dynamic deletedAt }); @@ -78,7 +78,7 @@ as DateTime,visibility: null == visibility ? _self.visibility : visibility // ig as int,content: null == content ? _self.content : content // ignore: cast_nullable_to_non_nullable as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable as int,meta: freezed == meta ? _self.meta : meta // ignore: cast_nullable_to_non_nullable -as dynamic,viewsUnique: null == viewsUnique ? _self.viewsUnique : viewsUnique // ignore: cast_nullable_to_non_nullable +as Map?,viewsUnique: null == viewsUnique ? _self.viewsUnique : viewsUnique // ignore: cast_nullable_to_non_nullable as int,viewsTotal: null == viewsTotal ? _self.viewsTotal : viewsTotal // ignore: cast_nullable_to_non_nullable as int,upvotes: null == upvotes ? _self.upvotes : upvotes // ignore: cast_nullable_to_non_nullable as int,downvotes: null == downvotes ? _self.downvotes : downvotes // ignore: cast_nullable_to_non_nullable @@ -118,7 +118,7 @@ $SnPublisherCopyWith<$Res> get publisher { @JsonSerializable() class _SnPost implements SnPost { - const _SnPost({required this.id, required this.title, required this.description, required this.language, required this.editedAt, required this.publishedAt, required this.visibility, required this.content, required this.type, required this.meta, required this.viewsUnique, required this.viewsTotal, required this.upvotes, required this.downvotes, required this.threadedPostId, required this.threadedPost, required this.repliedPostId, required this.repliedPost, required this.forwardedPostId, required this.forwardedPost, required final List attachments, required this.publisher, required final List reactions, required final List tags, required final List categories, required final List collections, required this.empty, required this.createdAt, required this.updatedAt, required this.deletedAt}): _attachments = attachments,_reactions = reactions,_tags = tags,_categories = categories,_collections = collections; + const _SnPost({required this.id, required this.title, required this.description, required this.language, required this.editedAt, required this.publishedAt, required this.visibility, required this.content, required this.type, required final Map? meta, required this.viewsUnique, required this.viewsTotal, required this.upvotes, required this.downvotes, required this.threadedPostId, required this.threadedPost, required this.repliedPostId, required this.repliedPost, required this.forwardedPostId, required this.forwardedPost, required final List attachments, required this.publisher, required final List reactions, required final List tags, required final List categories, required final List collections, required this.empty, required this.createdAt, required this.updatedAt, required this.deletedAt}): _meta = meta,_attachments = attachments,_reactions = reactions,_tags = tags,_categories = categories,_collections = collections; factory _SnPost.fromJson(Map json) => _$SnPostFromJson(json); @override final int id; @@ -130,7 +130,15 @@ class _SnPost implements SnPost { @override final int visibility; @override final String content; @override final int type; -@override final dynamic meta; + final Map? _meta; +@override Map? get meta { + final value = _meta; + if (value == null) return null; + if (_meta is EqualUnmodifiableMapView) return _meta; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); +} + @override final int viewsUnique; @override final int viewsTotal; @override final int upvotes; @@ -195,12 +203,12 @@ Map toJson() { @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnPost&&(identical(other.id, id) || other.id == id)&&(identical(other.title, title) || other.title == title)&&(identical(other.description, description) || other.description == description)&&const DeepCollectionEquality().equals(other.language, language)&&const DeepCollectionEquality().equals(other.editedAt, editedAt)&&(identical(other.publishedAt, publishedAt) || other.publishedAt == publishedAt)&&(identical(other.visibility, visibility) || other.visibility == visibility)&&(identical(other.content, content) || other.content == content)&&(identical(other.type, type) || other.type == type)&&const DeepCollectionEquality().equals(other.meta, meta)&&(identical(other.viewsUnique, viewsUnique) || other.viewsUnique == viewsUnique)&&(identical(other.viewsTotal, viewsTotal) || other.viewsTotal == viewsTotal)&&(identical(other.upvotes, upvotes) || other.upvotes == upvotes)&&(identical(other.downvotes, downvotes) || other.downvotes == downvotes)&&const DeepCollectionEquality().equals(other.threadedPostId, threadedPostId)&&const DeepCollectionEquality().equals(other.threadedPost, threadedPost)&&const DeepCollectionEquality().equals(other.repliedPostId, repliedPostId)&&const DeepCollectionEquality().equals(other.repliedPost, repliedPost)&&const DeepCollectionEquality().equals(other.forwardedPostId, forwardedPostId)&&const DeepCollectionEquality().equals(other.forwardedPost, forwardedPost)&&const DeepCollectionEquality().equals(other._attachments, _attachments)&&(identical(other.publisher, publisher) || other.publisher == publisher)&&const DeepCollectionEquality().equals(other._reactions, _reactions)&&const DeepCollectionEquality().equals(other._tags, _tags)&&const DeepCollectionEquality().equals(other._categories, _categories)&&const DeepCollectionEquality().equals(other._collections, _collections)&&(identical(other.empty, empty) || other.empty == empty)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&const DeepCollectionEquality().equals(other.deletedAt, deletedAt)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnPost&&(identical(other.id, id) || other.id == id)&&(identical(other.title, title) || other.title == title)&&(identical(other.description, description) || other.description == description)&&const DeepCollectionEquality().equals(other.language, language)&&const DeepCollectionEquality().equals(other.editedAt, editedAt)&&(identical(other.publishedAt, publishedAt) || other.publishedAt == publishedAt)&&(identical(other.visibility, visibility) || other.visibility == visibility)&&(identical(other.content, content) || other.content == content)&&(identical(other.type, type) || other.type == type)&&const DeepCollectionEquality().equals(other._meta, _meta)&&(identical(other.viewsUnique, viewsUnique) || other.viewsUnique == viewsUnique)&&(identical(other.viewsTotal, viewsTotal) || other.viewsTotal == viewsTotal)&&(identical(other.upvotes, upvotes) || other.upvotes == upvotes)&&(identical(other.downvotes, downvotes) || other.downvotes == downvotes)&&const DeepCollectionEquality().equals(other.threadedPostId, threadedPostId)&&const DeepCollectionEquality().equals(other.threadedPost, threadedPost)&&const DeepCollectionEquality().equals(other.repliedPostId, repliedPostId)&&const DeepCollectionEquality().equals(other.repliedPost, repliedPost)&&const DeepCollectionEquality().equals(other.forwardedPostId, forwardedPostId)&&const DeepCollectionEquality().equals(other.forwardedPost, forwardedPost)&&const DeepCollectionEquality().equals(other._attachments, _attachments)&&(identical(other.publisher, publisher) || other.publisher == publisher)&&const DeepCollectionEquality().equals(other._reactions, _reactions)&&const DeepCollectionEquality().equals(other._tags, _tags)&&const DeepCollectionEquality().equals(other._categories, _categories)&&const DeepCollectionEquality().equals(other._collections, _collections)&&(identical(other.empty, empty) || other.empty == empty)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&const DeepCollectionEquality().equals(other.deletedAt, deletedAt)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hashAll([runtimeType,id,title,description,const DeepCollectionEquality().hash(language),const DeepCollectionEquality().hash(editedAt),publishedAt,visibility,content,type,const DeepCollectionEquality().hash(meta),viewsUnique,viewsTotal,upvotes,downvotes,const DeepCollectionEquality().hash(threadedPostId),const DeepCollectionEquality().hash(threadedPost),const DeepCollectionEquality().hash(repliedPostId),const DeepCollectionEquality().hash(repliedPost),const DeepCollectionEquality().hash(forwardedPostId),const DeepCollectionEquality().hash(forwardedPost),const DeepCollectionEquality().hash(_attachments),publisher,const DeepCollectionEquality().hash(_reactions),const DeepCollectionEquality().hash(_tags),const DeepCollectionEquality().hash(_categories),const DeepCollectionEquality().hash(_collections),empty,createdAt,updatedAt,const DeepCollectionEquality().hash(deletedAt)]); +int get hashCode => Object.hashAll([runtimeType,id,title,description,const DeepCollectionEquality().hash(language),const DeepCollectionEquality().hash(editedAt),publishedAt,visibility,content,type,const DeepCollectionEquality().hash(_meta),viewsUnique,viewsTotal,upvotes,downvotes,const DeepCollectionEquality().hash(threadedPostId),const DeepCollectionEquality().hash(threadedPost),const DeepCollectionEquality().hash(repliedPostId),const DeepCollectionEquality().hash(repliedPost),const DeepCollectionEquality().hash(forwardedPostId),const DeepCollectionEquality().hash(forwardedPost),const DeepCollectionEquality().hash(_attachments),publisher,const DeepCollectionEquality().hash(_reactions),const DeepCollectionEquality().hash(_tags),const DeepCollectionEquality().hash(_categories),const DeepCollectionEquality().hash(_collections),empty,createdAt,updatedAt,const DeepCollectionEquality().hash(deletedAt)]); @override String toString() { @@ -215,7 +223,7 @@ abstract mixin class _$SnPostCopyWith<$Res> implements $SnPostCopyWith<$Res> { factory _$SnPostCopyWith(_SnPost value, $Res Function(_SnPost) _then) = __$SnPostCopyWithImpl; @override @useResult $Res call({ - int id, String title, String description, dynamic language, dynamic editedAt, DateTime publishedAt, int visibility, String content, int type, dynamic meta, int viewsUnique, int viewsTotal, int upvotes, int downvotes, dynamic threadedPostId, dynamic threadedPost, dynamic repliedPostId, dynamic repliedPost, dynamic forwardedPostId, dynamic forwardedPost, List attachments, SnPublisher publisher, List reactions, List tags, List categories, List collections, bool empty, DateTime createdAt, DateTime updatedAt, dynamic deletedAt + int id, String title, String description, dynamic language, dynamic editedAt, DateTime publishedAt, int visibility, String content, int type, Map? meta, int viewsUnique, int viewsTotal, int upvotes, int downvotes, dynamic threadedPostId, dynamic threadedPost, dynamic repliedPostId, dynamic repliedPost, dynamic forwardedPostId, dynamic forwardedPost, List attachments, SnPublisher publisher, List reactions, List tags, List categories, List collections, bool empty, DateTime createdAt, DateTime updatedAt, dynamic deletedAt }); @@ -243,8 +251,8 @@ as dynamic,publishedAt: null == publishedAt ? _self.publishedAt : publishedAt // as DateTime,visibility: null == visibility ? _self.visibility : visibility // ignore: cast_nullable_to_non_nullable as int,content: null == content ? _self.content : content // ignore: cast_nullable_to_non_nullable as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable -as int,meta: freezed == meta ? _self.meta : meta // ignore: cast_nullable_to_non_nullable -as dynamic,viewsUnique: null == viewsUnique ? _self.viewsUnique : viewsUnique // ignore: cast_nullable_to_non_nullable +as int,meta: freezed == meta ? _self._meta : meta // ignore: cast_nullable_to_non_nullable +as Map?,viewsUnique: null == viewsUnique ? _self.viewsUnique : viewsUnique // ignore: cast_nullable_to_non_nullable as int,viewsTotal: null == viewsTotal ? _self.viewsTotal : viewsTotal // ignore: cast_nullable_to_non_nullable as int,upvotes: null == upvotes ? _self.upvotes : upvotes // ignore: cast_nullable_to_non_nullable as int,downvotes: null == downvotes ? _self.downvotes : downvotes // ignore: cast_nullable_to_non_nullable @@ -284,7 +292,7 @@ $SnPublisherCopyWith<$Res> get publisher { /// @nodoc mixin _$SnPublisher { - int get id; int get publisherType; String get name; String get nick; String get bio; SnCloudFile get picture; SnCloudFile get background; int get accountId; DateTime get createdAt; DateTime get updatedAt; DateTime? get deletedAt; + int get id; int get publisherType; String get name; String get nick; String get bio; SnCloudFile? get picture; SnCloudFile? get background; int get accountId; DateTime get createdAt; DateTime get updatedAt; DateTime? get deletedAt; /// Create a copy of SnPublisher /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -317,11 +325,11 @@ abstract mixin class $SnPublisherCopyWith<$Res> { factory $SnPublisherCopyWith(SnPublisher value, $Res Function(SnPublisher) _then) = _$SnPublisherCopyWithImpl; @useResult $Res call({ - int id, int publisherType, String name, String nick, String bio, SnCloudFile picture, SnCloudFile background, int accountId, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt + int id, int publisherType, String name, String nick, String bio, SnCloudFile? picture, SnCloudFile? background, int accountId, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt }); -$SnCloudFileCopyWith<$Res> get picture;$SnCloudFileCopyWith<$Res> get background; +$SnCloudFileCopyWith<$Res>? get picture;$SnCloudFileCopyWith<$Res>? get background; } /// @nodoc @@ -334,16 +342,16 @@ class _$SnPublisherCopyWithImpl<$Res> /// Create a copy of SnPublisher /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? publisherType = null,Object? name = null,Object? nick = null,Object? bio = null,Object? picture = null,Object? background = null,Object? accountId = null,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? publisherType = null,Object? name = null,Object? nick = null,Object? bio = null,Object? picture = freezed,Object? background = freezed,Object? accountId = null,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) { return _then(_self.copyWith( id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as int,publisherType: null == publisherType ? _self.publisherType : publisherType // ignore: cast_nullable_to_non_nullable as int,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable as String,nick: null == nick ? _self.nick : nick // ignore: cast_nullable_to_non_nullable as String,bio: null == bio ? _self.bio : bio // ignore: cast_nullable_to_non_nullable -as String,picture: null == picture ? _self.picture : picture // ignore: cast_nullable_to_non_nullable -as SnCloudFile,background: null == background ? _self.background : background // ignore: cast_nullable_to_non_nullable -as SnCloudFile,accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable +as String,picture: freezed == picture ? _self.picture : picture // ignore: cast_nullable_to_non_nullable +as SnCloudFile?,background: freezed == background ? _self.background : background // ignore: cast_nullable_to_non_nullable +as SnCloudFile?,accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable as int,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 as DateTime,deletedAt: freezed == deletedAt ? _self.deletedAt : deletedAt // ignore: cast_nullable_to_non_nullable @@ -354,18 +362,24 @@ as DateTime?, /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') -$SnCloudFileCopyWith<$Res> get picture { - - return $SnCloudFileCopyWith<$Res>(_self.picture, (value) { +$SnCloudFileCopyWith<$Res>? get picture { + if (_self.picture == null) { + return null; + } + + return $SnCloudFileCopyWith<$Res>(_self.picture!, (value) { return _then(_self.copyWith(picture: value)); }); }/// Create a copy of SnPublisher /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') -$SnCloudFileCopyWith<$Res> get background { - - return $SnCloudFileCopyWith<$Res>(_self.background, (value) { +$SnCloudFileCopyWith<$Res>? get background { + if (_self.background == null) { + return null; + } + + return $SnCloudFileCopyWith<$Res>(_self.background!, (value) { return _then(_self.copyWith(background: value)); }); } @@ -384,8 +398,8 @@ class _SnPublisher implements SnPublisher { @override final String name; @override final String nick; @override final String bio; -@override final SnCloudFile picture; -@override final SnCloudFile background; +@override final SnCloudFile? picture; +@override final SnCloudFile? background; @override final int accountId; @override final DateTime createdAt; @override final DateTime updatedAt; @@ -424,11 +438,11 @@ abstract mixin class _$SnPublisherCopyWith<$Res> implements $SnPublisherCopyWith factory _$SnPublisherCopyWith(_SnPublisher value, $Res Function(_SnPublisher) _then) = __$SnPublisherCopyWithImpl; @override @useResult $Res call({ - int id, int publisherType, String name, String nick, String bio, SnCloudFile picture, SnCloudFile background, int accountId, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt + int id, int publisherType, String name, String nick, String bio, SnCloudFile? picture, SnCloudFile? background, int accountId, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt }); -@override $SnCloudFileCopyWith<$Res> get picture;@override $SnCloudFileCopyWith<$Res> get background; +@override $SnCloudFileCopyWith<$Res>? get picture;@override $SnCloudFileCopyWith<$Res>? get background; } /// @nodoc @@ -441,16 +455,16 @@ class __$SnPublisherCopyWithImpl<$Res> /// Create a copy of SnPublisher /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? publisherType = null,Object? name = null,Object? nick = null,Object? bio = null,Object? picture = null,Object? background = null,Object? accountId = null,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? publisherType = null,Object? name = null,Object? nick = null,Object? bio = null,Object? picture = freezed,Object? background = freezed,Object? accountId = null,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) { return _then(_SnPublisher( id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as int,publisherType: null == publisherType ? _self.publisherType : publisherType // ignore: cast_nullable_to_non_nullable as int,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable as String,nick: null == nick ? _self.nick : nick // ignore: cast_nullable_to_non_nullable as String,bio: null == bio ? _self.bio : bio // ignore: cast_nullable_to_non_nullable -as String,picture: null == picture ? _self.picture : picture // ignore: cast_nullable_to_non_nullable -as SnCloudFile,background: null == background ? _self.background : background // ignore: cast_nullable_to_non_nullable -as SnCloudFile,accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable +as String,picture: freezed == picture ? _self.picture : picture // ignore: cast_nullable_to_non_nullable +as SnCloudFile?,background: freezed == background ? _self.background : background // ignore: cast_nullable_to_non_nullable +as SnCloudFile?,accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable as int,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 as DateTime,deletedAt: freezed == deletedAt ? _self.deletedAt : deletedAt // ignore: cast_nullable_to_non_nullable @@ -462,18 +476,24 @@ as DateTime?, /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') -$SnCloudFileCopyWith<$Res> get picture { - - return $SnCloudFileCopyWith<$Res>(_self.picture, (value) { +$SnCloudFileCopyWith<$Res>? get picture { + if (_self.picture == null) { + return null; + } + + return $SnCloudFileCopyWith<$Res>(_self.picture!, (value) { return _then(_self.copyWith(picture: value)); }); }/// Create a copy of SnPublisher /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') -$SnCloudFileCopyWith<$Res> get background { - - return $SnCloudFileCopyWith<$Res>(_self.background, (value) { +$SnCloudFileCopyWith<$Res>? get background { + if (_self.background == null) { + return null; + } + + return $SnCloudFileCopyWith<$Res>(_self.background!, (value) { return _then(_self.copyWith(background: value)); }); } diff --git a/lib/models/post.g.dart b/lib/models/post.g.dart index 8a3be7e..09302bf 100644 --- a/lib/models/post.g.dart +++ b/lib/models/post.g.dart @@ -16,7 +16,7 @@ _SnPost _$SnPostFromJson(Map json) => _SnPost( visibility: (json['visibility'] as num).toInt(), content: json['content'] as String, type: (json['type'] as num).toInt(), - meta: json['meta'], + meta: json['meta'] as Map?, viewsUnique: (json['views_unique'] as num).toInt(), viewsTotal: (json['views_total'] as num).toInt(), upvotes: (json['upvotes'] as num).toInt(), @@ -81,8 +81,14 @@ _SnPublisher _$SnPublisherFromJson(Map json) => _SnPublisher( name: json['name'] as String, nick: json['nick'] as String, bio: json['bio'] as String, - picture: SnCloudFile.fromJson(json['picture'] as Map), - background: SnCloudFile.fromJson(json['background'] as Map), + picture: + json['picture'] == null + ? null + : SnCloudFile.fromJson(json['picture'] as Map), + background: + json['background'] == null + ? null + : SnCloudFile.fromJson(json['background'] as Map), accountId: (json['account_id'] as num).toInt(), createdAt: DateTime.parse(json['created_at'] as String), updatedAt: DateTime.parse(json['updated_at'] as String), @@ -99,8 +105,8 @@ Map _$SnPublisherToJson(_SnPublisher instance) => 'name': instance.name, 'nick': instance.nick, 'bio': instance.bio, - 'picture': instance.picture.toJson(), - 'background': instance.background.toJson(), + 'picture': instance.picture?.toJson(), + 'background': instance.background?.toJson(), 'account_id': instance.accountId, 'created_at': instance.createdAt.toIso8601String(), 'updated_at': instance.updatedAt.toIso8601String(), diff --git a/lib/route.dart b/lib/route.dart index 60ce490..de9c3f8 100644 --- a/lib/route.dart +++ b/lib/route.dart @@ -21,5 +21,11 @@ class AppRouter extends RootStackRouter { AutoRoute(page: CreateAccountRoute.page, path: '/auth/create-account'), AutoRoute(page: MyselfProfileRoute.page, path: '/account/me'), AutoRoute(page: UpdateProfileRoute.page, path: '/account/me/update'), + AutoRoute(page: ManagedPublisherRoute.page, path: '/account/me/publishers'), + AutoRoute(page: NewPublisherRoute.page, path: '/account/me/publishers/new'), + AutoRoute( + page: EditPublisherRoute.page, + path: '/account/me/publishers/:id', + ), ]; } diff --git a/lib/route.gr.dart b/lib/route.gr.dart index 333116a..73c72b7 100644 --- a/lib/route.gr.dart +++ b/lib/route.gr.dart @@ -9,24 +9,26 @@ // coverage:ignore-file // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:auto_route/auto_route.dart' as _i8; +import 'package:auto_route/auto_route.dart' as _i9; +import 'package:flutter/material.dart' as _i10; import 'package:island/screens/account.dart' as _i1; -import 'package:island/screens/auth/account/me.dart' as _i5; -import 'package:island/screens/auth/account/me/update.dart' as _i7; +import 'package:island/screens/auth/account/me.dart' as _i6; +import 'package:island/screens/auth/account/me/publishers.dart' as _i3; +import 'package:island/screens/auth/account/me/update.dart' as _i8; import 'package:island/screens/auth/create_account.dart' as _i2; -import 'package:island/screens/auth/login.dart' as _i4; -import 'package:island/screens/auth/tabs.dart' as _i6; -import 'package:island/screens/explore.dart' as _i3; +import 'package:island/screens/auth/login.dart' as _i5; +import 'package:island/screens/auth/tabs.dart' as _i7; +import 'package:island/screens/explore.dart' as _i4; /// generated route for /// [_i1.AccountScreen] -class AccountRoute extends _i8.PageRouteInfo { - const AccountRoute({List<_i8.PageRouteInfo>? children}) +class AccountRoute extends _i9.PageRouteInfo { + const AccountRoute({List<_i9.PageRouteInfo>? children}) : super(AccountRoute.name, initialChildren: children); static const String name = 'AccountRoute'; - static _i8.PageInfo page = _i8.PageInfo( + static _i9.PageInfo page = _i9.PageInfo( name, builder: (data) { return const _i1.AccountScreen(); @@ -36,13 +38,13 @@ class AccountRoute extends _i8.PageRouteInfo { /// generated route for /// [_i2.CreateAccountScreen] -class CreateAccountRoute extends _i8.PageRouteInfo { - const CreateAccountRoute({List<_i8.PageRouteInfo>? children}) +class CreateAccountRoute extends _i9.PageRouteInfo { + const CreateAccountRoute({List<_i9.PageRouteInfo>? children}) : super(CreateAccountRoute.name, initialChildren: children); static const String name = 'CreateAccountRoute'; - static _i8.PageInfo page = _i8.PageInfo( + static _i9.PageInfo page = _i9.PageInfo( name, builder: (data) { return const _i2.CreateAccountScreen(); @@ -51,81 +53,154 @@ class CreateAccountRoute extends _i8.PageRouteInfo { } /// generated route for -/// [_i3.ExploreScreen] -class ExploreRoute extends _i8.PageRouteInfo { - const ExploreRoute({List<_i8.PageRouteInfo>? children}) +/// [_i3.EditPublisherScreen] +class EditPublisherRoute extends _i9.PageRouteInfo { + EditPublisherRoute({ + _i10.Key? key, + String? name, + List<_i9.PageRouteInfo>? children, + }) : super( + EditPublisherRoute.name, + args: EditPublisherRouteArgs(key: key, name: name), + rawPathParams: {'id': name}, + initialChildren: children, + ); + + static const String name = 'EditPublisherRoute'; + + static _i9.PageInfo page = _i9.PageInfo( + name, + builder: (data) { + final pathParams = data.inheritedPathParams; + final args = data.argsAs( + orElse: () => EditPublisherRouteArgs(name: pathParams.optString('id')), + ); + return _i3.EditPublisherScreen(key: args.key, name: args.name); + }, + ); +} + +class EditPublisherRouteArgs { + const EditPublisherRouteArgs({this.key, this.name}); + + final _i10.Key? key; + + final String? name; + + @override + String toString() { + return 'EditPublisherRouteArgs{key: $key, name: $name}'; + } +} + +/// generated route for +/// [_i4.ExploreScreen] +class ExploreRoute extends _i9.PageRouteInfo { + const ExploreRoute({List<_i9.PageRouteInfo>? children}) : super(ExploreRoute.name, initialChildren: children); static const String name = 'ExploreRoute'; - static _i8.PageInfo page = _i8.PageInfo( + static _i9.PageInfo page = _i9.PageInfo( name, builder: (data) { - return const _i3.ExploreScreen(); + return const _i4.ExploreScreen(); }, ); } /// generated route for -/// [_i4.LoginScreen] -class LoginRoute extends _i8.PageRouteInfo { - const LoginRoute({List<_i8.PageRouteInfo>? children}) +/// [_i5.LoginScreen] +class LoginRoute extends _i9.PageRouteInfo { + const LoginRoute({List<_i9.PageRouteInfo>? children}) : super(LoginRoute.name, initialChildren: children); static const String name = 'LoginRoute'; - static _i8.PageInfo page = _i8.PageInfo( + static _i9.PageInfo page = _i9.PageInfo( name, builder: (data) { - return const _i4.LoginScreen(); + return const _i5.LoginScreen(); }, ); } /// generated route for -/// [_i5.MyselfProfileScreen] -class MyselfProfileRoute extends _i8.PageRouteInfo { - const MyselfProfileRoute({List<_i8.PageRouteInfo>? children}) +/// [_i3.ManagedPublisherScreen] +class ManagedPublisherRoute extends _i9.PageRouteInfo { + const ManagedPublisherRoute({List<_i9.PageRouteInfo>? children}) + : super(ManagedPublisherRoute.name, initialChildren: children); + + static const String name = 'ManagedPublisherRoute'; + + static _i9.PageInfo page = _i9.PageInfo( + name, + builder: (data) { + return const _i3.ManagedPublisherScreen(); + }, + ); +} + +/// generated route for +/// [_i6.MyselfProfileScreen] +class MyselfProfileRoute extends _i9.PageRouteInfo { + const MyselfProfileRoute({List<_i9.PageRouteInfo>? children}) : super(MyselfProfileRoute.name, initialChildren: children); static const String name = 'MyselfProfileRoute'; - static _i8.PageInfo page = _i8.PageInfo( + static _i9.PageInfo page = _i9.PageInfo( name, builder: (data) { - return const _i5.MyselfProfileScreen(); + return const _i6.MyselfProfileScreen(); }, ); } /// generated route for -/// [_i6.TabsScreen] -class TabsRoute extends _i8.PageRouteInfo { - const TabsRoute({List<_i8.PageRouteInfo>? children}) +/// [_i3.NewPublisherScreen] +class NewPublisherRoute extends _i9.PageRouteInfo { + const NewPublisherRoute({List<_i9.PageRouteInfo>? children}) + : super(NewPublisherRoute.name, initialChildren: children); + + static const String name = 'NewPublisherRoute'; + + static _i9.PageInfo page = _i9.PageInfo( + name, + builder: (data) { + return const _i3.NewPublisherScreen(); + }, + ); +} + +/// generated route for +/// [_i7.TabsScreen] +class TabsRoute extends _i9.PageRouteInfo { + const TabsRoute({List<_i9.PageRouteInfo>? children}) : super(TabsRoute.name, initialChildren: children); static const String name = 'TabsRoute'; - static _i8.PageInfo page = _i8.PageInfo( + static _i9.PageInfo page = _i9.PageInfo( name, builder: (data) { - return const _i6.TabsScreen(); + return const _i7.TabsScreen(); }, ); } /// generated route for -/// [_i7.UpdateProfileScreen] -class UpdateProfileRoute extends _i8.PageRouteInfo { - const UpdateProfileRoute({List<_i8.PageRouteInfo>? children}) +/// [_i8.UpdateProfileScreen] +class UpdateProfileRoute extends _i9.PageRouteInfo { + const UpdateProfileRoute({List<_i9.PageRouteInfo>? children}) : super(UpdateProfileRoute.name, initialChildren: children); static const String name = 'UpdateProfileRoute'; - static _i8.PageInfo page = _i8.PageInfo( + static _i9.PageInfo page = _i9.PageInfo( name, builder: (data) { - return const _i7.UpdateProfileScreen(); + return const _i8.UpdateProfileScreen(); }, ); } diff --git a/lib/screens/account.dart b/lib/screens/account.dart index 0ea2cf1..c71deb3 100644 --- a/lib/screens/account.dart +++ b/lib/screens/account.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; +import 'package:gap/gap.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:island/pods/userinfo.dart'; import 'package:island/route.gr.dart'; @@ -71,34 +72,42 @@ class AccountScreen extends HookConsumerWidget { ).padding(horizontal: 16, vertical: 16), ], ), + ).padding(horizontal: 8), + const Gap(8), + ListTile( + minTileHeight: 48, + leading: const Icon(LucideIcons.bookOpen), + trailing: const Icon(LucideIcons.chevronRight), + contentPadding: EdgeInsets.symmetric(horizontal: 24), + title: Text('managedPublisher').tr(), + onTap: () { + context.router.push(ManagedPublisherRoute()); + }, ), ListTile( + minTileHeight: 48, leading: const Icon(LucideIcons.edit), trailing: const Icon(LucideIcons.chevronRight), contentPadding: EdgeInsets.symmetric(horizontal: 24), - title: Text('accountProfile').tr(), - subtitle: Text('Update your profile.'), + title: Text('updateYourProfile').tr(), onTap: () { context.router.push(UpdateProfileRoute()); }, ), + const Divider(height: 1).padding(vertical: 4), ListTile( + minTileHeight: 48, leading: const Icon(LucideIcons.logOut), trailing: const Icon(LucideIcons.chevronRight), contentPadding: EdgeInsets.symmetric(horizontal: 24), title: Text('logout').tr(), - subtitle: Text('Log out of your account.'), onTap: () { final userNotifier = ref.read(userInfoProvider.notifier); userNotifier.logOut(); }, ), ], - ).padding( - horizontal: 8, - top: 8, - bottom: MediaQuery.of(context).padding.bottom, - ), + ).padding(top: 8, bottom: MediaQuery.of(context).padding.bottom), ), ); } diff --git a/lib/screens/auth/account/me/publishers.dart b/lib/screens/auth/account/me/publishers.dart new file mode 100644 index 0000000..5cbddd7 --- /dev/null +++ b/lib/screens/auth/account/me/publishers.dart @@ -0,0 +1,349 @@ +import 'package:auto_route/auto_route.dart'; +import 'package:dio/dio.dart'; +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:image_picker/image_picker.dart'; +import 'package:island/models/file.dart'; +import 'package:island/models/post.dart'; +import 'package:island/pods/config.dart'; +import 'package:island/pods/network.dart'; +import 'package:island/pods/userinfo.dart'; +import 'package:island/route.gr.dart'; +import 'package:island/services/file.dart'; +import 'package:island/widgets/alert.dart'; +import 'package:island/widgets/app_scaffold.dart'; +import 'package:island/widgets/content/cloud_files.dart'; +import 'package:lucide_icons/lucide_icons.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:styled_widget/styled_widget.dart'; + +part 'publishers.g.dart'; + +@riverpod +Future> publishersManaged(Ref ref) async { + final client = ref.watch(apiClientProvider); + final resp = await client.get('/publishers'); + return resp.data + .map((e) => SnPublisher.fromJson(e)) + .cast() + .toList(); +} + +@RoutePage() +class ManagedPublisherScreen extends HookConsumerWidget { + const ManagedPublisherScreen({super.key}); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final publishers = ref.watch(publishersManagedProvider); + + return AppScaffold( + appBar: AppBar( + title: Text('publishers').tr(), + leading: const PageBackButton(), + ), + body: RefreshIndicator( + child: publishers.when( + data: + (value) => Column( + children: [ + ListTile( + leading: const Icon(LucideIcons.plus), + title: Text('Create a publisher').tr(), + subtitle: Text('To create posts, collections, etc.'), + trailing: const Icon(LucideIcons.chevronRight), + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + onTap: () { + context.router.push(NewPublisherRoute()); + }, + ), + const Divider(height: 1), + Expanded( + child: ListView.builder( + padding: EdgeInsets.only( + bottom: MediaQuery.of(context).padding.bottom, + ), + itemCount: value.length, + itemBuilder: (context, item) { + return ListTile( + leading: ProfilePictureWidget( + item: value[item].picture, + ), + title: Text(value[item].nick), + subtitle: Text('@${value[item].name}'), + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + IconButton( + padding: EdgeInsets.zero, + icon: Icon(LucideIcons.edit, size: 16), + onPressed: () { + context.router + .push( + EditPublisherRoute( + name: value[item].name, + ), + ) + .then((value) { + if (value != null) { + ref.invalidate( + publishersManagedProvider, + ); + } + }); + }, + ), + ], + ), + contentPadding: EdgeInsets.only(left: 16, right: 14), + ); + }, + ), + ), + ], + ), + loading: () => const Center(child: CircularProgressIndicator()), + error: + (e, _) => GestureDetector( + child: Center( + child: Text('Error: $e', textAlign: TextAlign.center), + ), + onTap: () { + ref.invalidate(publishersManagedProvider); + }, + ), + ), + onRefresh: () => ref.refresh(publishersManagedProvider.future), + ), + ); + } +} + +@riverpod +Future publisher(Ref ref, String? identifier) async { + if (identifier == null) return null; + final client = ref.watch(apiClientProvider); + final resp = await client.get('/publishers/$identifier'); + return SnPublisher.fromJson(resp.data); +} + +@RoutePage() +class NewPublisherScreen extends StatelessWidget { + const NewPublisherScreen({super.key}); + + @override + Widget build(BuildContext context) { + return EditPublisherScreen(key: key); + } +} + +@RoutePage() +class EditPublisherScreen extends HookConsumerWidget { + final String? name; + const EditPublisherScreen({super.key, @PathParam('id') this.name}); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final submitting = useState(false); + + final picture = useState(null); + final background = useState(null); + + void setPicture(String position) async { + final result = await ref + .read(imagePickerProvider) + .pickImage(source: ImageSource.gallery); + if (result == null) return; + + submitting.value = true; + try { + final baseUrl = ref.watch(serverUrlProvider); + final atk = await getFreshAtk( + ref.watch(tokenPairProvider), + baseUrl, + onRefreshed: (atk, rtk) { + setTokenPair(ref.watch(sharedPreferencesProvider), atk, rtk); + ref.invalidate(tokenPairProvider); + }, + ); + if (atk == null) throw ArgumentError('Access token is null'); + final cloudFile = + await putMediaToCloud( + fileData: result, + atk: atk, + baseUrl: baseUrl, + filename: result.name, + mimetype: result.mimeType ?? 'image/jpeg', + ).future; + if (cloudFile == null) { + throw ArgumentError('Failed to upload the file...'); + } + switch (position) { + case 'picture': + picture.value = cloudFile; + case 'background': + background.value = cloudFile; + } + } catch (err) { + showErrorAlert(err); + } finally { + submitting.value = false; + } + } + + final publisher = ref.watch(publisherProvider(name)); + + final formKey = useMemoized(GlobalKey.new, const []); + final nameController = useTextEditingController( + text: publisher.value?.name, + ); + final nickController = useTextEditingController( + text: publisher.value?.nick, + ); + final bioController = useTextEditingController(text: publisher.value?.bio); + + useEffect(() { + if (publisher.value != null) { + picture.value = publisher.value!.picture; + background.value = publisher.value!.background; + nameController.text = publisher.value!.name; + nickController.text = publisher.value!.nick; + bioController.text = publisher.value!.bio; + } + return null; + }, [publisher]); + + Future performAction() async { + if (!formKey.currentState!.validate()) return; + + submitting.value = true; + try { + final client = ref.watch(apiClientProvider); + final resp = await client.request( + name == null ? '/publishers' : '/publishers/$name', + data: { + 'name': nameController.text, + 'nick': nickController.text, + 'bio': bioController.text, + 'picture_id': picture.value?.id, + 'background_id': background.value?.id, + }, + options: Options(method: name == null ? 'POST' : 'PATCH'), + ); + if (context.mounted) { + context.maybePop(SnPublisher.fromJson(resp.data)); + } + } catch (err) { + showErrorAlert(err); + } finally { + submitting.value = false; + } + } + + return AppScaffold( + appBar: AppBar( + title: Text(name == null ? 'createPublisher' : 'editPublisher').tr(), + leading: const PageBackButton(), + ), + body: Column( + children: [ + AspectRatio( + aspectRatio: 16 / 7, + child: Stack( + clipBehavior: Clip.none, + fit: StackFit.expand, + children: [ + GestureDetector( + child: Container( + color: Theme.of(context).colorScheme.surfaceContainerHigh, + child: + background.value != null + ? CloudFileWidget( + item: background.value!, + fit: BoxFit.cover, + ) + : const SizedBox.shrink(), + ), + onTap: () { + setPicture('background'); + }, + ), + Positioned( + left: 20, + bottom: -32, + child: GestureDetector( + child: ProfilePictureWidget( + item: picture.value, + radius: 40, + ), + onTap: () { + setPicture('picture'); + }, + ), + ), + ], + ), + ).padding(bottom: 32), + Form( + key: formKey, + child: Column( + spacing: 16, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TextFormField( + controller: nameController, + decoration: InputDecoration( + labelText: 'username'.tr(), + helperText: 'usernameCannotChangeHint'.tr(), + prefixText: '@', + ), + readOnly: name != null, + onTapOutside: + (_) => FocusManager.instance.primaryFocus?.unfocus(), + ), + TextFormField( + controller: nickController, + decoration: InputDecoration(labelText: 'nickname'.tr()), + onTapOutside: + (_) => FocusManager.instance.primaryFocus?.unfocus(), + ), + TextFormField( + controller: bioController, + decoration: InputDecoration(labelText: 'bio'.tr()), + minLines: 3, + maxLines: null, + onTapOutside: + (_) => FocusManager.instance.primaryFocus?.unfocus(), + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + TextButton.icon( + onPressed: () { + final user = ref.watch(userInfoProvider); + nameController.text = user.value!.name; + nickController.text = user.value!.nick; + bioController.text = user.value!.profile.bio ?? ''; + picture.value = user.value!.profile.picture; + background.value = user.value!.profile.background; + }, + label: Text('syncPublisher'.tr()), + icon: const Icon(LucideIcons.refreshCcw), + ), + TextButton.icon( + onPressed: submitting.value ? null : performAction, + label: Text('saveChanges'.tr()), + icon: const Icon(LucideIcons.save), + ), + ], + ), + ], + ).padding(horizontal: 24), + ), + ], + ), + ); + } +} diff --git a/lib/screens/auth/account/me/publishers.g.dart b/lib/screens/auth/account/me/publishers.g.dart new file mode 100644 index 0000000..3772999 --- /dev/null +++ b/lib/screens/auth/account/me/publishers.g.dart @@ -0,0 +1,168 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'publishers.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$publishersManagedHash() => r'1ea611c8d45c46002976c99bf4ee7f60bd6dbf8e'; + +/// See also [publishersManaged]. +@ProviderFor(publishersManaged) +final publishersManagedProvider = + AutoDisposeFutureProvider>.internal( + publishersManaged, + name: r'publishersManagedProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') + ? null + : _$publishersManagedHash, + dependencies: null, + allTransitiveDependencies: null, + ); + +@Deprecated('Will be removed in 3.0. Use Ref instead') +// ignore: unused_element +typedef PublishersManagedRef = AutoDisposeFutureProviderRef>; +String _$publisherHash() => r'd66f2efba7ae449b9b460a4da34ce48cf3b16fe5'; + +/// Copied from Dart SDK +class _SystemHash { + _SystemHash._(); + + static int combine(int hash, int value) { + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + value); + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); + return hash ^ (hash >> 6); + } + + static int finish(int hash) { + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); + // ignore: parameter_assignments + hash = hash ^ (hash >> 11); + return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); + } +} + +/// See also [publisher]. +@ProviderFor(publisher) +const publisherProvider = PublisherFamily(); + +/// See also [publisher]. +class PublisherFamily extends Family> { + /// See also [publisher]. + const PublisherFamily(); + + /// See also [publisher]. + PublisherProvider call(String? identifier) { + return PublisherProvider(identifier); + } + + @override + PublisherProvider getProviderOverride(covariant PublisherProvider provider) { + return call(provider.identifier); + } + + static const Iterable? _dependencies = null; + + @override + Iterable? get dependencies => _dependencies; + + static const Iterable? _allTransitiveDependencies = null; + + @override + Iterable? get allTransitiveDependencies => + _allTransitiveDependencies; + + @override + String? get name => r'publisherProvider'; +} + +/// See also [publisher]. +class PublisherProvider extends AutoDisposeFutureProvider { + /// See also [publisher]. + PublisherProvider(String? identifier) + : this._internal( + (ref) => publisher(ref as PublisherRef, identifier), + from: publisherProvider, + name: r'publisherProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') + ? null + : _$publisherHash, + dependencies: PublisherFamily._dependencies, + allTransitiveDependencies: PublisherFamily._allTransitiveDependencies, + identifier: identifier, + ); + + PublisherProvider._internal( + super._createNotifier, { + required super.name, + required super.dependencies, + required super.allTransitiveDependencies, + required super.debugGetCreateSourceHash, + required super.from, + required this.identifier, + }) : super.internal(); + + final String? identifier; + + @override + Override overrideWith( + FutureOr Function(PublisherRef provider) create, + ) { + return ProviderOverride( + origin: this, + override: PublisherProvider._internal( + (ref) => create(ref as PublisherRef), + from: from, + name: null, + dependencies: null, + allTransitiveDependencies: null, + debugGetCreateSourceHash: null, + identifier: identifier, + ), + ); + } + + @override + AutoDisposeFutureProviderElement createElement() { + return _PublisherProviderElement(this); + } + + @override + bool operator ==(Object other) { + return other is PublisherProvider && other.identifier == identifier; + } + + @override + int get hashCode { + var hash = _SystemHash.combine(0, runtimeType.hashCode); + hash = _SystemHash.combine(hash, identifier.hashCode); + + return _SystemHash.finish(hash); + } +} + +@Deprecated('Will be removed in 3.0. Use Ref instead') +// ignore: unused_element +mixin PublisherRef on AutoDisposeFutureProviderRef { + /// The parameter `identifier` of this provider. + String? get identifier; +} + +class _PublisherProviderElement + extends AutoDisposeFutureProviderElement + with PublisherRef { + _PublisherProviderElement(super.provider); + + @override + String? get identifier => (origin as PublisherProvider).identifier; +} + +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package diff --git a/lib/screens/explore.dart b/lib/screens/explore.dart index e1a0793..994a57b 100644 --- a/lib/screens/explore.dart +++ b/lib/screens/explore.dart @@ -20,20 +20,33 @@ class ExploreScreen extends ConsumerWidget { appBar: AppBar(title: const Text('Explore')), body: postAsync.when( data: - (controller) => InfiniteList( - padding: EdgeInsets.zero, - itemCount: controller.posts.length, - isLoading: controller.isLoading, - hasReachedMax: controller.hasReachedMax, - onFetchData: controller.fetchMore, - itemBuilder: (context, index) { - final post = controller.posts[index]; - return PostItem(item: post); - }, - separatorBuilder: (_, __) => const Divider(height: 1), + (controller) => RefreshIndicator( + onRefresh: controller.refresh, + child: InfiniteList( + padding: EdgeInsets.only( + bottom: MediaQuery.of(context).padding.bottom, + ), + itemCount: controller.posts.length, + isLoading: controller.isLoading, + hasReachedMax: controller.hasReachedMax, + onFetchData: controller.fetchMore, + itemBuilder: (context, index) { + final post = controller.posts[index]; + return PostItem(item: post); + }, + separatorBuilder: (_, __) => const Divider(height: 1), + ), ), loading: () => const Center(child: CircularProgressIndicator()), - error: (e, _) => Center(child: Text('Error: $e')), + error: + (e, _) => GestureDetector( + child: Center( + child: Text('Error: $e', textAlign: TextAlign.center), + ), + onTap: () { + postAsync.value?.refresh(); + }, + ), ), ); } @@ -57,6 +70,13 @@ class _PostListController { final int take = 20; int total = 0; + Future refresh() async { + hasReachedMax = false; + offset = 0; + posts.clear(); + await fetchMore(); + } + Future fetchMore() async { if (isLoading || hasReachedMax) return; isLoading = true; diff --git a/lib/widgets/alert.dart b/lib/widgets/alert.dart index ba61ddf..153883b 100644 --- a/lib/widgets/alert.dart +++ b/lib/widgets/alert.dart @@ -17,3 +17,13 @@ void showInfoAlert(String message, String title) async { iconStyle: IconStyle.information, ); } + +Future showConfirmAlert(String message, String title) async { + final result = await FlutterPlatformAlert.showAlert( + windowTitle: title, + text: message, + alertStyle: AlertButtonStyle.okCancel, + iconStyle: IconStyle.question, + ); + return result == AlertButton.okButton; +} diff --git a/lib/widgets/content/cloud_files.dart b/lib/widgets/content/cloud_files.dart index 05dd7e1..45a8a74 100644 --- a/lib/widgets/content/cloud_files.dart +++ b/lib/widgets/content/cloud_files.dart @@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:island/models/file.dart'; import 'package:island/pods/config.dart'; import 'package:lucide_icons/lucide_icons.dart'; +import 'package:styled_widget/styled_widget.dart'; import 'image.dart'; import 'video.dart'; @@ -43,11 +44,10 @@ class CloudFileWidget extends ConsumerWidget { class ProfilePictureWidget extends ConsumerWidget { final SnCloudFile? item; final double radius; - const ProfilePictureWidget({super.key, required this.item, this.radius = 24}); + const ProfilePictureWidget({super.key, required this.item, this.radius = 20}); @override Widget build(BuildContext context, WidgetRef ref) { - if (item == null) return const SizedBox.shrink(); return ClipRRect( borderRadius: BorderRadius.all(Radius.circular(radius)), child: Container( @@ -56,7 +56,7 @@ class ProfilePictureWidget extends ConsumerWidget { color: Theme.of(context).colorScheme.primaryContainer, child: item == null - ? Icon(LucideIcons.userCircle) + ? Icon(LucideIcons.userCircle, size: radius).center() : CloudFileWidget(item: item!), ), ); diff --git a/pubspec.lock b/pubspec.lock index 6d28159..911df5b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,18 +5,26 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - sha256: e55636ed79578b9abca5fecf9437947798f5ef7456308b5cb85720b793eac92f + sha256: dc27559385e905ad30838356c5f5d574014ba39872d732111cd07ac0beff4c57 url: "https://pub.dev" source: hosted - version: "82.0.0" + version: "80.0.0" analyzer: dependency: transitive description: name: analyzer - sha256: "13c1e6c6fd460522ea840abec3f677cc226f5fec7872c04ad7b425517ccf54f7" + sha256: "192d1c5b944e7e53b24b5586db760db934b177d4147c42fbca8c8c5f1eb8d11e" url: "https://pub.dev" source: hosted - version: "7.4.4" + version: "7.3.0" + analyzer_plugin: + dependency: transitive + description: + name: analyzer_plugin + sha256: b3075265c5ab222f8b3188342dcb50b476286394a40323e85d1fa725035d40a4 + url: "https://pub.dev" + source: hosted + version: "0.13.0" animations: dependency: "direct main" description: @@ -217,6 +225,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" + ci: + dependency: transitive + description: + name: ci + sha256: "145d095ce05cddac4d797a158bc4cf3b6016d1fe63d8c3d2fbd7212590adca13" + url: "https://pub.dev" + source: hosted + version: "0.1.0" + cli_util: + dependency: transitive + description: + name: cli_util + sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c + url: "https://pub.dev" + source: hosted + version: "0.4.2" clock: dependency: transitive description: @@ -273,6 +297,38 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.8" + custom_lint: + dependency: "direct dev" + description: + name: custom_lint + sha256: "409c485fd14f544af1da965d5a0d160ee57cd58b63eeaa7280a4f28cf5bda7f1" + url: "https://pub.dev" + source: hosted + version: "0.7.5" + custom_lint_builder: + dependency: transitive + description: + name: custom_lint_builder + sha256: "107e0a43606138015777590ee8ce32f26ba7415c25b722ff0908a6f5d7a4c228" + url: "https://pub.dev" + source: hosted + version: "0.7.5" + custom_lint_core: + dependency: transitive + description: + name: custom_lint_core + sha256: "31110af3dde9d29fb10828ca33f1dce24d2798477b167675543ce3d208dee8be" + url: "https://pub.dev" + source: hosted + version: "0.7.5" + custom_lint_visitor: + dependency: transitive + description: + name: custom_lint_visitor + sha256: "36282d85714af494ee2d7da8c8913630aa6694da99f104fb2ed4afcf8fc857d8" + url: "https://pub.dev" + source: hosted + version: "1.0.0+7.3.0" dart_style: dependency: transitive description: @@ -669,6 +725,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.6.1" + hotreloader: + dependency: transitive + description: + name: hotreloader + sha256: bc167a1163807b03bada490bfe2df25b0d744df359227880220a5cbd04e5734b + url: "https://pub.dev" + source: hosted + version: "4.3.0" http: dependency: transitive description: @@ -1149,6 +1213,38 @@ packages: url: "https://pub.dev" source: hosted version: "2.6.1" + riverpod_analyzer_utils: + dependency: transitive + description: + name: riverpod_analyzer_utils + sha256: "03a17170088c63aab6c54c44456f5ab78876a1ddb6032ffde1662ddab4959611" + url: "https://pub.dev" + source: hosted + version: "0.5.10" + riverpod_annotation: + dependency: "direct main" + description: + name: riverpod_annotation + sha256: e14b0bf45b71326654e2705d462f21b958f987087be850afd60578fcd502d1b8 + url: "https://pub.dev" + source: hosted + version: "2.6.1" + riverpod_generator: + dependency: "direct dev" + description: + name: riverpod_generator + sha256: "44a0992d54473eb199ede00e2260bd3c262a86560e3c6f6374503d86d0580e36" + url: "https://pub.dev" + source: hosted + version: "2.6.5" + riverpod_lint: + dependency: "direct dev" + description: + name: riverpod_lint + sha256: "89a52b7334210dbff8605c3edf26cfe69b15062beed5cbfeff2c3812c33c9e35" + url: "https://pub.dev" + source: hosted + version: "2.6.5" rxdart: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index f580eb9..1e9bc00 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -75,6 +75,7 @@ dependencies: cross_file: ^0.3.4+2 image_picker: ^1.1.2 file_picker: ^10.1.2 + riverpod_annotation: ^2.6.1 dev_dependencies: flutter_test: @@ -90,6 +91,9 @@ dev_dependencies: build_runner: ^2.4.15 freezed: ^3.0.6 json_serializable: ^6.9.5 + riverpod_generator: ^2.6.5 + custom_lint: ^0.7.5 + riverpod_lint: ^2.6.5 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec