✨ Realm Popularity
This commit is contained in:
parent
3338e699c4
commit
a8e0ade0c8
@ -104,7 +104,7 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
|
||||
try {
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
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;
|
||||
Navigator.pop(context, false);
|
||||
|
@ -136,6 +136,7 @@ class _RealmScreenState extends State<RealmScreen> {
|
||||
final realm = _realms![idx];
|
||||
|
||||
return RealmItemWidget(
|
||||
showPopularity: false,
|
||||
item: realm,
|
||||
isListView: _isCompactView,
|
||||
actionListView: [
|
||||
|
@ -43,6 +43,7 @@ class SnRealm with _$SnRealm {
|
||||
@HiveField(10) required int accountId,
|
||||
@HiveField(11) required bool isPublic,
|
||||
@HiveField(12) required bool isCommunity,
|
||||
@Default(0) int popularity,
|
||||
}) = _SnRealm;
|
||||
|
||||
factory SnRealm.fromJson(Map<String, dynamic> json) =>
|
||||
|
@ -394,6 +394,7 @@ mixin _$SnRealm {
|
||||
bool get isPublic => throw _privateConstructorUsedError;
|
||||
@HiveField(12)
|
||||
bool get isCommunity => throw _privateConstructorUsedError;
|
||||
int get popularity => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this SnRealm to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@ -423,7 +424,8 @@ abstract class $SnRealmCopyWith<$Res> {
|
||||
@HiveField(9) Map<String, dynamic>? accessPolicy,
|
||||
@HiveField(10) int accountId,
|
||||
@HiveField(11) bool isPublic,
|
||||
@HiveField(12) bool isCommunity});
|
||||
@HiveField(12) bool isCommunity,
|
||||
int popularity});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@ -455,6 +457,7 @@ class _$SnRealmCopyWithImpl<$Res, $Val extends SnRealm>
|
||||
Object? accountId = null,
|
||||
Object? isPublic = null,
|
||||
Object? isCommunity = null,
|
||||
Object? popularity = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
id: null == id
|
||||
@ -513,6 +516,10 @@ class _$SnRealmCopyWithImpl<$Res, $Val extends SnRealm>
|
||||
? _value.isCommunity
|
||||
: isCommunity // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
popularity: null == popularity
|
||||
? _value.popularity
|
||||
: popularity // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
@ -538,7 +545,8 @@ abstract class _$$SnRealmImplCopyWith<$Res> implements $SnRealmCopyWith<$Res> {
|
||||
@HiveField(9) Map<String, dynamic>? accessPolicy,
|
||||
@HiveField(10) int accountId,
|
||||
@HiveField(11) bool isPublic,
|
||||
@HiveField(12) bool isCommunity});
|
||||
@HiveField(12) bool isCommunity,
|
||||
int popularity});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@ -568,6 +576,7 @@ class __$$SnRealmImplCopyWithImpl<$Res>
|
||||
Object? accountId = null,
|
||||
Object? isPublic = null,
|
||||
Object? isCommunity = null,
|
||||
Object? popularity = null,
|
||||
}) {
|
||||
return _then(_$SnRealmImpl(
|
||||
id: null == id
|
||||
@ -626,6 +635,10 @@ class __$$SnRealmImplCopyWithImpl<$Res>
|
||||
? _value.isCommunity
|
||||
: isCommunity // ignore: cast_nullable_to_non_nullable
|
||||
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(10) required this.accountId,
|
||||
@HiveField(11) required this.isPublic,
|
||||
@HiveField(12) required this.isCommunity})
|
||||
@HiveField(12) required this.isCommunity,
|
||||
this.popularity = 0})
|
||||
: _members = members,
|
||||
_accessPolicy = accessPolicy,
|
||||
super._();
|
||||
@ -713,10 +727,13 @@ class _$SnRealmImpl extends _SnRealm {
|
||||
@override
|
||||
@HiveField(12)
|
||||
final bool isCommunity;
|
||||
@override
|
||||
@JsonKey()
|
||||
final int popularity;
|
||||
|
||||
@override
|
||||
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
|
||||
@ -745,7 +762,9 @@ class _$SnRealmImpl extends _SnRealm {
|
||||
(identical(other.isPublic, isPublic) ||
|
||||
other.isPublic == isPublic) &&
|
||||
(identical(other.isCommunity, isCommunity) ||
|
||||
other.isCommunity == isCommunity));
|
||||
other.isCommunity == isCommunity) &&
|
||||
(identical(other.popularity, popularity) ||
|
||||
other.popularity == popularity));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@ -765,7 +784,8 @@ class _$SnRealmImpl extends _SnRealm {
|
||||
const DeepCollectionEquality().hash(_accessPolicy),
|
||||
accountId,
|
||||
isPublic,
|
||||
isCommunity);
|
||||
isCommunity,
|
||||
popularity);
|
||||
|
||||
/// Create a copy of SnRealm
|
||||
/// 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(10) required final int accountId,
|
||||
@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._();
|
||||
|
||||
factory _SnRealm.fromJson(Map<String, dynamic> json) = _$SnRealmImpl.fromJson;
|
||||
@ -844,6 +865,8 @@ abstract class _SnRealm extends SnRealm {
|
||||
@override
|
||||
@HiveField(12)
|
||||
bool get isCommunity;
|
||||
@override
|
||||
int get popularity;
|
||||
|
||||
/// Create a copy of SnRealm
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
|
@ -128,6 +128,7 @@ _$SnRealmImpl _$$SnRealmImplFromJson(Map<String, dynamic> json) =>
|
||||
accountId: (json['account_id'] as num).toInt(),
|
||||
isPublic: json['is_public'] as bool,
|
||||
isCommunity: json['is_community'] as bool,
|
||||
popularity: (json['popularity'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$SnRealmImplToJson(_$SnRealmImpl instance) =>
|
||||
@ -146,4 +147,5 @@ Map<String, dynamic> _$$SnRealmImplToJson(_$SnRealmImpl instance) =>
|
||||
'account_id': instance.accountId,
|
||||
'is_public': instance.isPublic,
|
||||
'is_community': instance.isCommunity,
|
||||
'popularity': instance.popularity,
|
||||
};
|
||||
|
@ -15,6 +15,7 @@ class RealmItemWidget extends StatelessWidget {
|
||||
final List<PopupMenuItem>? actionListView;
|
||||
final Function? onUpdate;
|
||||
final Function? onTap;
|
||||
final bool showPopularity;
|
||||
|
||||
const RealmItemWidget({
|
||||
super.key,
|
||||
@ -23,6 +24,7 @@ class RealmItemWidget extends StatelessWidget {
|
||||
this.actionListView,
|
||||
this.onUpdate,
|
||||
this.onTap,
|
||||
this.showPopularity = true,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -35,13 +37,27 @@ class RealmItemWidget extends StatelessWidget {
|
||||
fallbackWidget: const Icon(Symbols.group, size: 20),
|
||||
),
|
||||
title: Text(item.name),
|
||||
subtitle: Text(
|
||||
item.description,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
subtitle: Row(
|
||||
children: [
|
||||
if (showPopularity) const Icon(Symbols.local_fire_department, size: 18).padding(right: 1),
|
||||
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: () {
|
||||
if (onTap != null) {
|
||||
onTap!();
|
||||
return;
|
||||
}
|
||||
GoRouter.of(context).pushNamed(
|
||||
'realmDetail',
|
||||
pathParameters: {'alias': item.alias},
|
||||
@ -100,13 +116,23 @@ class RealmItemWidget extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
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!),
|
||||
],
|
||||
).padding(horizontal: 24, bottom: 14),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
if (onTap != null) onTap!();
|
||||
if (onTap != null) {
|
||||
onTap!();
|
||||
return;
|
||||
}
|
||||
GoRouter.of(context).pushNamed(
|
||||
'realmDetail',
|
||||
pathParameters: {'alias': item.alias},
|
||||
|
Loading…
x
Reference in New Issue
Block a user