Skip to content

Commit

Permalink
restructure and style
Browse files Browse the repository at this point in the history
  • Loading branch information
nikgraf committed Jun 7, 2024
1 parent daa3f9d commit a31d253
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 83 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ TODO better version where the token is also never exposed to the network so not
- fix input active for iOS
- fix iOS of add item
- show members and invitation link as menu
- split nav into login/register and authed part
- proper login/signup redirect

- use expo-secure-store for the sessionKey
- encrypt MMKV storage on iOS and Android
Expand Down
34 changes: 34 additions & 0 deletions apps/app/src/app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Drawer } from "expo-router/drawer";
import { useWindowDimensions } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { DrawerContent } from "../../components/drawerContent";
import { useIsPermanentLeftDrawer } from "../../hooks/useIsPermanentDrawer";

export default function Layout() {
const isPermanentLeftDrawer = useIsPermanentLeftDrawer();
const { width: fullWidth } = useWindowDimensions();

return (
<GestureHandlerRootView style={{ flex: 1 }}>
<Drawer
drawerContent={DrawerContent}
screenOptions={{
drawerType: isPermanentLeftDrawer ? "permanent" : "front",
drawerStyle: {
width: isPermanentLeftDrawer ? 240 : fullWidth,
},
overlayColor: "transparent",
drawerPosition: "left",
headerShown: isPermanentLeftDrawer ? false : true,
// headerLeft: () => {
// return <PanelLeft />;
// },
headerTitle: () => null,
// drawerStyle: {
// width: 240,
// },
}}
/>
</GestureHandlerRootView>
);
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import * as sodium from "react-native-libsodium";
import { Button } from "~/components/ui/button";
import { Card } from "~/components/ui/card";
import { Text } from "~/components/ui/text";
import { useLocker } from "../../hooks/useLocker";
import { acceptInvitation } from "../../utils/acceptInvitation";
import { getHashParameter } from "../../utils/getHashParam";
import { getSessionKey } from "../../utils/sessionKeyStorage";
import { trpc } from "../../utils/trpc";
import { useLocker } from "../../../hooks/useLocker";
import { acceptInvitation } from "../../../utils/acceptInvitation";
import { getHashParameter } from "../../../utils/getHashParam";
import { getSessionKey } from "../../../utils/sessionKeyStorage";
import { trpc } from "../../../utils/trpc";

const Invitation: React.FC = () => {
const acceptDocumentInvitationMutation =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { Checkbox } from "~/components/ui/checkbox";
import { Input } from "~/components/ui/input";
import { Text } from "~/components/ui/text";
import { X } from "~/lib/icons/X";
import { DocumentInvitation } from "../../components/documentInvitation";
import { SubtleInput } from "../../components/subtleInput";
import { UpdateDocumentNameForm } from "../../components/updateDocumentNameForm";
import { useLocker } from "../../hooks/useLocker";
import { useYArray } from "../../hooks/useYArray";
import { deserialize } from "../../utils/deserialize";
import { DocumentInvitation } from "../../../components/documentInvitation";
import { SubtleInput } from "../../../components/subtleInput";
import { UpdateDocumentNameForm } from "../../../components/updateDocumentNameForm";
import { useLocker } from "../../../hooks/useLocker";
import { useYArray } from "../../../hooks/useYArray";
import { deserialize } from "../../../utils/deserialize";
import {
documentPendingChangesStorage,
documentStorage,
} from "../../utils/documentStorage";
import { serialize } from "../../utils/serialize";
} from "../../../utils/documentStorage";
import { serialize } from "../../../utils/serialize";

const websocketEndpoint =
process.env.NODE_ENV === "development"
Expand Down Expand Up @@ -120,15 +120,17 @@ const List: React.FC<Props> = () => {
/>

<View className="flex flex-row items-center gap-2 px-6">
<Input
placeholder="What needs to be done?"
onChangeText={(value) => setNewTodoText(value)}
value={newTodoText}
autoCapitalize="none"
autoCorrect={false}
autoComplete="off"
numberOfLines={1}
/>
<View className="flex flex-1">
<Input
placeholder="What needs to be done?"
onChangeText={(value) => setNewTodoText(value)}
value={newTodoText}
autoCapitalize="none"
autoCorrect={false}
autoComplete="off"
numberOfLines={1}
/>
</View>
<Button
className="add"
onPress={(event) => {
Expand All @@ -153,7 +155,16 @@ const List: React.FC<Props> = () => {
console.log("checked", index);
}}
/>
<SubtleInput value={entry} />
<View className="flex flex-1">
<SubtleInput
placeholder="What needs to be done?"
value={entry}
numberOfLines={1}
autoCapitalize="none"
autoCorrect={false}
autoComplete="off"
/>
</View>
<Button
variant="ghost"
size="icon"
Expand Down
43 changes: 2 additions & 41 deletions apps/app/src/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ import {
QueryClientProvider,
} from "@tanstack/react-query";
import { httpBatchLink } from "@trpc/client";
import { SplashScreen } from "expo-router";
import { Drawer } from "expo-router/drawer";
import { Slot, SplashScreen } from "expo-router";
import { StatusBar } from "expo-status-bar";
import { useEffect, useState } from "react";
import { useWindowDimensions } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { NAV_THEME } from "~/lib/constants";
import { useColorScheme } from "~/lib/useColorScheme";
import { DrawerContent } from "../components/drawerContent";
import "../global.css";
import { useIsPermanentLeftDrawer } from "../hooks/useIsPermanentDrawer";
import useLoadingLibsodium from "../hooks/useLoadingLibsodium";
import { trpc } from "../utils/trpc";

Expand Down Expand Up @@ -103,11 +98,6 @@ export default function Layout() {
})
);

const isPermanentLeftDrawer = useIsPermanentLeftDrawer();
const { width: fullWidth } = useWindowDimensions();

console.log(isPermanentLeftDrawer);

if (!isLoadingComplete) {
return null;
}
Expand All @@ -118,37 +108,8 @@ export default function Layout() {
<SafeAreaProvider>
<ThemeProvider value={isDarkColorScheme ? DARK_THEME : LIGHT_THEME}>
<StatusBar style={isDarkColorScheme ? "light" : "dark"} />
{/* <Stack>
<Stack.Screen
name="index"
options={{
// Hide the header for all other routes.
title: "Lists",
}}
/>
</Stack> */}

<GestureHandlerRootView style={{ flex: 1 }}>
<Drawer
drawerContent={DrawerContent}
screenOptions={{
drawerType: isPermanentLeftDrawer ? "permanent" : "front",
drawerStyle: {
width: isPermanentLeftDrawer ? 240 : fullWidth,
},
overlayColor: "transparent",
drawerPosition: "left",
headerShown: isPermanentLeftDrawer ? false : true,
// headerLeft: () => {
// return <PanelLeft />;
// },
headerTitle: () => null,
// drawerStyle: {
// width: 240,
// },
}}
/>
</GestureHandlerRootView>
<Slot />

{/* Default Portal Host (one per app) */}
{/* <PortalHost /> */}
Expand Down
12 changes: 9 additions & 3 deletions apps/app/src/app/login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { router, useLocalSearchParams } from "expo-router";
import { Link, router, useLocalSearchParams } from "expo-router";
import { useState } from "react";
import { View } from "react-native";
import { Text } from "~/components/ui/text";
Expand All @@ -16,7 +16,7 @@ const Login = () => {
const { addItem } = useLocker();

return (
<View className="max-w-md mr-auto ml-auto">
<View className="max-w-md mr-auto ml-auto min-w-80 mt-32">
<AuthForm
onSubmit={async ({ password, username }) => {
const loginResult = await login({
Expand All @@ -41,7 +41,7 @@ const Login = () => {
}
router.navigate("/");
}}
children={<Text>Login</Text>}
children="Login"
isPending={isPending}
/>

Expand All @@ -53,6 +53,12 @@ const Login = () => {
<Text>Failed to log in</Text>
</View>
)}

<View className="mt-8 text-center">
<Link href="/register" className="text-center">
Sign up here
</Link>
</View>
</View>
);
};
Expand Down
14 changes: 10 additions & 4 deletions apps/app/src/app/register.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { router, useLocalSearchParams } from "expo-router";
import { Link, router, useLocalSearchParams } from "expo-router";
import { useState } from "react";
import { View } from "react-native";
import { Text } from "~/components/ui/text";
Expand All @@ -16,7 +16,7 @@ const Register = () => {
const { addItem } = useLocker();

return (
<View className="max-w-md mr-auto ml-auto">
<View className="max-w-md mr-auto ml-auto min-w-80 mt-32">
<AuthForm
onSubmit={async ({ password, username }) => {
const result = await registerAndLogin({
Expand All @@ -41,17 +41,23 @@ const Register = () => {
}
router.navigate("/");
}}
children={<Text>Register</Text>}
children="Sign up"
isPending={isPending}
/>
{error && (
<View className="mt-4">
<AlertCircle className="h-4 w-4" />
{/* TODO proper styling */}
<Text>Error</Text>
<Text>Failed to register</Text>
<Text>Failed to sign up</Text>
</View>
)}

<View className="mt-8 text-center">
<Link href="/login" className="text-center">
Login here
</Link>
</View>
</View>
);
};
Expand Down
4 changes: 2 additions & 2 deletions apps/app/src/components/authForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const AuthForm = ({ onSubmit, isPending, children }: Props) => {

return (
<View>
<Text className="text-xl text-center font-semibold mb-8 mt-12">
<Text className="text-3xl text-center font-semibold mb-8 mt-12">
{children}
</Text>

Expand Down Expand Up @@ -53,7 +53,7 @@ export const AuthForm = ({ onSubmit, isPending, children }: Props) => {
onSubmit({ username, password });
}}
>
{children}
<Text>{children}</Text>
</Button>
</View>
</View>
Expand Down
3 changes: 1 addition & 2 deletions apps/app/src/components/documentInvitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const DocumentInvitation: React.FC<Props> = ({
}

return (
<View className="flex gap-2 pt-2 px-6">
<View className="flex flex-col gap-2 pt-2 px-6">
{documentInvitationQuery.data ? (
<Text>
You have one invitation link ({documentInvitationQuery.data.token})
Expand All @@ -77,7 +77,6 @@ export const DocumentInvitation: React.FC<Props> = ({
id={id}
value={`${window.location.origin}/list-invitation/${documentInvitationQuery.data?.token}#key=${seed}`}
readOnly
className="w-72 h-40"
multiline
/>
)}
Expand Down
9 changes: 2 additions & 7 deletions apps/app/src/components/drawerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ export const DrawerContent: React.FC = () => {
}}
>
<View className="gap-4">
<Link href="/login">
<Text>Login</Text>
</Link>
<Link href="/register">Register</Link>

<View className="flex flex-row px-4 items-center gap-2">
<View className="flex flex-row px-4 items-center gap-2 pt-4">
<View className="bg-slate-200 w-10 h-10 rounded-full items-center justify-center">
<Text>{meQuery.data?.username.substring(0, 2)}</Text>
</View>
Expand Down Expand Up @@ -93,7 +88,7 @@ export const DrawerContent: React.FC = () => {
<ListTodo width={16} height={16} />
</Text>
<Text className="text-xl" numberOfLines={1}>
{name}
{name || "Untitled"}
</Text>
</Link>
);
Expand Down

0 comments on commit a31d253

Please sign in to comment.