mobile bluesky app made with flutter lazurite.stormlightlabs.org/
mobile bluesky flutter
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 158 lines 5.3 kB view raw
1part of 'dev_tools_cubit.dart'; 2 3enum DevToolsStatus { initial, loading, repoLoaded, collectionLoaded, recordLoaded, loadingMore, error } 4 5class CollectionSummary extends Equatable { 6 const CollectionSummary(this.name, {this.recordCount}); 7 8 final String name; 9 final int? recordCount; 10 11 String get countLabel => recordCount == null ? '...' : '$recordCount'; 12 13 @override 14 List<Object?> get props => [name, recordCount]; 15} 16 17class RecordInfo extends Equatable { 18 const RecordInfo({required this.uri, this.cid, required this.value}); 19 20 final String uri; 21 final String? cid; 22 final Map<String, dynamic> value; 23 24 String get rkey { 25 try { 26 return AtUri.parse(uri).rkey; 27 } catch (_) { 28 return ''; 29 } 30 } 31 32 String get atUriToLink { 33 final uriString = uri.replaceFirst('at://', ''); 34 return 'https://aturi.to/$uriString'; 35 } 36 37 @override 38 List<Object?> get props => [uri, cid, value]; 39} 40 41const _devToolsStateNoChange = Object(); 42 43class DevToolsState extends Equatable { 44 const DevToolsState({ 45 this.status = DevToolsStatus.initial, 46 this.did, 47 this.repoServiceHost, 48 this.handle, 49 this.repoHandle, 50 this.typeaheadActors = const [], 51 this.isTypeaheadLoading = false, 52 this.collections = const [], 53 this.isCollectionCountsLoading = false, 54 this.selectedCollection, 55 this.records, 56 this.recordsCursor, 57 this.selectedRecord, 58 this.isCollectionLoading = false, 59 this.isRecordLoading = false, 60 this.errorMessage, 61 }); 62 63 final DevToolsStatus status; 64 final String? did; 65 final String? repoServiceHost; 66 final String? handle; 67 final String? repoHandle; 68 final List<ProfileViewBasic> typeaheadActors; 69 final bool isTypeaheadLoading; 70 final List<CollectionSummary> collections; 71 final bool isCollectionCountsLoading; 72 final String? selectedCollection; 73 final List<RepoListRecordsRecord>? records; 74 final String? recordsCursor; 75 final RecordInfo? selectedRecord; 76 final bool isCollectionLoading; 77 final bool isRecordLoading; 78 final String? errorMessage; 79 80 bool get isLoading => status == DevToolsStatus.loading || status == DevToolsStatus.loadingMore; 81 bool get isNavigating => isCollectionLoading || isRecordLoading; 82 bool get hasMoreRecords => recordsCursor != null && recordsCursor!.isNotEmpty; 83 int get totalRecords => records?.length ?? 0; 84 int? get totalRepoRecords { 85 if (collections.isEmpty) { 86 return 0; 87 } 88 if (collections.any((collection) => collection.recordCount == null)) { 89 return null; 90 } 91 92 return collections.fold<int>(0, (sum, collection) => sum + collection.recordCount!); 93 } 94 95 DevToolsState copyWith({ 96 DevToolsStatus? status, 97 Object? did = _devToolsStateNoChange, 98 Object? repoServiceHost = _devToolsStateNoChange, 99 Object? handle = _devToolsStateNoChange, 100 Object? repoHandle = _devToolsStateNoChange, 101 List<ProfileViewBasic>? typeaheadActors, 102 bool? isTypeaheadLoading, 103 List<CollectionSummary>? collections, 104 bool? isCollectionCountsLoading, 105 Object? selectedCollection = _devToolsStateNoChange, 106 Object? records = _devToolsStateNoChange, 107 Object? recordsCursor = _devToolsStateNoChange, 108 Object? selectedRecord = _devToolsStateNoChange, 109 bool? isCollectionLoading, 110 bool? isRecordLoading, 111 Object? errorMessage = _devToolsStateNoChange, 112 }) { 113 return DevToolsState( 114 status: status ?? this.status, 115 did: identical(did, _devToolsStateNoChange) ? this.did : did as String?, 116 repoServiceHost: identical(repoServiceHost, _devToolsStateNoChange) 117 ? this.repoServiceHost 118 : repoServiceHost as String?, 119 handle: identical(handle, _devToolsStateNoChange) ? this.handle : handle as String?, 120 repoHandle: identical(repoHandle, _devToolsStateNoChange) ? this.repoHandle : repoHandle as String?, 121 typeaheadActors: typeaheadActors ?? this.typeaheadActors, 122 isTypeaheadLoading: isTypeaheadLoading ?? this.isTypeaheadLoading, 123 collections: collections ?? this.collections, 124 isCollectionCountsLoading: isCollectionCountsLoading ?? this.isCollectionCountsLoading, 125 selectedCollection: identical(selectedCollection, _devToolsStateNoChange) 126 ? this.selectedCollection 127 : selectedCollection as String?, 128 records: identical(records, _devToolsStateNoChange) ? this.records : records as List<RepoListRecordsRecord>?, 129 recordsCursor: identical(recordsCursor, _devToolsStateNoChange) ? this.recordsCursor : recordsCursor as String?, 130 selectedRecord: identical(selectedRecord, _devToolsStateNoChange) 131 ? this.selectedRecord 132 : selectedRecord as RecordInfo?, 133 isCollectionLoading: isCollectionLoading ?? this.isCollectionLoading, 134 isRecordLoading: isRecordLoading ?? this.isRecordLoading, 135 errorMessage: identical(errorMessage, _devToolsStateNoChange) ? this.errorMessage : errorMessage as String?, 136 ); 137 } 138 139 @override 140 List<Object?> get props => [ 141 status, 142 did, 143 repoServiceHost, 144 handle, 145 repoHandle, 146 typeaheadActors, 147 isTypeaheadLoading, 148 collections, 149 isCollectionCountsLoading, 150 selectedCollection, 151 records, 152 recordsCursor, 153 selectedRecord, 154 isCollectionLoading, 155 isRecordLoading, 156 errorMessage, 157 ]; 158}