fix: some database bugs (#5210)

* fix: open logic for url cell in database

* fix: row date created not working

* fix: help my toasts are burnt

* chore: quote style and add comment
This commit is contained in:
Richard Shiue 2024-04-29 17:34:18 +08:00 committed by GitHub
parent 9135fb94ad
commit e0d6b194bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 28 deletions

View File

@ -4,7 +4,6 @@ import 'dart:io';
import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/widgets/flowy_mobile_quick_action_button.dart'; import 'package:appflowy/mobile/presentation/widgets/flowy_mobile_quick_action_button.dart';
import 'package:appflowy/core/helpers/url_launcher.dart';
import 'package:appflowy/plugins/database/application/cell/cell_controller.dart'; import 'package:appflowy/plugins/database/application/cell/cell_controller.dart';
import 'package:appflowy/plugins/database/application/cell/cell_controller_builder.dart'; import 'package:appflowy/plugins/database/application/cell/cell_controller_builder.dart';
import 'package:appflowy/plugins/database/application/database_controller.dart'; import 'package:appflowy/plugins/database/application/database_controller.dart';
@ -19,6 +18,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:url_launcher/url_launcher.dart';
import '../desktop_grid/desktop_grid_url_cell.dart'; import '../desktop_grid/desktop_grid_url_cell.dart';
import '../desktop_row_detail/desktop_row_detail_url_cell.dart'; import '../desktop_row_detail/desktop_row_detail_url_cell.dart';
@ -214,29 +214,20 @@ class MobileURLEditor extends StatelessWidget {
} }
void openUrlCellLink(String content) async { void openUrlCellLink(String content) async {
String url = ""; late Uri uri;
try { try {
// check protocol is provided uri = Uri.parse(content);
const linkPrefix = [ // `Uri` identifies `localhost` as a scheme
'http://', if (!uri.hasScheme || uri.scheme == 'localhost') {
'https://', uri = Uri.parse("http://$content");
'file://', await InternetAddress.lookup(uri.host);
'ftp://', }
'ftps://',
'mailto:',
];
final shouldAddScheme =
!linkPrefix.any((pattern) => content.startsWith(pattern));
url = shouldAddScheme ? 'http://$content' : content;
// get hostname and check validity
final uri = Uri.parse(url);
final hostName = uri.host;
await InternetAddress.lookup(hostName);
} catch (_) { } catch (_) {
url = "https://www.google.com/search?q=${Uri.encodeComponent(content)}"; uri = Uri.parse(
"https://www.google.com/search?q=${Uri.encodeComponent(content)}",
);
} finally { } finally {
await afLaunchUrlString(url); await launchUrl(uri);
} }
} }

View File

@ -41,8 +41,7 @@ void showMessageToast(
ToastGravity gravity = ToastGravity.BOTTOM, ToastGravity gravity = ToastGravity.BOTTOM,
}) { }) {
final child = FlowyMessageToast(message: message); final child = FlowyMessageToast(message: message);
final toast = context == null ? getIt<FToast>() : FToast() final toast = context == null ? getIt<FToast>() : (FToast()..init(context));
..init(context!);
toast.showToast( toast.showToast(
child: child, child: child,
gravity: gravity, gravity: gravity,

View File

@ -10,7 +10,8 @@ use crate::services::database_view::{
use crate::services::field::{ use crate::services::field::{
default_type_option_data_from_type, select_type_option_from_field, transform_type_option, default_type_option_data_from_type, select_type_option_from_field, transform_type_option,
type_option_data_from_pb, ChecklistCellChangeset, RelationTypeOption, SelectOptionCellChangeset, type_option_data_from_pb, ChecklistCellChangeset, RelationTypeOption, SelectOptionCellChangeset,
StrCellData, TimestampCellData, TypeOptionCellDataHandler, TypeOptionCellExt, StrCellData, TimestampCellData, TimestampCellDataWrapper, TypeOptionCellDataHandler,
TypeOptionCellExt,
}; };
use crate::services::field_settings::{default_field_settings_by_layout_map, FieldSettings}; use crate::services::field_settings::{default_field_settings_by_layout_map, FieldSettings};
use crate::services::filter::{Filter, FilterChangeset}; use crate::services::filter::{Filter, FilterChangeset};
@ -722,12 +723,12 @@ impl DatabaseEditor {
match field_type { match field_type {
FieldType::LastEditedTime | FieldType::CreatedTime => { FieldType::LastEditedTime | FieldType::CreatedTime => {
let row = database.get_row(row_id); let row = database.get_row(row_id);
let cell_data = if field_type.is_created_time() { let wrapped_cell_data = if field_type.is_created_time() {
TimestampCellData::new(row.created_at) TimestampCellDataWrapper::from((field_type, TimestampCellData::new(row.created_at)))
} else { } else {
TimestampCellData::new(row.modified_at) TimestampCellDataWrapper::from((field_type, TimestampCellData::new(row.modified_at)))
}; };
Some(Cell::from(cell_data)) Some(Cell::from(wrapped_cell_data))
}, },
_ => database.get_cell(field_id, row_id).cell, _ => database.get_cell(field_id, row_id).cell,
} }