Skip to content

Commit

Permalink
Merge pull request #71 from OpenPecha/home
Browse files Browse the repository at this point in the history
Home
  • Loading branch information
tentamdin authored Jan 21, 2025
2 parents c37f6b2 + bb6f06c commit 42e10a6
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 57 deletions.
9 changes: 9 additions & 0 deletions lib/repo/database_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ class DatabaseRepository<T> {
);
}

// get to total number of items in the database
Future<int> getCount() async {
final db = await dbHelper.database;
final count = Sqflite.firstIntValue(
await db.rawQuery('SELECT COUNT(*) FROM $tableName'),
);
return count ?? 0;
}

Future<List<T>> getSortedPaginatedOrganization(
int page, int pageSize, String category) async {
final db = await dbHelper.database;
Expand Down
10 changes: 10 additions & 0 deletions lib/states/deties_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DeityListState {
final int page;
final int pageSize;
final String? error;
final int total;

DeityListState({
required this.deities,
Expand All @@ -19,6 +20,7 @@ class DeityListState {
required this.page,
required this.pageSize,
this.error,
required this.total,
});

factory DeityListState.initial() {
Expand All @@ -28,6 +30,7 @@ class DeityListState {
hasReachedMax: false,
page: 0,
pageSize: 20,
total: 0,
);
}

Expand All @@ -38,6 +41,7 @@ class DeityListState {
int? page,
int? pageSize,
String? error,
int? total,
}) {
return DeityListState(
deities: deities ?? this.deities,
Expand All @@ -46,6 +50,7 @@ class DeityListState {
page: page ?? this.page,
pageSize: pageSize ?? this.pageSize,
error: error ?? this.error,
total: total ?? this.total,
);
}
}
Expand Down Expand Up @@ -120,6 +125,11 @@ class DeityNotifier extends StateNotifier<DeityListState> {
}
}

// get the total number of deties in the database
Future<int> getDeitiesCount() async {
return await repository.getCount();
}

void clearSearchResults() {
state = DeityListState.initial();
}
Expand Down
6 changes: 6 additions & 0 deletions lib/states/festival_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class FestivalNotifier extends StateNotifier<FestivalListState> {
}
}

// to get the total number of festivals
Future<int> getFestivalCount() async {
final totalFestivals = await repository.getCount();
return totalFestivals;
}

void clearSearchResults() {
state = FestivalListState.initial();
}
Expand Down
5 changes: 5 additions & 0 deletions lib/states/organization_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ class OrganizationNotifier extends StateNotifier<OrganizationListState> {
}
}

// get total number of organizations
Future<int> getOrganizationCount() async {
return await repository.getCount();
}

void clearSearchResults() {
state = OrganizationListState.initial();
}
Expand Down
Loading

0 comments on commit 42e10a6

Please sign in to comment.