Skip to content

Commit

Permalink
feat: universal settings page (#165)
Browse files Browse the repository at this point in the history
Fixes #164
  • Loading branch information
lollipopkit authored Sep 13, 2024
1 parent c1b3d0a commit 6604668
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 320 deletions.
46 changes: 0 additions & 46 deletions lib/core/route/page.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/data/model/chat/history/history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ final class ChatContent {
}

/// {@macro img_url_to_api}
///
///
/// Seperate from [toApi] to decouple the logic
static Future<String> contentToApi(String raw) async {
final isLocal = raw.isFileUrl(false);
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Future<void> _initApp() async {

await Paths.init(Build.name, bakName: Miscs.bakFileName);
await _initDb();

_setupLogger();
_initAppComponents();
}
Expand Down
43 changes: 43 additions & 0 deletions lib/view/page/home/appbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ final class _CustomAppBar extends CustomAppBar {

return CustomAppBar(
centerTitle: false,
leading: Btn.icon(
icon: const Icon(Icons.settings),
onTap: () async {
final ret = await SettingsPage.route.go(
context,
const SettingsPageArgs(),
);
if (ret?.restored == true) {
HomePage.afterRestore();
}
},
),
title: GestureDetector(
onLongPress: () => DebugPage.route.go(
context,
Expand Down Expand Up @@ -113,3 +125,34 @@ final class _CustomAppBar extends CustomAppBar {
);
}
}

// Future<void> _onLongTapSetting(
// BuildContext context,
// PersistentStore store,
// ) async {
// final map = store.box.toJson(includeInternal: false);
// final keys = map.keys;

// /// Encode [map] to String with indent `\t`
// final text = const JsonEncoder.withIndent(' ').convert(map);
// final result = await PlainEditPage.route.go(
// context,
// args: PlainEditPageArgs(
// initialText: text,
// title: store.box.name,
// ),
// );
// if (result == null) return;

// try {
// final newSettings = json.decode(result) as Map<String, dynamic>;
// store.box.putAll(newSettings);
// final newKeys = newSettings.keys;
// final removedKeys = keys.where((e) => !newKeys.contains(e));
// for (final key in removedKeys) {
// Stores.setting.box.delete(key);
// }
// } catch (e, s) {
// context.showErrDialog(e, s);
// }
// }
122 changes: 0 additions & 122 deletions lib/view/page/home/drawer.dart

This file was deleted.

5 changes: 4 additions & 1 deletion lib/view/page/home/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ enum HomePageEnum {
final addBtn = TextButton(
onPressed: () {
context.pop();
Routes.profile.go(context);
SettingsPage.route.go(
context,
const SettingsPageArgs(tabIndex: SettingsTab.profile),
);
},
child: Text(libL10n.add),
);
Expand Down
5 changes: 1 addition & 4 deletions lib/view/page/home/home.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math' as math;

Expand All @@ -12,7 +11,6 @@ import 'package:flutter/services.dart';
import 'package:gpt_box/core/util/sync.dart';
//import 'package:flutter_tiktoken/flutter_tiktoken.dart';
import 'package:gpt_box/data/model/chat/history/share.dart';
import 'package:gpt_box/core/route/page.dart';
import 'package:gpt_box/core/util/chat_title.dart';
import 'package:gpt_box/core/util/tool_func/tool.dart';
import 'package:gpt_box/data/model/chat/config.dart';
Expand All @@ -25,6 +23,7 @@ import 'package:gpt_box/data/res/openai.dart';
import 'package:gpt_box/data/res/rnode.dart';
import 'package:gpt_box/data/res/url.dart';
import 'package:gpt_box/data/store/all.dart';
import 'package:gpt_box/view/page/settings/setting.dart';
import 'package:gpt_box/view/widget/audio.dart';
import 'package:icons_plus/icons_plus.dart';
import 'package:image_picker/image_picker.dart';
Expand All @@ -41,7 +40,6 @@ part 'bottom.dart';
part 'url_scheme.dart';
part 'req.dart';
part 'md_copy.dart';
part 'drawer.dart';
part 'file_picked.dart';

class HomePage extends StatefulWidget {
Expand Down Expand Up @@ -89,7 +87,6 @@ class _HomePageState extends State<HomePage>
return ExitConfirm(
onPop: (_) => ExitConfirm.exitApp(),
child: const Scaffold(
drawer: _Drawer(),
appBar: _CustomAppBar(),
body: _Body(),
bottomNavigationBar: _HomeBottom(isHome: true),
Expand Down
12 changes: 3 additions & 9 deletions lib/view/page/home/url_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,10 @@ abstract final class AppLink {
if (page != null) {
switch (page) {
case 'setting':
Routes.setting.go(context);
return true;
case 'backup':
Routes.backup.go(context);
return true;
case 'about':
Routes.about.go(context);
return true;
case 'res':
Routes.res.go(context);
case 'about':
case 'backup':
SettingsPage.route.go(context, const SettingsPageArgs());
return true;
default:
final msg = l10n.invalidLinkFmt(page);
Expand Down
30 changes: 13 additions & 17 deletions lib/view/page/about.dart → lib/view/page/settings/about.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/material.dart';
import 'package:gpt_box/data/res/github_id.dart';
import 'package:gpt_box/data/res/l10n.dart';
import 'package:gpt_box/data/res/url.dart';
import 'package:url_launcher/url_launcher_string.dart';
part of 'setting.dart';

class AboutPage extends StatelessWidget {
const AboutPage({super.key, Never? args});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(title: Text(libL10n.about)),
body: Center(
child: ListView(
padding: const EdgeInsets.symmetric(horizontal: 17),
children: [
_buildUniLinks(),
_buildLicense(context),
_buildInfo(),
],
return ListView(
padding: const EdgeInsets.symmetric(horizontal: 17),
children: [
UIs.height13,
const Text(
'GPT Box v${Build.build}',
textAlign: TextAlign.center,
),
),
UIs.height13,
_buildUniLinks(),
_buildLicense(context),
_buildInfo(),
],
);
}

Expand Down
Loading

0 comments on commit 6604668

Please sign in to comment.