Realm Popularity

This commit is contained in:
LittleSheep 2025-02-20 23:44:28 +08:00
parent 3338e699c4
commit a8e0ade0c8
6 changed files with 67 additions and 14 deletions

View File

@ -104,7 +104,7 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
try { try {
final sn = context.read<SnNetworkProvider>(); final sn = context.read<SnNetworkProvider>();
await sn.client.delete( await sn.client.delete(
'/cgi/im/channels/${_channel!.realm?.alias ?? 'global'}/${_channel!.id}/members/me', '/cgi/im/channels/${_channel!.realm?.alias ?? 'global'}/${_channel!.alias}/members/me',
); );
if (!mounted) return; if (!mounted) return;
Navigator.pop(context, false); Navigator.pop(context, false);

View File

@ -136,6 +136,7 @@ class _RealmScreenState extends State<RealmScreen> {
final realm = _realms![idx]; final realm = _realms![idx];
return RealmItemWidget( return RealmItemWidget(
showPopularity: false,
item: realm, item: realm,
isListView: _isCompactView, isListView: _isCompactView,
actionListView: [ actionListView: [

View File

@ -43,6 +43,7 @@ class SnRealm with _$SnRealm {
@HiveField(10) required int accountId, @HiveField(10) required int accountId,
@HiveField(11) required bool isPublic, @HiveField(11) required bool isPublic,
@HiveField(12) required bool isCommunity, @HiveField(12) required bool isCommunity,
@Default(0) int popularity,
}) = _SnRealm; }) = _SnRealm;
factory SnRealm.fromJson(Map<String, dynamic> json) => factory SnRealm.fromJson(Map<String, dynamic> json) =>

View File

@ -394,6 +394,7 @@ mixin _$SnRealm {
bool get isPublic => throw _privateConstructorUsedError; bool get isPublic => throw _privateConstructorUsedError;
@HiveField(12) @HiveField(12)
bool get isCommunity => throw _privateConstructorUsedError; bool get isCommunity => throw _privateConstructorUsedError;
int get popularity => throw _privateConstructorUsedError;
/// Serializes this SnRealm to a JSON map. /// Serializes this SnRealm to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError; Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@ -423,7 +424,8 @@ abstract class $SnRealmCopyWith<$Res> {
@HiveField(9) Map<String, dynamic>? accessPolicy, @HiveField(9) Map<String, dynamic>? accessPolicy,
@HiveField(10) int accountId, @HiveField(10) int accountId,
@HiveField(11) bool isPublic, @HiveField(11) bool isPublic,
@HiveField(12) bool isCommunity}); @HiveField(12) bool isCommunity,
int popularity});
} }
/// @nodoc /// @nodoc
@ -455,6 +457,7 @@ class _$SnRealmCopyWithImpl<$Res, $Val extends SnRealm>
Object? accountId = null, Object? accountId = null,
Object? isPublic = null, Object? isPublic = null,
Object? isCommunity = null, Object? isCommunity = null,
Object? popularity = null,
}) { }) {
return _then(_value.copyWith( return _then(_value.copyWith(
id: null == id id: null == id
@ -513,6 +516,10 @@ class _$SnRealmCopyWithImpl<$Res, $Val extends SnRealm>
? _value.isCommunity ? _value.isCommunity
: isCommunity // ignore: cast_nullable_to_non_nullable : isCommunity // ignore: cast_nullable_to_non_nullable
as bool, as bool,
popularity: null == popularity
? _value.popularity
: popularity // ignore: cast_nullable_to_non_nullable
as int,
) as $Val); ) as $Val);
} }
} }
@ -538,7 +545,8 @@ abstract class _$$SnRealmImplCopyWith<$Res> implements $SnRealmCopyWith<$Res> {
@HiveField(9) Map<String, dynamic>? accessPolicy, @HiveField(9) Map<String, dynamic>? accessPolicy,
@HiveField(10) int accountId, @HiveField(10) int accountId,
@HiveField(11) bool isPublic, @HiveField(11) bool isPublic,
@HiveField(12) bool isCommunity}); @HiveField(12) bool isCommunity,
int popularity});
} }
/// @nodoc /// @nodoc
@ -568,6 +576,7 @@ class __$$SnRealmImplCopyWithImpl<$Res>
Object? accountId = null, Object? accountId = null,
Object? isPublic = null, Object? isPublic = null,
Object? isCommunity = null, Object? isCommunity = null,
Object? popularity = null,
}) { }) {
return _then(_$SnRealmImpl( return _then(_$SnRealmImpl(
id: null == id id: null == id
@ -626,6 +635,10 @@ class __$$SnRealmImplCopyWithImpl<$Res>
? _value.isCommunity ? _value.isCommunity
: isCommunity // ignore: cast_nullable_to_non_nullable : isCommunity // ignore: cast_nullable_to_non_nullable
as bool, as bool,
popularity: null == popularity
? _value.popularity
: popularity // ignore: cast_nullable_to_non_nullable
as int,
)); ));
} }
} }
@ -648,7 +661,8 @@ class _$SnRealmImpl extends _SnRealm {
@HiveField(9) required final Map<String, dynamic>? accessPolicy, @HiveField(9) required final Map<String, dynamic>? accessPolicy,
@HiveField(10) required this.accountId, @HiveField(10) required this.accountId,
@HiveField(11) required this.isPublic, @HiveField(11) required this.isPublic,
@HiveField(12) required this.isCommunity}) @HiveField(12) required this.isCommunity,
this.popularity = 0})
: _members = members, : _members = members,
_accessPolicy = accessPolicy, _accessPolicy = accessPolicy,
super._(); super._();
@ -713,10 +727,13 @@ class _$SnRealmImpl extends _SnRealm {
@override @override
@HiveField(12) @HiveField(12)
final bool isCommunity; final bool isCommunity;
@override
@JsonKey()
final int popularity;
@override @override
String toString() { String toString() {
return 'SnRealm(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, alias: $alias, name: $name, description: $description, members: $members, avatar: $avatar, banner: $banner, accessPolicy: $accessPolicy, accountId: $accountId, isPublic: $isPublic, isCommunity: $isCommunity)'; return 'SnRealm(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, alias: $alias, name: $name, description: $description, members: $members, avatar: $avatar, banner: $banner, accessPolicy: $accessPolicy, accountId: $accountId, isPublic: $isPublic, isCommunity: $isCommunity, popularity: $popularity)';
} }
@override @override
@ -745,7 +762,9 @@ class _$SnRealmImpl extends _SnRealm {
(identical(other.isPublic, isPublic) || (identical(other.isPublic, isPublic) ||
other.isPublic == isPublic) && other.isPublic == isPublic) &&
(identical(other.isCommunity, isCommunity) || (identical(other.isCommunity, isCommunity) ||
other.isCommunity == isCommunity)); other.isCommunity == isCommunity) &&
(identical(other.popularity, popularity) ||
other.popularity == popularity));
} }
@JsonKey(includeFromJson: false, includeToJson: false) @JsonKey(includeFromJson: false, includeToJson: false)
@ -765,7 +784,8 @@ class _$SnRealmImpl extends _SnRealm {
const DeepCollectionEquality().hash(_accessPolicy), const DeepCollectionEquality().hash(_accessPolicy),
accountId, accountId,
isPublic, isPublic,
isCommunity); isCommunity,
popularity);
/// Create a copy of SnRealm /// Create a copy of SnRealm
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@ -798,7 +818,8 @@ abstract class _SnRealm extends SnRealm {
@HiveField(9) required final Map<String, dynamic>? accessPolicy, @HiveField(9) required final Map<String, dynamic>? accessPolicy,
@HiveField(10) required final int accountId, @HiveField(10) required final int accountId,
@HiveField(11) required final bool isPublic, @HiveField(11) required final bool isPublic,
@HiveField(12) required final bool isCommunity}) = _$SnRealmImpl; @HiveField(12) required final bool isCommunity,
final int popularity}) = _$SnRealmImpl;
const _SnRealm._() : super._(); const _SnRealm._() : super._();
factory _SnRealm.fromJson(Map<String, dynamic> json) = _$SnRealmImpl.fromJson; factory _SnRealm.fromJson(Map<String, dynamic> json) = _$SnRealmImpl.fromJson;
@ -844,6 +865,8 @@ abstract class _SnRealm extends SnRealm {
@override @override
@HiveField(12) @HiveField(12)
bool get isCommunity; bool get isCommunity;
@override
int get popularity;
/// Create a copy of SnRealm /// Create a copy of SnRealm
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.

View File

@ -128,6 +128,7 @@ _$SnRealmImpl _$$SnRealmImplFromJson(Map<String, dynamic> json) =>
accountId: (json['account_id'] as num).toInt(), accountId: (json['account_id'] as num).toInt(),
isPublic: json['is_public'] as bool, isPublic: json['is_public'] as bool,
isCommunity: json['is_community'] as bool, isCommunity: json['is_community'] as bool,
popularity: (json['popularity'] as num?)?.toInt() ?? 0,
); );
Map<String, dynamic> _$$SnRealmImplToJson(_$SnRealmImpl instance) => Map<String, dynamic> _$$SnRealmImplToJson(_$SnRealmImpl instance) =>
@ -146,4 +147,5 @@ Map<String, dynamic> _$$SnRealmImplToJson(_$SnRealmImpl instance) =>
'account_id': instance.accountId, 'account_id': instance.accountId,
'is_public': instance.isPublic, 'is_public': instance.isPublic,
'is_community': instance.isCommunity, 'is_community': instance.isCommunity,
'popularity': instance.popularity,
}; };

View File

@ -15,6 +15,7 @@ class RealmItemWidget extends StatelessWidget {
final List<PopupMenuItem>? actionListView; final List<PopupMenuItem>? actionListView;
final Function? onUpdate; final Function? onUpdate;
final Function? onTap; final Function? onTap;
final bool showPopularity;
const RealmItemWidget({ const RealmItemWidget({
super.key, super.key,
@ -23,6 +24,7 @@ class RealmItemWidget extends StatelessWidget {
this.actionListView, this.actionListView,
this.onUpdate, this.onUpdate,
this.onTap, this.onTap,
this.showPopularity = true,
}); });
@override @override
@ -35,13 +37,27 @@ class RealmItemWidget extends StatelessWidget {
fallbackWidget: const Icon(Symbols.group, size: 20), fallbackWidget: const Icon(Symbols.group, size: 20),
), ),
title: Text(item.name), title: Text(item.name),
subtitle: Text( subtitle: Row(
item.description, children: [
maxLines: 1, if (showPopularity) const Icon(Symbols.local_fire_department, size: 18).padding(right: 1),
overflow: TextOverflow.ellipsis, if (showPopularity) Text(item.popularity.toString()),
if (showPopularity) const Gap(6),
Expanded(
child: Text(
item.description,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
), ),
trailing: PopupMenuButton(itemBuilder: (BuildContext context) => actionListView ?? []), trailing:
actionListView != null ? PopupMenuButton(itemBuilder: (BuildContext context) => actionListView!) : null,
onTap: () { onTap: () {
if (onTap != null) {
onTap!();
return;
}
GoRouter.of(context).pushNamed( GoRouter.of(context).pushNamed(
'realmDetail', 'realmDetail',
pathParameters: {'alias': item.alias}, pathParameters: {'alias': item.alias},
@ -100,13 +116,23 @@ class RealmItemWidget extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text(item.name).textStyle(Theme.of(context).textTheme.titleMedium!), Text(item.name).textStyle(Theme.of(context).textTheme.titleMedium!),
if (showPopularity)
Row(
children: [
Text(item.popularity.toString()),
const Icon(Symbols.local_fire_department, size: 16).padding(bottom: 2),
],
).padding(top: 6),
Text(item.description).textStyle(Theme.of(context).textTheme.bodySmall!), Text(item.description).textStyle(Theme.of(context).textTheme.bodySmall!),
], ],
).padding(horizontal: 24, bottom: 14), ).padding(horizontal: 24, bottom: 14),
], ],
), ),
onTap: () { onTap: () {
if (onTap != null) onTap!(); if (onTap != null) {
onTap!();
return;
}
GoRouter.of(context).pushNamed( GoRouter.of(context).pushNamed(
'realmDetail', 'realmDetail',
pathParameters: {'alias': item.alias}, pathParameters: {'alias': item.alias},