Skip to content

Commit

Permalink
fix: only reload first
Browse files Browse the repository at this point in the history
  • Loading branch information
evan361425 committed Sep 17, 2024
1 parent 9a7b02c commit a0d66c6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion assets/l10n/en/transit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ GS:
empty:
label: Select Spreadsheet
hint: Once you choose the spreadsheet to import, you can start importing data.
dropdownHint: Sheet to Import
dropdownHint: Select desired sheet
confirm:
- This action will {hint}
- hint:
Expand Down
2 changes: 1 addition & 1 deletion assets/l10n/zh/transit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ GS:
empty:
label: 選擇試算表
hint: 選擇要匯入的試算表後,就能開始匯入資料
dropdownHint: 匯入的表單
dropdownHint: 選擇欲匯入的表單
confirm: 此動作將會{hint}
selectionHint:
- _: 輸入試算表網址或試算表 ID
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@@locale": "en",
"@@last_modified": "2024-09-16T01:27:44.582362Z",
"@@last_modified": "2024-09-17T01:42:01.939663Z",
"@@author": "Lu Shueh Chou",
"settingTab": "Settings",
"settingVersion": "Version: {version}",
Expand Down Expand Up @@ -387,7 +387,7 @@
"transitGSSpreadsheetImportExistHint": "Get all sheet names from the spreadsheet and ready to import.",
"transitGSSpreadsheetImportEmptyLabel": "Select Spreadsheet",
"transitGSSpreadsheetImportEmptyHint": "Once you choose the spreadsheet to import, you can start importing data.",
"transitGSSpreadsheetImportDropdownHint": "Sheet to Import",
"transitGSSpreadsheetImportDropdownHint": "Select desired sheet",
"transitGSSpreadsheetConfirm": "This action will {hint}",
"@transitGSSpreadsheetConfirm": {
"placeholders": {
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@@locale": "zh",
"@@last_modified": "2024-09-16T01:27:44.603687Z",
"@@last_modified": "2024-09-17T01:42:02.002121Z",
"@@author": "Lu Shueh Chou",
"settingTab": "設定",
"settingVersion": "版本:{version}",
Expand Down Expand Up @@ -387,7 +387,7 @@
"transitGSSpreadsheetImportExistHint": "從試算表中取得所有表單的名稱,並進行匯入",
"transitGSSpreadsheetImportEmptyLabel": "選擇試算表",
"transitGSSpreadsheetImportEmptyHint": "選擇要匯入的試算表後,就能開始匯入資料",
"transitGSSpreadsheetImportDropdownHint": "匯入的表單",
"transitGSSpreadsheetImportDropdownHint": "選擇欲匯入的表單",
"transitGSSpreadsheetConfirm": "此動作將會{hint}",
"@transitGSSpreadsheetConfirm": {
"placeholders": {
Expand Down
34 changes: 15 additions & 19 deletions lib/models/repository/seller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,22 @@ class Seller extends ChangeNotifier {

final result = await Future.wait(queries);

try {
final order = result[0][0];
int? productCount;
int? ingredientCount;
int? attrCount;
if (countingAll) {
productCount = result[1][0]['count'] as int;
ingredientCount = result[2][0]['count'] as int;
attrCount = result[3][0]['count'] as int;
}

return OrderMetrics.fromMap(
order,
productCount: productCount,
ingredientCount: ingredientCount,
attrCount: attrCount,
);
} catch (e) {
return OrderMetrics.fromMap(const {});
final order = result[0][0];
int? productCount;
int? ingredientCount;
int? attrCount;
if (countingAll) {
productCount = result[1][0]['count'] as int;
ingredientCount = result[2][0]['count'] as int;
attrCount = result[3][0]['count'] as int;
}

return OrderMetrics.fromMap(
order,
productCount: productCount,
ingredientCount: ingredientCount,
attrCount: attrCount,
);
}

/// Get the metric of orders grouped by the day.
Expand Down
16 changes: 8 additions & 8 deletions lib/services/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ class Database {
final limitQuery = limit == null ? '' : 'LIMIT $offset, $limit';
final joinQuery = join == null ? '' : join.toString();

try {
return await db.rawQuery(
'SELECT $selectQuery FROM $table $joinQuery $whereQuery $groupByQuery $orderByQuery $limitQuery',
whereArgs,
);
} catch (e, stack) {
return db
.rawQuery(
'SELECT $selectQuery FROM $table $joinQuery $whereQuery $groupByQuery $orderByQuery $limitQuery',
whereArgs,
)
.catchError((e, stack) {
Log.err(e, 'db_query_error', stack);
return [];
}
return <Map<String, Object?>>[];
});
}

Future<int> update(
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/analysis/widgets/reloadable_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class _ReloadableCardState<T> extends State<ReloadableCard<T>> with AutomaticKee
/// Last built target, used to prevent rebuild when reloading
Widget? lastBuiltTarget;

Future<T>? lastFuture;

@override
Widget build(BuildContext context) {
super.build(context);
Expand Down Expand Up @@ -145,7 +147,7 @@ class _ReloadableCardState<T> extends State<ReloadableCard<T>> with AutomaticKee
key: Key('anal_card.${widget.id}'),
onVisibilityChanged: (info) async {
// if partially visible
if (info.visibleFraction > 0) {
if (info.visibleFraction > 0.1) {
await reload();
}
},
Expand Down Expand Up @@ -196,12 +198,10 @@ class _ReloadableCardState<T> extends State<ReloadableCard<T>> with AutomaticKee
Future<void> reload() async {
// only reload when data changed
if (reloadable) {
reloadable = false;
lastBuiltTarget = null;
final inline = await load();

setState(() {
// TODO: avoid run conflict with handleUpdate
reloadable = false;
lastBuiltTarget = null;
data = inline;
Expand Down
5 changes: 3 additions & 2 deletions test/ui/transit/transit_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ void main() {

for (var key in keys) {
await tester.tap(find.byKey(Key(key)));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pop')));
await tester.pump(const Duration(milliseconds: 100));
await tester.pump(const Duration(milliseconds: 100));
await tester.tap(find.byKey(const Key('pop')).last);
await tester.pumpAndSettle();
}

Expand Down

0 comments on commit a0d66c6

Please sign in to comment.