Realm discovery and more detailed realm

This commit is contained in:
2025-06-27 21:10:53 +08:00
parent f511612a53
commit 9d115a5712
16 changed files with 288 additions and 102 deletions

View File

@ -41,9 +41,16 @@ Future<Color?> realmAppbarForegroundColor(Ref ref, String realmSlug) async {
@riverpod
Future<SnRealmMember?> realmIdentity(Ref ref, String realmSlug) async {
final apiClient = ref.watch(apiClientProvider);
final response = await apiClient.get('/realms/$realmSlug/members/me');
return SnRealmMember.fromJson(response.data);
try {
final apiClient = ref.watch(apiClientProvider);
final response = await apiClient.get('/realms/$realmSlug/members/me');
return SnRealmMember.fromJson(response.data);
} catch (err) {
if (err is DioException && err.response?.statusCode == 404) {
return null; // No identity found, user is not a member
}
rethrow;
}
}
@riverpod
@ -135,12 +142,14 @@ class RealmDetailScreen extends HookConsumerWidget {
tilePadding: EdgeInsets.symmetric(
horizontal: 20,
),
expandedCrossAxisAlignment:
CrossAxisAlignment.stretch,
children: [
Text(
realm.description,
style: const TextStyle(fontSize: 16),
).padding(
horizontal: 16,
horizontal: 20,
bottom: 16,
top: 8,
),
@ -160,13 +169,14 @@ class RealmDetailScreen extends HookConsumerWidget {
realmIdentityProvider(slug),
);
ref.invalidate(realmsJoinedProvider);
showSnackBar('joinRealmSuccess'.tr());
} catch (err) {
showErrorAlert(err);
}
},
icon: const Icon(Symbols.add),
label: const Text('joinRealm').tr(),
).padding(horizontal: 16, vertical: 4)
).padding(horizontal: 16, vertical: 8)
else
const SizedBox.shrink(),
],

View File

@ -155,7 +155,7 @@ class _RealmAppbarForegroundColorProviderElement
(origin as RealmAppbarForegroundColorProvider).realmSlug;
}
String _$realmIdentityHash() => r'eac6e829b5b46bcfadbf201ab6f918d78c894b9f';
String _$realmIdentityHash() => r'308d43eef8a6145c762d27bdf7e12e27149524db';
/// See also [realmIdentity].
@ProviderFor(realmIdentity)

View File

@ -46,6 +46,10 @@ class RealmListScreen extends HookConsumerWidget {
appBar: AppBar(
title: const Text('realms').tr(),
actions: [
IconButton(
icon: const Icon(Symbols.travel_explore),
onPressed: () => context.push('/discovery/realms'),
),
IconButton(
icon: Badge(
label: Text(