Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Livinglist committed Jun 1, 2024
1 parent c732510 commit a702889
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 36 deletions.
4 changes: 2 additions & 2 deletions lib/config/locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ Future<void> setUpLocator() async {
),
)
..registerSingleton<SembastRepository>(SembastRepository())
..registerSingleton<RemoteConfigRepository>(RemoteConfigRepository())
..registerSingleton<RemoteConfigCubit>(RemoteConfigCubit())
..registerSingleton<HackerNewsRepository>(HackerNewsRepository())
..registerSingleton<HackerNewsWebRepository>(HackerNewsWebRepository())
..registerSingleton<PreferenceRepository>(PreferenceRepository())
..registerSingleton<SearchRepository>(SearchRepository())
..registerSingleton<AuthRepository>(AuthRepository())
..registerSingleton<PostRepository>(PostRepository())
..registerSingleton<OfflineRepository>(OfflineRepository())
..registerSingleton<RemoteConfigRepository>(RemoteConfigRepository())
..registerSingleton<RemoteConfigCubit>(RemoteConfigCubit())
..registerSingleton<DraftCache>(DraftCache())
..registerSingleton<CommentCache>(CommentCache())
..registerSingleton<LocalNotificationService>(LocalNotificationService())
Expand Down
5 changes: 4 additions & 1 deletion lib/cubits/remote_config/remote_config_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import 'package:hacki/config/locator.dart';
import 'package:hacki/repositories/remote_config_repository.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
Expand All @@ -19,7 +20,9 @@ class RemoteConfigCubit extends HydratedCubit<RemoteConfigState> {
_remoteConfigRepository
.fetchRemoteConfig()
.then((Map<String, dynamic> data) {
emit(state.copyWith(data: data));
if (data.isNotEmpty) {
emit(state.copyWith(data: data));
}
});
}

Expand Down
24 changes: 4 additions & 20 deletions lib/cubits/remote_config/remote_config_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,9 @@ final class RemoteConfigState extends Equatable {

RemoteConfigState.init() : data = <String, dynamic>{};

@protected
final Map<String, dynamic> data;

Map<String, dynamic> get _data {
if (data.isEmpty) {
return <String, dynamic>{
'athingComtrSelector':
'''#hnmain > tbody > tr > td > table > tbody > .athing.comtr''',
'commentTextSelector':
'''td > table > tbody > tr > td.default > div.comment > div.commtext''',
'commentHeadSelector':
'''td > table > tbody > tr > td.default > div > span > a''',
'commentAgeSelector':
'''td > table > tbody > tr > td.default > div > span > span.age''',
'commentIndentSelector': '''td > table > tbody > tr > td.ind''',
};
}
return data;
}

String get athingComtrSelector => getString(
key: 'athingComtrSelector',
fallback:
Expand Down Expand Up @@ -55,15 +39,15 @@ final class RemoteConfigState extends Equatable {
);

String getString({required String key, String fallback = ''}) {
return _data[key] as String? ?? fallback;
return data[key] as String? ?? fallback;
}

bool getBool({required String key, bool fallback = false}) {
return _data[key] as bool? ?? fallback;
return data[key] as bool? ?? fallback;
}

int getInt({required String key, int fallback = 0}) {
return _data[key] as int? ?? fallback;
return data[key] as int? ?? fallback;
}

RemoteConfigState copyWith({Map<String, dynamic>? data}) {
Expand Down
15 changes: 7 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ Future<void> main({bool testing = false}) async {
final String tempPath = tempDir.path;
Hive.init(tempPath);

final HydratedStorage storage = await HydratedStorage.build(
storageDirectory: kIsWeb
? HydratedStorage.webStorageDirectory
: await getTemporaryDirectory(),
);
HydratedBloc.storage = storage;

await setUpLocator();

EquatableConfig.stringify = true;
Expand All @@ -66,12 +73,6 @@ Future<void> main({bool testing = false}) async {
);
};

final HydratedStorage storage = await HydratedStorage.build(
storageDirectory: kIsWeb
? HydratedStorage.webStorageDirectory
: await getTemporaryDirectory(),
);

if (Platform.isIOS) {
unawaited(
Workmanager().initialize(
Expand Down Expand Up @@ -139,8 +140,6 @@ Future<void> main({bool testing = false}) async {
// Uncomment this line to log events from bloc/cubit.
// Bloc.observer = CustomBlocObserver();

HydratedBloc.storage = storage;

VisibilityDetectorController.instance.updateInterval = AppDurations.ms200;

runApp(
Expand Down
9 changes: 4 additions & 5 deletions lib/repositories/hacker_news_web_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,15 @@ class HackerNewsWebRepository {
_remoteConfigCubit.state.athingComtrSelector;

String get _commentTextSelector =>
_remoteConfigCubit.state.athingComtrSelector;
_remoteConfigCubit.state.commentTextSelector;

String get _commentHeadSelector =>
_remoteConfigCubit.state.athingComtrSelector;
_remoteConfigCubit.state.commentHeadSelector;

String get _commentAgeSelector =>
_remoteConfigCubit.state.athingComtrSelector;
String get _commentAgeSelector => _remoteConfigCubit.state.commentAgeSelector;

String get _commentIndentSelector =>
_remoteConfigCubit.state.athingComtrSelector;
_remoteConfigCubit.state.commentIndentSelector;

Stream<Comment> fetchCommentsStream(Item item) async* {
final bool isOnWifi = await _isOnWifi;
Expand Down

0 comments on commit a702889

Please sign in to comment.