🧱 New categories, tags subscription type
This commit is contained in:
@@ -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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user