more refactors and logs page handling

This commit is contained in:
shenlong-tanwen
2024-10-23 02:30:46 +05:30
parent 8f47645cdb
commit a0afea04d8
90 changed files with 2386 additions and 584 deletions
@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -55,15 +57,15 @@ class _LoginPageState extends State<LoginPage>
void _onLoginPageStateChange(BuildContext context, LoginPageState state) {
if (state.isLoginSuccessful) {
context.replaceRoute(const TabControllerRoute());
unawaited(context.replaceRoute(const TabControllerRoute()));
}
}
@override
Widget build(BuildContext context) {
final PreferredSizeWidget? appBar;
late final Widget primaryBody;
late final Widget secondaryBody;
final Widget primaryBody;
final Widget secondaryBody;
Widget rotatingLogo = GestureDetector(
onDoubleTap: _populateDemoCredentials,
@@ -73,7 +75,7 @@ class _LoginPageState extends State<LoginPage>
children: [
RotationTransition(
turns: _animationController,
child: const ImLogo(width: 100),
child: const ImLogo(dimension: 100),
),
const SizedGap.lh(),
const ImLogoText(),
@@ -104,7 +106,7 @@ class _LoginPageState extends State<LoginPage>
),
),
TextButton(
onPressed: () => context.navigateRoot(const LogsRoute()),
onPressed: () => unawaited(context.navigateRoot(const LogsRoute())),
child: const Text('Logs'),
),
],
@@ -122,7 +124,9 @@ class _LoginPageState extends State<LoginPage>
fontWeight: FontWeight.w500,
),
child: InkWell(
onTap: () => launchUrl(Uri.parse(_serverUrlController.text)),
onTap: () => unawaited(
launchUrl(Uri.parse(_serverUrlController.text)),
),
child: Text(
_serverUrlController.text,
textAlign: TextAlign.center,
@@ -157,12 +161,12 @@ class _LoginPageState extends State<LoginPage>
bottom,
]),
);
secondaryBody = const SizedBox.shrink();
}
return BlocListener<LoginPageCubit, LoginPageState>(
listener: _onLoginPageStateChange,
child: Scaffold(
resizeToAvoidBottomInset: false,
appBar: appBar,
body: SafeArea(
child: ImAdaptiveScaffoldBody(
@@ -170,6 +174,7 @@ class _LoginPageState extends State<LoginPage>
secondaryBody: (_) => secondaryBody,
),
),
resizeToAvoidBottomInset: false,
),
);
}
@@ -182,13 +187,14 @@ class _MobileAppBar extends StatelessWidget implements PreferredSizeWidget {
Widget build(BuildContext context) {
return AppBar(
automaticallyImplyLeading: false,
scrolledUnderElevation: 0.0,
actions: [
IconButton(
onPressed: () => context.navigateRoot(const SettingsRoute()),
onPressed: () =>
unawaited(context.navigateRoot(const SettingsRoute())),
icon: const Icon(Symbols.settings),
),
],
scrolledUnderElevation: 0.0,
);
}
@@ -61,7 +61,7 @@ class LoginPageCubit extends Cubit<LoginPageState> with LogMixin {
// Check for /.well-known/immich
url = await loginService.resolveEndpoint(uri);
di<IStoreRepository>().upsert(StoreKey.serverEndpoint, url);
await di<IStoreRepository>().upsert(StoreKey.serverEndpoint, url);
await di<LoginService>().handlePostUrlResolution(url);
emit(state.copyWith(isServerValidated: true));
@@ -34,14 +34,14 @@ class LoginForm extends StatelessWidget {
builder: (_, isServerValidated) => SingleChildScrollView(
child: AnimatedSwitcher(
duration: Durations.medium1,
layoutBuilder: (current, previous) =>
current ?? (previous.lastOrNull ?? const SizedBox.shrink()),
child: isServerValidated
? _CredentialsForm(
emailController: emailController,
passwordController: passwordController,
)
: _ServerForm(controller: serverUrlController),
layoutBuilder: (current, previous) =>
current ?? (previous.lastOrNull ?? const SizedBox.shrink()),
),
),
);
@@ -75,13 +75,13 @@ class _ServerFormState extends State<_ServerForm> {
child: BlocSelector<LoginPageCubit, LoginPageState, bool>(
selector: (model) => model.isValidationInProgress,
builder: (_, isValidationInProgress) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ImTextFormField(
controller: widget.controller,
label: context.t.login.label.endpoint,
validator: context.read<LoginPageCubit>().validateServerUrl,
label: context.t.login.label.endpoint,
autoFillHints: const [AutofillHints.url],
keyboardType: TextInputType.url,
textInputAction: TextInputAction.go,
@@ -89,10 +89,10 @@ class _ServerFormState extends State<_ServerForm> {
),
const SizedGap.mh(),
ImFilledButton(
label: context.t.login.label.next_button,
icon: Symbols.arrow_forward_rounded,
onPressed: () => unawaited(_validateForm(context)),
isDisabled: isValidationInProgress,
label: context.t.login.label.next_button,
),
const SizedGap.mh(),
if (isValidationInProgress) const ImLoadingIndicator(),
@@ -117,11 +117,11 @@ class _CredentialsForm extends StatefulWidget {
}
class _CredentialsFormState extends State<_CredentialsForm> {
final passwordFocusNode = FocusNode();
final _passwordFocusNode = FocusNode();
@override
void dispose() {
passwordFocusNode.dispose();
_passwordFocusNode.dispose();
super.dispose();
}
@@ -134,28 +134,27 @@ class _CredentialsFormState extends State<_CredentialsForm> {
: ValueListenableBuilder(
valueListenable: di<ServerFeatureConfigProvider>(),
builder: (_, state, __) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (state.features.hasPasswordLogin) ...[
ImTextFormField(
controller: widget.emailController,
label: context.t.login.label.email,
isDisabled: isValidationInProgress,
textInputAction: TextInputAction.next,
onSubmitted: (_) => passwordFocusNode.requestFocus(),
isDisabled: isValidationInProgress,
onSubmitted: (_) => _passwordFocusNode.requestFocus(),
),
const SizedGap.mh(),
ImPasswordFormField(
controller: widget.passwordController,
focusNode: _passwordFocusNode,
label: context.t.login.label.password,
focusNode: passwordFocusNode,
isDisabled: isValidationInProgress,
textInputAction: TextInputAction.go,
isDisabled: isValidationInProgress,
),
const SizedGap.mh(),
ImFilledButton(
label: context.t.login.label.login_button,
icon: Symbols.login_rounded,
onPressed: () => unawaited(
context.read<LoginPageCubit>().passwordLogin(
@@ -163,31 +162,32 @@ class _CredentialsFormState extends State<_CredentialsForm> {
password: widget.passwordController.text,
),
),
label: context.t.login.label.login_button,
),
// Divider when both password and oAuth login is enabled
if (state.features.hasOAuthLogin) const Divider(),
],
if (state.features.hasOAuthLogin)
ImFilledButton(
label: state.config.oauthButtonText ??
context.t.login.label.oauth_button,
icon: Symbols.pin_rounded,
onPressed: () => unawaited(
context.read<LoginPageCubit>().oAuthLogin(),
),
label: state.config.oauthButtonText ??
context.t.login.label.oauth_button,
),
if (!state.features.hasPasswordLogin &&
!state.features.hasOAuthLogin)
ImFilledButton(
label: context.t.login.label.login_disabled,
isDisabled: true,
label: context.t.login.label.login_disabled,
),
const SizedGap.sh(),
ImTextButton(
label: context.t.login.label.back_button,
icon: Symbols.arrow_back_rounded,
onPressed:
context.read<LoginPageCubit>().resetServerValidation,
label: context.t.login.label.back_button,
),
],
),