🧱 New categories, tags subscription type
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:island/models/post.dart';
|
||||
import 'package:island/models/post_tag.dart';
|
||||
import 'package:island/utils/text.dart';
|
||||
|
||||
part 'post_category.freezed.dart';
|
||||
@@ -29,3 +30,21 @@ sealed class SnPostCategory with _$SnPostCategory {
|
||||
return name ?? slug;
|
||||
}
|
||||
}
|
||||
|
||||
@freezed
|
||||
sealed class SnCategorySubscription with _$SnCategorySubscription {
|
||||
const factory SnCategorySubscription({
|
||||
required String id,
|
||||
required String accountId,
|
||||
required String? categoryId,
|
||||
required SnPostCategory? category,
|
||||
required String? tagId,
|
||||
required SnPostTag? tag,
|
||||
required DateTime createdAt,
|
||||
required DateTime updatedAt,
|
||||
required DateTime? deletedAt,
|
||||
}) = _SnCategorySubscription;
|
||||
|
||||
factory SnCategorySubscription.fromJson(Map<String, dynamic> json) =>
|
||||
_$SnCategorySubscriptionFromJson(json);
|
||||
}
|
||||
|
||||
@@ -286,4 +286,333 @@ as int,
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// @nodoc
|
||||
mixin _$SnCategorySubscription {
|
||||
|
||||
String get id; String get accountId; String? get categoryId; SnPostCategory? get category; String? get tagId; SnPostTag? get tag; DateTime get createdAt; DateTime get updatedAt; DateTime? get deletedAt;
|
||||
/// Create a copy of SnCategorySubscription
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$SnCategorySubscriptionCopyWith<SnCategorySubscription> get copyWith => _$SnCategorySubscriptionCopyWithImpl<SnCategorySubscription>(this as SnCategorySubscription, _$identity);
|
||||
|
||||
/// Serializes this SnCategorySubscription to a JSON map.
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is SnCategorySubscription&&(identical(other.id, id) || other.id == id)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.categoryId, categoryId) || other.categoryId == categoryId)&&(identical(other.category, category) || other.category == category)&&(identical(other.tagId, tagId) || other.tagId == tagId)&&(identical(other.tag, tag) || other.tag == tag)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,accountId,categoryId,category,tagId,tag,createdAt,updatedAt,deletedAt);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SnCategorySubscription(id: $id, accountId: $accountId, categoryId: $categoryId, category: $category, tagId: $tagId, tag: $tag, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $SnCategorySubscriptionCopyWith<$Res> {
|
||||
factory $SnCategorySubscriptionCopyWith(SnCategorySubscription value, $Res Function(SnCategorySubscription) _then) = _$SnCategorySubscriptionCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String id, String accountId, String? categoryId, SnPostCategory? category, String? tagId, SnPostTag? tag, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt
|
||||
});
|
||||
|
||||
|
||||
$SnPostCategoryCopyWith<$Res>? get category;$SnPostTagCopyWith<$Res>? get tag;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$SnCategorySubscriptionCopyWithImpl<$Res>
|
||||
implements $SnCategorySubscriptionCopyWith<$Res> {
|
||||
_$SnCategorySubscriptionCopyWithImpl(this._self, this._then);
|
||||
|
||||
final SnCategorySubscription _self;
|
||||
final $Res Function(SnCategorySubscription) _then;
|
||||
|
||||
/// Create a copy of SnCategorySubscription
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? accountId = null,Object? categoryId = freezed,Object? category = freezed,Object? tagId = freezed,Object? tag = freezed,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 String,accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable
|
||||
as String,categoryId: freezed == categoryId ? _self.categoryId : categoryId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,category: freezed == category ? _self.category : category // ignore: cast_nullable_to_non_nullable
|
||||
as SnPostCategory?,tagId: freezed == tagId ? _self.tagId : tagId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,tag: freezed == tag ? _self.tag : tag // ignore: cast_nullable_to_non_nullable
|
||||
as SnPostTag?,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
|
||||
as DateTime?,
|
||||
));
|
||||
}
|
||||
/// Create a copy of SnCategorySubscription
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$SnPostCategoryCopyWith<$Res>? get category {
|
||||
if (_self.category == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $SnPostCategoryCopyWith<$Res>(_self.category!, (value) {
|
||||
return _then(_self.copyWith(category: value));
|
||||
});
|
||||
}/// Create a copy of SnCategorySubscription
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$SnPostTagCopyWith<$Res>? get tag {
|
||||
if (_self.tag == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $SnPostTagCopyWith<$Res>(_self.tag!, (value) {
|
||||
return _then(_self.copyWith(tag: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [SnCategorySubscription].
|
||||
extension SnCategorySubscriptionPatterns on SnCategorySubscription {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _SnCategorySubscription value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _SnCategorySubscription() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _SnCategorySubscription value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _SnCategorySubscription():
|
||||
return $default(_that);}
|
||||
}
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _SnCategorySubscription value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _SnCategorySubscription() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String id, String accountId, String? categoryId, SnPostCategory? category, String? tagId, SnPostTag? tag, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _SnCategorySubscription() when $default != null:
|
||||
return $default(_that.id,_that.accountId,_that.categoryId,_that.category,_that.tagId,_that.tag,_that.createdAt,_that.updatedAt,_that.deletedAt);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String id, String accountId, String? categoryId, SnPostCategory? category, String? tagId, SnPostTag? tag, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _SnCategorySubscription():
|
||||
return $default(_that.id,_that.accountId,_that.categoryId,_that.category,_that.tagId,_that.tag,_that.createdAt,_that.updatedAt,_that.deletedAt);}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id, String accountId, String? categoryId, SnPostCategory? category, String? tagId, SnPostTag? tag, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _SnCategorySubscription() when $default != null:
|
||||
return $default(_that.id,_that.accountId,_that.categoryId,_that.category,_that.tagId,_that.tag,_that.createdAt,_that.updatedAt,_that.deletedAt);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
|
||||
class _SnCategorySubscription implements SnCategorySubscription {
|
||||
const _SnCategorySubscription({required this.id, required this.accountId, required this.categoryId, required this.category, required this.tagId, required this.tag, required this.createdAt, required this.updatedAt, required this.deletedAt});
|
||||
factory _SnCategorySubscription.fromJson(Map<String, dynamic> json) => _$SnCategorySubscriptionFromJson(json);
|
||||
|
||||
@override final String id;
|
||||
@override final String accountId;
|
||||
@override final String? categoryId;
|
||||
@override final SnPostCategory? category;
|
||||
@override final String? tagId;
|
||||
@override final SnPostTag? tag;
|
||||
@override final DateTime createdAt;
|
||||
@override final DateTime updatedAt;
|
||||
@override final DateTime? deletedAt;
|
||||
|
||||
/// Create a copy of SnCategorySubscription
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$SnCategorySubscriptionCopyWith<_SnCategorySubscription> get copyWith => __$SnCategorySubscriptionCopyWithImpl<_SnCategorySubscription>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$SnCategorySubscriptionToJson(this, );
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnCategorySubscription&&(identical(other.id, id) || other.id == id)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.categoryId, categoryId) || other.categoryId == categoryId)&&(identical(other.category, category) || other.category == category)&&(identical(other.tagId, tagId) || other.tagId == tagId)&&(identical(other.tag, tag) || other.tag == tag)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,accountId,categoryId,category,tagId,tag,createdAt,updatedAt,deletedAt);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SnCategorySubscription(id: $id, accountId: $accountId, categoryId: $categoryId, category: $category, tagId: $tagId, tag: $tag, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$SnCategorySubscriptionCopyWith<$Res> implements $SnCategorySubscriptionCopyWith<$Res> {
|
||||
factory _$SnCategorySubscriptionCopyWith(_SnCategorySubscription value, $Res Function(_SnCategorySubscription) _then) = __$SnCategorySubscriptionCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
String id, String accountId, String? categoryId, SnPostCategory? category, String? tagId, SnPostTag? tag, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt
|
||||
});
|
||||
|
||||
|
||||
@override $SnPostCategoryCopyWith<$Res>? get category;@override $SnPostTagCopyWith<$Res>? get tag;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$SnCategorySubscriptionCopyWithImpl<$Res>
|
||||
implements _$SnCategorySubscriptionCopyWith<$Res> {
|
||||
__$SnCategorySubscriptionCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _SnCategorySubscription _self;
|
||||
final $Res Function(_SnCategorySubscription) _then;
|
||||
|
||||
/// Create a copy of SnCategorySubscription
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? accountId = null,Object? categoryId = freezed,Object? category = freezed,Object? tagId = freezed,Object? tag = freezed,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) {
|
||||
return _then(_SnCategorySubscription(
|
||||
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
|
||||
as String,accountId: null == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable
|
||||
as String,categoryId: freezed == categoryId ? _self.categoryId : categoryId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,category: freezed == category ? _self.category : category // ignore: cast_nullable_to_non_nullable
|
||||
as SnPostCategory?,tagId: freezed == tagId ? _self.tagId : tagId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,tag: freezed == tag ? _self.tag : tag // ignore: cast_nullable_to_non_nullable
|
||||
as SnPostTag?,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
|
||||
as DateTime?,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of SnCategorySubscription
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$SnPostCategoryCopyWith<$Res>? get category {
|
||||
if (_self.category == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $SnPostCategoryCopyWith<$Res>(_self.category!, (value) {
|
||||
return _then(_self.copyWith(category: value));
|
||||
});
|
||||
}/// Create a copy of SnCategorySubscription
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$SnPostTagCopyWith<$Res>? get tag {
|
||||
if (_self.tag == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $SnPostTagCopyWith<$Res>(_self.tag!, (value) {
|
||||
return _then(_self.copyWith(tag: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// dart format on
|
||||
|
||||
@@ -27,3 +27,37 @@ Map<String, dynamic> _$SnPostCategoryToJson(_SnPostCategory instance) =>
|
||||
'posts': instance.posts.map((e) => e.toJson()).toList(),
|
||||
'usage': instance.usage,
|
||||
};
|
||||
|
||||
_SnCategorySubscription _$SnCategorySubscriptionFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _SnCategorySubscription(
|
||||
id: json['id'] as String,
|
||||
accountId: json['account_id'] as String,
|
||||
categoryId: json['category_id'] as String?,
|
||||
category: json['category'] == null
|
||||
? null
|
||||
: SnPostCategory.fromJson(json['category'] as Map<String, dynamic>),
|
||||
tagId: json['tag_id'] as String?,
|
||||
tag: json['tag'] == null
|
||||
? null
|
||||
: SnPostTag.fromJson(json['tag'] as Map<String, dynamic>),
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
deletedAt: json['deleted_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['deleted_at'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SnCategorySubscriptionToJson(
|
||||
_SnCategorySubscription instance,
|
||||
) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'account_id': instance.accountId,
|
||||
'category_id': instance.categoryId,
|
||||
'category': instance.category?.toJson(),
|
||||
'tag_id': instance.tagId,
|
||||
'tag': instance.tag?.toJson(),
|
||||
'created_at': instance.createdAt.toIso8601String(),
|
||||
'updated_at': instance.updatedAt.toIso8601String(),
|
||||
'deleted_at': instance.deletedAt?.toIso8601String(),
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ Future<SnPostTag> postTag(Ref ref, String slug) async {
|
||||
}
|
||||
|
||||
@riverpod
|
||||
Future<bool> postCategorySubscriptionStatus(
|
||||
Future<SnCategorySubscription?> postCategorySubscription(
|
||||
Ref ref,
|
||||
String slug,
|
||||
bool isCategory,
|
||||
@@ -40,9 +40,10 @@ Future<bool> postCategorySubscriptionStatus(
|
||||
final resp = await apiClient.get(
|
||||
'/sphere/posts/${isCategory ? 'categories' : 'tags'}/$slug/subscription',
|
||||
);
|
||||
return resp.statusCode == 200;
|
||||
if (resp.data == 200) return SnCategorySubscription.fromJson(resp.data);
|
||||
return null;
|
||||
} catch (_) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +57,7 @@ Future<void> _subscribeToCategoryOrTag(
|
||||
'/sphere/posts/${isCategory ? 'categories' : 'tags'}/$slug/subscribe',
|
||||
);
|
||||
// Invalidate the subscription status to refresh it
|
||||
ref.invalidate(postCategorySubscriptionStatusProvider(slug, isCategory));
|
||||
ref.invalidate(postCategorySubscriptionProvider(slug, isCategory));
|
||||
}
|
||||
|
||||
Future<void> _unsubscribeFromCategoryOrTag(
|
||||
@@ -69,7 +70,7 @@ Future<void> _unsubscribeFromCategoryOrTag(
|
||||
'/sphere/posts/${isCategory ? 'categories' : 'tags'}/$slug/unsubscribe',
|
||||
);
|
||||
// Invalidate the subscription status to refresh it
|
||||
ref.invalidate(postCategorySubscriptionStatusProvider(slug, isCategory));
|
||||
ref.invalidate(postCategorySubscriptionProvider(slug, isCategory));
|
||||
}
|
||||
|
||||
class PostCategoryDetailScreen extends HookConsumerWidget {
|
||||
@@ -88,7 +89,7 @@ class PostCategoryDetailScreen extends HookConsumerWidget {
|
||||
: null;
|
||||
final postTag = isCategory ? null : ref.watch(postTagProvider(slug));
|
||||
final subscriptionStatus = ref.watch(
|
||||
postCategorySubscriptionStatusProvider(slug, isCategory),
|
||||
postCategorySubscriptionProvider(slug, isCategory),
|
||||
);
|
||||
|
||||
final postFilterTitle = isCategory
|
||||
@@ -118,7 +119,7 @@ class PostCategoryDetailScreen extends HookConsumerWidget {
|
||||
Text('A category'),
|
||||
const Gap(8),
|
||||
subscriptionStatus.when(
|
||||
data: (isSubscribed) => isSubscribed
|
||||
data: (subscription) => subscription != null
|
||||
? FilledButton.icon(
|
||||
onPressed: () async {
|
||||
await _unsubscribeFromCategoryOrTag(
|
||||
@@ -176,7 +177,7 @@ class PostCategoryDetailScreen extends HookConsumerWidget {
|
||||
Text('A tag'),
|
||||
const Gap(8),
|
||||
subscriptionStatus.when(
|
||||
data: (isSubscribed) => isSubscribed
|
||||
data: (subscription) => subscription != null
|
||||
? FilledButton.icon(
|
||||
onPressed: () async {
|
||||
await _unsubscribeFromCategoryOrTag(
|
||||
|
||||
@@ -158,48 +158,55 @@ final class PostTagFamily extends $Family
|
||||
String toString() => r'postTagProvider';
|
||||
}
|
||||
|
||||
@ProviderFor(postCategorySubscriptionStatus)
|
||||
const postCategorySubscriptionStatusProvider =
|
||||
PostCategorySubscriptionStatusFamily._();
|
||||
@ProviderFor(postCategorySubscription)
|
||||
const postCategorySubscriptionProvider = PostCategorySubscriptionFamily._();
|
||||
|
||||
final class PostCategorySubscriptionStatusProvider
|
||||
extends $FunctionalProvider<AsyncValue<bool>, bool, FutureOr<bool>>
|
||||
with $FutureModifier<bool>, $FutureProvider<bool> {
|
||||
const PostCategorySubscriptionStatusProvider._({
|
||||
required PostCategorySubscriptionStatusFamily super.from,
|
||||
final class PostCategorySubscriptionProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<SnCategorySubscription?>,
|
||||
SnCategorySubscription?,
|
||||
FutureOr<SnCategorySubscription?>
|
||||
>
|
||||
with
|
||||
$FutureModifier<SnCategorySubscription?>,
|
||||
$FutureProvider<SnCategorySubscription?> {
|
||||
const PostCategorySubscriptionProvider._({
|
||||
required PostCategorySubscriptionFamily super.from,
|
||||
required (String, bool) super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'postCategorySubscriptionStatusProvider',
|
||||
name: r'postCategorySubscriptionProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$postCategorySubscriptionStatusHash();
|
||||
String debugGetCreateSourceHash() => _$postCategorySubscriptionHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'postCategorySubscriptionStatusProvider'
|
||||
return r'postCategorySubscriptionProvider'
|
||||
''
|
||||
'$argument';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<bool> $createElement($ProviderPointer pointer) =>
|
||||
$FutureProviderElement(pointer);
|
||||
$FutureProviderElement<SnCategorySubscription?> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<bool> create(Ref ref) {
|
||||
FutureOr<SnCategorySubscription?> create(Ref ref) {
|
||||
final argument = this.argument as (String, bool);
|
||||
return postCategorySubscriptionStatus(ref, argument.$1, argument.$2);
|
||||
return postCategorySubscription(ref, argument.$1, argument.$2);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is PostCategorySubscriptionStatusProvider &&
|
||||
return other is PostCategorySubscriptionProvider &&
|
||||
other.argument == argument;
|
||||
}
|
||||
|
||||
@@ -209,26 +216,30 @@ final class PostCategorySubscriptionStatusProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$postCategorySubscriptionStatusHash() =>
|
||||
r'407dc7fcaeffc461b591b4ee2418811aa4f0a63f';
|
||||
String _$postCategorySubscriptionHash() =>
|
||||
r'60fe0a68ab3d8d493eac3577187d7adcfc0244b9';
|
||||
|
||||
final class PostCategorySubscriptionStatusFamily extends $Family
|
||||
with $FunctionalFamilyOverride<FutureOr<bool>, (String, bool)> {
|
||||
const PostCategorySubscriptionStatusFamily._()
|
||||
final class PostCategorySubscriptionFamily extends $Family
|
||||
with
|
||||
$FunctionalFamilyOverride<
|
||||
FutureOr<SnCategorySubscription?>,
|
||||
(String, bool)
|
||||
> {
|
||||
const PostCategorySubscriptionFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'postCategorySubscriptionStatusProvider',
|
||||
name: r'postCategorySubscriptionProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
PostCategorySubscriptionStatusProvider call(String slug, bool isCategory) =>
|
||||
PostCategorySubscriptionStatusProvider._(
|
||||
PostCategorySubscriptionProvider call(String slug, bool isCategory) =>
|
||||
PostCategorySubscriptionProvider._(
|
||||
argument: (slug, isCategory),
|
||||
from: this,
|
||||
);
|
||||
|
||||
@override
|
||||
String toString() => r'postCategorySubscriptionStatusProvider';
|
||||
String toString() => r'postCategorySubscriptionProvider';
|
||||
}
|
||||
|
||||
@@ -4,14 +4,17 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:island/models/post.dart';
|
||||
import 'package:island/models/post_category.dart';
|
||||
import 'package:island/pods/network.dart';
|
||||
import 'package:island/widgets/content/cloud_files.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
|
||||
final subscriptionsProvider = FutureProvider<List<SnPublisherSubscription>>((
|
||||
ref,
|
||||
) async {
|
||||
part 'post_subscription_filter.g.dart';
|
||||
|
||||
@riverpod
|
||||
Future<List<SnPublisherSubscription>> publishersSubscriptions(Ref ref) async {
|
||||
final client = ref.read(apiClientProvider);
|
||||
|
||||
final response = await client.get('/sphere/publishers/subscriptions');
|
||||
@@ -20,7 +23,19 @@ final subscriptionsProvider = FutureProvider<List<SnPublisherSubscription>>((
|
||||
.map((json) => SnPublisherSubscription.fromJson(json))
|
||||
.cast<SnPublisherSubscription>()
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
|
||||
@riverpod
|
||||
Future<List<SnCategorySubscription>> categoriesSubscriptions(Ref ref) async {
|
||||
final client = ref.read(apiClientProvider);
|
||||
|
||||
final response = await client.get('/sphere/categories/subscriptions');
|
||||
|
||||
return response.data
|
||||
.map((json) => SnCategorySubscription.fromJson(json))
|
||||
.cast<SnCategorySubscription>()
|
||||
.toList();
|
||||
}
|
||||
|
||||
class PostSubscriptionFilterWidget extends HookConsumerWidget {
|
||||
final List<String> initialSelectedPublisherNames;
|
||||
@@ -40,7 +55,7 @@ class PostSubscriptionFilterWidget extends HookConsumerWidget {
|
||||
initialSelectedPublisherNames,
|
||||
);
|
||||
|
||||
final subscriptionsAsync = ref.watch(subscriptionsProvider);
|
||||
final subscriptionsAsync = ref.watch(publishersSubscriptionsProvider);
|
||||
|
||||
void updateSelection() {
|
||||
onSelectedPublishersChanged(selectedPublisherNames.value);
|
||||
|
||||
94
lib/widgets/posts/post_subscription_filter.g.dart
Normal file
94
lib/widgets/posts/post_subscription_filter.g.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'post_subscription_filter.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(publishersSubscriptions)
|
||||
const publishersSubscriptionsProvider = PublishersSubscriptionsProvider._();
|
||||
|
||||
final class PublishersSubscriptionsProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<List<SnPublisherSubscription>>,
|
||||
List<SnPublisherSubscription>,
|
||||
FutureOr<List<SnPublisherSubscription>>
|
||||
>
|
||||
with
|
||||
$FutureModifier<List<SnPublisherSubscription>>,
|
||||
$FutureProvider<List<SnPublisherSubscription>> {
|
||||
const PublishersSubscriptionsProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'publishersSubscriptionsProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$publishersSubscriptionsHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<List<SnPublisherSubscription>> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<List<SnPublisherSubscription>> create(Ref ref) {
|
||||
return publishersSubscriptions(ref);
|
||||
}
|
||||
}
|
||||
|
||||
String _$publishersSubscriptionsHash() =>
|
||||
r'208463c1f879a3ddab4092112e312a0cd27ebc2f';
|
||||
|
||||
@ProviderFor(categoriesSubscriptions)
|
||||
const categoriesSubscriptionsProvider = CategoriesSubscriptionsProvider._();
|
||||
|
||||
final class CategoriesSubscriptionsProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<List<SnCategorySubscription>>,
|
||||
List<SnCategorySubscription>,
|
||||
FutureOr<List<SnCategorySubscription>>
|
||||
>
|
||||
with
|
||||
$FutureModifier<List<SnCategorySubscription>>,
|
||||
$FutureProvider<List<SnCategorySubscription>> {
|
||||
const CategoriesSubscriptionsProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'categoriesSubscriptionsProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$categoriesSubscriptionsHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<List<SnCategorySubscription>> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<List<SnCategorySubscription>> create(Ref ref) {
|
||||
return categoriesSubscriptions(ref);
|
||||
}
|
||||
}
|
||||
|
||||
String _$categoriesSubscriptionsHash() =>
|
||||
r'14a8f04d258d1a10aae20ca959495926840c9386';
|
||||
Reference in New Issue
Block a user