Phase 0 foundation for Docwell, an open-source knowledge base: - Database: PocketBase v0.40.6 with initial schema migrations; users is the built-in auth collection, plus a hook for token checks and env-driven app URL/SMTP settings - Server: Go API (health, version, auth endpoints forwarded to PocketBase, admin user list) with an embedded Vue admin panel - Web-App: Go static server and Vue/Tailwind app with Tiptap editor, sign-in, sign-up, password reset and email verification (EN/PL) - Desktop-App: Wails v3 host reusing the web app - Phone-App: Flutter app with sign-in - Shared packages (editor, ui, api-client), OpenAPI spec, Docker compose (separate services and all-in-one), GitHub Actions CI - Docs: feature inventory and architecture/build plan Licensed under AGPL-3.0-or-later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
196 lines
6.1 KiB
Dart
196 lines
6.1 KiB
Dart
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'api/docwell_api.dart';
|
|
|
|
void main() {
|
|
runApp(const DocwellApp());
|
|
}
|
|
|
|
// Android emulators reach the host machine at 10.0.2.2.
|
|
const defaultServerUrl = 'http://10.0.2.2:8080';
|
|
|
|
class DocwellApp extends StatefulWidget {
|
|
const DocwellApp({super.key, this.api});
|
|
|
|
final DocwellApi? api;
|
|
|
|
@override
|
|
State<DocwellApp> createState() => _DocwellAppState();
|
|
}
|
|
|
|
class _DocwellAppState extends State<DocwellApp> {
|
|
late final DocwellApi _api = widget.api ?? DocwellApi(defaultServerUrl);
|
|
// Kept in memory only for now; secure storage comes with the full mobile app.
|
|
User? _user;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
const brand = Color(0xFF2F5FD0);
|
|
return MaterialApp(
|
|
title: 'Docwell',
|
|
theme: ThemeData(colorSchemeSeed: brand, useMaterial3: true),
|
|
darkTheme: ThemeData(colorSchemeSeed: brand, brightness: Brightness.dark, useMaterial3: true),
|
|
home: _user == null
|
|
? LoginScreen(api: _api, onSignedIn: (u) => setState(() => _user = u))
|
|
: HomeScreen(
|
|
api: _api,
|
|
user: _user!,
|
|
onSignOut: () => setState(() {
|
|
_api.logout();
|
|
_user = null;
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
const LoginScreen({super.key, required this.api, required this.onSignedIn});
|
|
|
|
final DocwellApi api;
|
|
final ValueChanged<User> onSignedIn;
|
|
|
|
@override
|
|
State<LoginScreen> createState() => _LoginScreenState();
|
|
}
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
final _email = TextEditingController();
|
|
final _password = TextEditingController();
|
|
bool _busy = false;
|
|
String? _error;
|
|
|
|
static const _messages = {
|
|
'invalid_credentials': 'Wrong email or password.',
|
|
'account_disabled': 'This account is disabled.',
|
|
'mfa_required': 'Two-step sign-in is not supported in the app yet.',
|
|
};
|
|
|
|
Future<void> _submit() async {
|
|
setState(() {
|
|
_busy = true;
|
|
_error = null;
|
|
});
|
|
try {
|
|
widget.onSignedIn(await widget.api.login(_email.text.trim(), _password.text));
|
|
} on DocwellApiException catch (e) {
|
|
setState(() => _error = _messages[e.code] ?? 'Sign-in failed.');
|
|
} catch (_) {
|
|
setState(() => _error = "Can't reach the server.");
|
|
} finally {
|
|
if (mounted) setState(() => _busy = false);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_email.dispose();
|
|
_password.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(24),
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 400),
|
|
child: AutofillGroup(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text('Sign in to Docwell', style: Theme.of(context).textTheme.headlineSmall),
|
|
const SizedBox(height: 24),
|
|
TextField(
|
|
key: const Key('email'),
|
|
controller: _email,
|
|
keyboardType: TextInputType.emailAddress,
|
|
autofillHints: const [AutofillHints.email],
|
|
decoration: const InputDecoration(labelText: 'Email', border: OutlineInputBorder()),
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextField(
|
|
key: const Key('password'),
|
|
controller: _password,
|
|
obscureText: true,
|
|
autofillHints: const [AutofillHints.password],
|
|
onSubmitted: (_) => _submit(),
|
|
decoration: const InputDecoration(labelText: 'Password', border: OutlineInputBorder()),
|
|
),
|
|
if (_error != null) ...[
|
|
const SizedBox(height: 12),
|
|
Text(_error!, style: TextStyle(color: Theme.of(context).colorScheme.error)),
|
|
],
|
|
const SizedBox(height: 20),
|
|
FilledButton(onPressed: _busy ? null : _submit, child: const Text('Sign in')),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
const HomeScreen({super.key, required this.api, required this.user, required this.onSignOut});
|
|
|
|
final DocwellApi api;
|
|
final User user;
|
|
final VoidCallback onSignOut;
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
late Future<String> _version = widget.api.version();
|
|
|
|
void _retry() => setState(() => _version = widget.api.version());
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Docwell'),
|
|
actions: [TextButton(onPressed: widget.onSignOut, child: const Text('Sign out'))],
|
|
),
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text('Hello, ${widget.user.name}', style: Theme.of(context).textTheme.titleLarge),
|
|
const SizedBox(height: 16),
|
|
FutureBuilder<String>(
|
|
future: _version,
|
|
builder: (context, snap) {
|
|
if (snap.connectionState != ConnectionState.done) {
|
|
return const CircularProgressIndicator();
|
|
}
|
|
if (snap.hasError) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Text('Server unreachable'),
|
|
const SizedBox(height: 12),
|
|
FilledButton(onPressed: _retry, child: const Text('Retry')),
|
|
],
|
|
);
|
|
}
|
|
return Text('Connected · v${snap.data}');
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|