Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor 008: Error Handling #534

Merged
merged 7 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode/**

5 changes: 5 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rebase:
git rebase -i dev

push:
git push --set-upstream origin @
17 changes: 11 additions & 6 deletions violet/lib/component/hitomi/hitomi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,17 @@ class QueryTranslator {
where += parseParentheses(token, negative);
where += parseExpression();
where += nextToken();
if (hasMoreTokens()) {
where += parseLogicalExpression();
}
} else if (token == ')') {
return token;
} else {
where += parseTitle(token, negative);
}

if (hasMoreTokens() && lookAhead() != ')') {
String logicalOp = parseLogicalOperator();
where += logicalOp + parseExpression();
where += parseLogicalExpression();
}

return where;
Expand Down Expand Up @@ -393,18 +395,21 @@ class QueryTranslator {
return negative ? "Title NOT LIKE '%$token%'" : "Title LIKE '%$token%'";
}

String parseLogicalOperator() {
String parseLogicalExpression() {
String next = lookAhead();
late String op;
if (next.toLowerCase() == 'or') {
nextToken();
return ' OR ';
op = 'OR';
} else {
op = 'AND';
}
return ' AND ';
return ' $op ${parseExpression()}';
}

String nextToken() => tokens[index++];
String lookAhead() => index < tokens.length ? tokens[index] : '';
bool hasMoreTokens() => index < tokens.length - 1;
bool hasMoreTokens() => index < tokens.length;

static String findColumnByTag(String tag) {
switch (tag) {
Expand Down
6 changes: 3 additions & 3 deletions violet/lib/pages/settings/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,14 @@ class _SettingsPageState extends State<SettingsPage>
title: Text(Translations.instance!.trans('excludetag')),
trailing: const Icon(Icons.keyboard_arrow_right),
onTap: () async {
final vv = await showDialog(
final vv = await showDialog<(int, String)?>(
context: context,
builder: (BuildContext context) =>
const TagSelectorDialog(what: 'exclude'),
);

if (vv.$1 == 1) {
Settings.setExcludeTags(vv.$2);
if (vv?.$1 == 1) {
Settings.setExcludeTags(vv!.$2);
setState(() {
_shouldReload = true;
});
Expand Down
13 changes: 7 additions & 6 deletions violet/lib/pages/viewer/horizontal_viewer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
return Obx(
() => Stack(
children: [
Visibility.maintain(
child: OrientationBuilder(builder: (context, orientation) {
c.jump(c.page.value);
return const SizedBox.shrink();
}),
),
// TODO: 없어도 될 것 같은데 뭐지
// Visibility.maintain(
// child: OrientationBuilder(builder: (context, orientation) {
// c.jump(c.page.value);
// return const SizedBox.shrink();
// }),
// ),
Container(
decoration: const BoxDecoration(
color: Colors.black,
Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/viewer/image/file_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class ImageCropBookmark extends StatelessWidget {
'$articleId(${page}p): [${area.toString().split('(')[1].split(')')[0]}] Saved!',
);

if (!context.mounted) return;
// ignore: use_build_context_synchronously
Navigator.pop(context);
}
}
2 changes: 1 addition & 1 deletion violet/lib/pages/viewer/image/provider_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class ImageCropBookmark extends StatelessWidget {
'$articleId(${page}p): [${area.toString().split('(')[1].split(')')[0]}] Saved!',
);

if (!context.mounted) return;
// ignore: use_build_context_synchronously
Navigator.pop(context);
}
}
1 change: 1 addition & 0 deletions violet/makefile
2 changes: 1 addition & 1 deletion violet/test/query_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void main() {
expect(result1,
'SELECT * FROM HitomiColumnModel WHERE Tags LIKE \'%|female:sole female|%\' AND NOT (Tags LIKE \'%|female:mother|%\' AND Tags LIKE \'%|female:milf|%\') AND ExistOnHitomi=1');
expect(result2,
'SELECT * FROM HitomiColumnModel WHERE (Language LIKE \'%korean%\' OR Language LIKE \'%n/a%\') AND ExistOnHitomi=1');
'SELECT * FROM HitomiColumnModel WHERE (Language LIKE \'%korean%\' OR Language LIKE \'%n/a%\') AND (Tags LIKE \'%|female:sole female|%\') IS NOT 1 AND ExistOnHitomi=1');
});
});
}
Loading