A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat(mobile): minor cleanups to the login page
Mohamed Bassem9b1b2b735b8d
diff --git a/apps/mobile/app/signin.tsx b/apps/mobile/app/signin.tsxindex 61ece071..6bf6817e 100644--- a/apps/mobile/app/signin.tsx+++ b/apps/mobile/app/signin.tsx@@ -1,21 +1,18 @@-import { useRef, useState } from "react";-import {- Keyboard,- KeyboardAvoidingView,- Pressable,- TouchableWithoutFeedback,- View,-} from "react-native";+import type { TextInputProps } from "react-native";+import { forwardRef, useRef, useState } from "react";+import { ActivityIndicator, Pressable, TextInput, View } from "react-native";+import { KeyboardAwareScrollView } from "react-native-keyboard-controller";import { Redirect, useRouter } from "expo-router";import * as WebBrowser from "expo-web-browser";import Logo from "@/components/Logo";import { TailwindResolver } from "@/components/TailwindResolver";import { Button } from "@/components/ui/Button";-import { Input } from "@/components/ui/Input";+import ChevronRight from "@/components/ui/ChevronRight";+import { GroupedSection, RowSeparator } from "@/components/ui/GroupedList";import { Text } from "@/components/ui/Text";import useAppSettings from "@/lib/settings";+import { cn } from "@/lib/utils";import { useMutation } from "@tanstack/react-query";-import { Bug, Edit3 } from "lucide-react-native";import { useTRPC } from "@karakeep/shared-react/trpc";@@ -24,6 +21,33 @@ enum LoginType {ApiKey,}+const DEFAULT_SERVER_ADDRESS = "https://cloud.karakeep.app";++// The logo artboard is 598x166; derive the width so it never letterboxes.+const LOGO_HEIGHT = 52;+const LOGO_WIDTH = Math.round((LOGO_HEIGHT * 598) / 166);++/**+ * A grouped-list row pairing a leading label with an inline text field.+ */+const LABEL_WIDTH = 104;++const FieldRow = forwardRef<TextInput, { label: string } & TextInputProps>(+ ({ label, ...props }, ref) => (+ <View className="flex-row items-center px-4">+ <Text className="py-3.5" style={{ width: LABEL_WIDTH }}>+ {label}+ </Text>+ <TextInput+ ref={ref}+ className="flex-1 py-3.5 text-[17px] leading-6 text-foreground placeholder:text-muted-foreground/50"+ {...props}+ />+ </View>+ ),+);+FieldRow.displayName = "FieldRow";+export default function Signin() {const { settings, setSettings } = useAppSettings();const router = useRouter();@@ -34,16 +58,7 @@ export default function Signin() {const emailRef = useRef<string>("");const passwordRef = useRef<string>("");const apiKeyRef = useRef<string>("");-- const toggleLoginType = () => {- setLoginType((prev) => {- if (prev === LoginType.Password) {- return LoginType.ApiKey;- } else {- return LoginType.Password;- }- });- };+ const passwordInputRef = useRef<TextInput>(null);const { mutate: login, isPending: userNamePasswordRequestIsPending } =useMutation(@@ -82,8 +97,11 @@ export default function Signin() {return <Redirect href="dashboard" />;}+ const isPending =+ userNamePasswordRequestIsPending || apiKeyValueRequestIsPending;+ const serverAddress = settings.address ?? DEFAULT_SERVER_ADDRESS;+const onSignUp = async () => {- const serverAddress = settings.address ?? "https://cloud.karakeep.app";const signupUrl = `${serverAddress}/signup?redirectUrl=${encodeURIComponent("karakeep://signin")}&skipSessionRedirect=1`;await WebBrowser.openAuthSessionAsync(signupUrl, "karakeep://signin");@@ -120,129 +138,173 @@ export default function Signin() {};return (- <KeyboardAvoidingView behavior="padding">- <TouchableWithoutFeedback onPress={Keyboard.dismiss}>- <View className="flex h-full flex-col justify-center gap-2 px-4">- <View className="items-center">- <TailwindResolver- className="color-foreground"- comp={(styles) => (- <Logo- height={150}- width={250}- fill={styles?.color?.toString()}- />- )}- />- </View>- {error && (- <Text className="w-full text-center text-red-500">{error}</Text>- )}- <View className="gap-2">- <Text className="font-bold">Server Address</Text>- <View className="flex-row items-center gap-2">- <View className="flex-1 rounded-md border border-border bg-card px-3 py-2">- <Text>{settings.address ?? "https://cloud.karakeep.app"}</Text>- </View>- <Button- size="icon"- variant="secondary"- onPress={() => router.push("/server-address")}- >- <TailwindResolver- comp={(styles) => (- <Edit3 size={16} color={styles?.color?.toString()} />- )}- className="color-foreground"- />- </Button>- </View>- </View>- {loginType === LoginType.Password && (- <>- <View className="gap-2">- <Text className="font-bold">Email</Text>- <Input- className="w-full"- inputClasses="bg-card"- placeholder="Email"+ <>+ <KeyboardAwareScrollView+ contentContainerStyle={{+ flexGrow: 1,+ justifyContent: "center",+ gap: 24,+ paddingHorizontal: 20,+ // Slight upward bias so the block doesn't sit dead centre.+ paddingTop: 24,+ paddingBottom: 88,+ }}+ bottomOffset={24}+ keyboardShouldPersistTaps="handled"+ keyboardDismissMode="interactive"+ >+ <View className="items-center pb-6">+ <TailwindResolver+ className="color-foreground"+ comp={(styles) => (+ <Logo+ height={LOGO_HEIGHT}+ width={LOGO_WIDTH}+ fill={styles?.color?.toString()}+ />+ )}+ />+ </View>++ <View className="gap-3">+ <GroupedSection>+ <Pressable+ accessibilityRole="button"+ onPress={() => router.push("/server-address")}+ className="flex-row items-center px-4 active:opacity-70"+ >+ <Text className="py-3.5" style={{ width: LABEL_WIDTH }}>+ Server+ </Text>+ <Text className="flex-1 py-3.5" numberOfLines={1}>+ {serverAddress}+ </Text>+ <ChevronRight size={16} />+ </Pressable>++ {loginType === LoginType.Password ? (+ <>+ <RowSeparator />+ <FieldRow+ label="Email"+ placeholder="[email protected]"keyboardType="email-address"autoCapitalize="none"+ autoCorrect={false}+ autoComplete="email"+ textContentType="emailAddress"+ returnKeyType="next"+ submitBehavior="submit"+ onSubmitEditing={() => passwordInputRef.current?.focus()}defaultValue={""}onChangeText={(text) => (emailRef.current = text)}/>- </View>- <View className="gap-2">- <Text className="font-bold">Password</Text>- <Input- className="w-full"- inputClasses="bg-card"- placeholder="Password"+ <RowSeparator />+ <FieldRow+ ref={passwordInputRef}+ label="Password"+ placeholder="Enter your password"secureTextEntry- defaultValue={""}autoCapitalize="none"+ autoComplete="current-password"textContentType="password"+ returnKeyType="go"+ onSubmitEditing={onSignin}+ defaultValue={""}onChangeText={(text) => (passwordRef.current = text)}/>- </View>- </>- )}+ </>+ ) : (+ <>+ <RowSeparator />+ <FieldRow+ label="API Key"+ placeholder="Paste your key"+ secureTextEntry+ autoCapitalize="none"+ autoCorrect={false}+ textContentType="password"+ returnKeyType="go"+ onSubmitEditing={onSignin}+ defaultValue={""}+ onChangeText={(text) => (apiKeyRef.current = text)}+ />+ </>+ )}+ </GroupedSection>- {loginType === LoginType.ApiKey && (- <View className="gap-2">- <Text className="font-bold">API Key</Text>- <Input- className="w-full"- inputClasses="bg-card"- placeholder="API Key"- secureTextEntry- defaultValue={""}- autoCapitalize="none"- textContentType="password"- onChangeText={(text) => (apiKeyRef.current = text)}- />+ {error && (+ <View+ className="rounded-xl bg-destructive/10 px-4 py-3"+ style={{ borderCurve: "continuous" }}+ >+ <Text className="text-center text-sm text-destructive">+ {error}+ </Text></View>)}- <View className="flex flex-row items-center justify-between gap-2">- <Button- size="lg"- androidRootClassName="flex-1"- onPress={onSignin}- disabled={- userNamePasswordRequestIsPending || apiKeyValueRequestIsPending- }- >- <Text>Sign In</Text>- </Button>- <Button- size="icon"- onPress={() => router.push("/test-connection")}- disabled={!settings.address}- >- <TailwindResolver- comp={(styles) => (- <Bug size={20} color={styles?.color?.toString()} />- )}- className="text-white"- />- </Button>- </View>- <Pressable onPress={toggleLoginType}>- <Text className="mt-2 text-center text-gray-500">+ <Button+ size="lg"+ className="w-full"+ androidRootClassName="w-full"+ onPress={onSignin}+ disabled={isPending}+ >+ {isPending && <ActivityIndicator size="small" color="white" />}+ <Text>{isPending ? "Signing in…" : "Sign In"}</Text>+ </Button>+ </View>++ <View className="items-center gap-3">+ <Pressable+ accessibilityRole="button"+ onPress={() => router.push("/test-connection")}+ disabled={!settings.address}+ hitSlop={8}+ className={cn(+ "active:opacity-60",+ !settings.address && "opacity-40",+ )}+ >+ <Text className="text-sm text-muted-foreground">+ Test connection+ </Text>+ </Pressable>+ <Pressable+ accessibilityRole="button"+ onPress={() => {+ setLoginType(+ loginType === LoginType.Password+ ? LoginType.ApiKey+ : LoginType.Password,+ );+ setError(undefined);+ }}+ hitSlop={8}+ className="active:opacity-60"+ >+ <Text className="text-sm text-muted-foreground">{loginType === LoginType.Password- ? "Use API key instead?"- : "Use password instead?"}+ ? "Use an API key instead"+ : "Use your password instead"}</Text></Pressable>- <Pressable onPress={onSignUp}>- <Text className="mt-4 text-center text-gray-500">- Don't have an account?{" "}- <Text className="text-foreground underline">Sign Up</Text>+ <Pressable+ accessibilityRole="button"+ onPress={onSignUp}+ hitSlop={8}+ className="active:opacity-60"+ >+ <Text className="text-sm text-muted-foreground">+ New to Karakeep?{" "}+ <Text className="text-sm font-medium text-primary">+ Create account+ </Text></Text></Pressable></View>- </TouchableWithoutFeedback>- </KeyboardAvoidingView>+ </KeyboardAwareScrollView>+ </>);}