Add default sortings
This commit is contained in:
parent
c371c3f4fb
commit
e357332a07
|
@ -72,6 +72,24 @@ class ConfigStore extends ChangeNotifier {
|
|||
save();
|
||||
}
|
||||
|
||||
late SortType _defaultSortType;
|
||||
@JsonKey(fromJson: _sortTypeFromJson)
|
||||
SortType get defaultSortType => _defaultSortType;
|
||||
set defaultSortType(SortType defaultSortType) {
|
||||
_defaultSortType = defaultSortType;
|
||||
notifyListeners();
|
||||
save();
|
||||
}
|
||||
|
||||
late PostListingType _defaultListingType;
|
||||
@JsonKey(fromJson: _postListingTypeFromJson)
|
||||
PostListingType get defaultListingType => _defaultListingType;
|
||||
set defaultListingType(PostListingType defaultListingType) {
|
||||
_defaultListingType = defaultListingType;
|
||||
notifyListeners();
|
||||
save();
|
||||
}
|
||||
|
||||
/// Copies over settings from lemmy to [ConfigStore]
|
||||
void copyLemmyUserSettings(LocalUserSettings localUserSettings) {
|
||||
// themes from lemmy-ui that are dark mode
|
||||
|
@ -95,10 +113,8 @@ class ConfigStore extends ChangeNotifier {
|
|||
// : _locale;
|
||||
// TODO: add when it is released
|
||||
// _showScores = localUserSettings.showScores;
|
||||
|
||||
// TODO: should these even be supported? Or we should use our own per-community setting
|
||||
// SortType defaultSortType
|
||||
// PostListingType defaultListingType
|
||||
_defaultSortType = localUserSettings.defaultSortType;
|
||||
_defaultListingType = localUserSettings.defaultListingType;
|
||||
|
||||
notifyListeners();
|
||||
save();
|
||||
|
@ -125,3 +141,9 @@ class ConfigStore extends ChangeNotifier {
|
|||
await prefs.setString(prefsKey, jsonEncode(_$ConfigStoreToJson(this)));
|
||||
}
|
||||
}
|
||||
|
||||
SortType _sortTypeFromJson(String? json) =>
|
||||
json != null ? SortType.fromJson(json) : SortType.hot;
|
||||
// String _sortType
|
||||
PostListingType _postListingTypeFromJson(String? json) =>
|
||||
json != null ? PostListingType.fromJson(json) : PostListingType.all;
|
||||
|
|
|
@ -14,7 +14,10 @@ ConfigStore _$ConfigStoreFromJson(Map<String, dynamic> json) {
|
|||
..locale = LocaleSerde.fromJson(json['locale'] as String?)
|
||||
..showAvatars = json['showAvatars'] as bool? ?? true
|
||||
..showNsfw = json['showNsfw'] as bool? ?? false
|
||||
..showScores = json['showScores'] as bool? ?? true;
|
||||
..showScores = json['showScores'] as bool? ?? true
|
||||
..defaultSortType = _sortTypeFromJson(json['defaultSortType'] as String?)
|
||||
..defaultListingType =
|
||||
_postListingTypeFromJson(json['defaultListingType'] as String?);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$ConfigStoreToJson(ConfigStore instance) =>
|
||||
|
@ -25,6 +28,8 @@ Map<String, dynamic> _$ConfigStoreToJson(ConfigStore instance) =>
|
|||
'showAvatars': instance.showAvatars,
|
||||
'showNsfw': instance.showNsfw,
|
||||
'showScores': instance.showScores,
|
||||
'defaultSortType': instance.defaultSortType,
|
||||
'defaultListingType': instance.defaultListingType,
|
||||
};
|
||||
|
||||
K _$enumDecode<K, V>(
|
||||
|
|
Loading…
Reference in New Issue