Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 106 additions & 24 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Stack, useGlobalSearchParams, useRouter } from "expo-router";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { Ionicons } from "@expo/vector-icons";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { useUniwind } from "uniwind";

import { KeyProvider } from "@/src/providers/keyProvider";
import { DbProvider } from "@/src/providers/dbProvider";
Expand All @@ -19,6 +20,11 @@ import { ModalProvider, useSearchModal } from "@/src/providers/modalProvider";
import { NotificationProvider } from "@/src/providers/notificationProvider";
import { NetworkProvider } from "@/src/providers/networkProvider";
import OfflineBanner from "@/src/components/OfflineBanner";
import CourseFrame from "@/src/components/CourseFrame";
import {
CourseLayoutProvider,
useCourseLayout,
} from "@/src/providers/courseLayoutProvider";
import "@/global.css";

function HeaderLeft() {
Expand Down Expand Up @@ -46,6 +52,7 @@ function HeaderRight() {
const router = useRouter();
const { courseid } = useGlobalSearchParams();
const { openSearch } = useSearchModal();
const { isWide, openSidebarSearch } = useCourseLayout();

const normalizedCourseId =
courseid && (!Array.isArray(courseid) || courseid.length > 0)
Expand All @@ -57,22 +64,110 @@ function HeaderRight() {
<>
{isInCourse && (
<Pressable
onPress={() => openSearch(normalizedCourseId)}
accessibilityRole="button"
accessibilityLabel="Search threads"
onPress={() =>
isWide ? openSidebarSearch() : openSearch(normalizedCourseId)
}
style={{ marginRight: 16 }}
>
<Ionicons name="search" size={24} color="white" />
</Pressable>
)}
<Pressable onPress={() => router.navigate("/settings")}>
<Pressable
accessibilityRole="button"
accessibilityLabel="Settings"
onPress={() => router.navigate("/settings")}
>
<Ionicons name="person" size={24} color="white" />
</Pressable>
</>
);
}

export default function RootLayout() {
function WideCourseHeader() {
const { courseId, hasThread } = useCourseLayout();
const insets = useSafeAreaInsets();
const router = useRouter();
const course = getCachedCourses()?.find((item) => item.id === courseId);

return (
<View
style={{
backgroundColor: "#70069e",
paddingTop: insets.top,
paddingLeft: insets.left,
paddingRight: insets.right,
}}
>
<View
style={{
height: 56,
flexDirection: "row",
alignItems: "center",
paddingHorizontal: 16,
}}
>
<Pressable
accessibilityRole="button"
accessibilityLabel={hasThread ? "Back to course" : "Back"}
hitSlop={8}
style={{ padding: 8, marginRight: 16 }}
onPress={() => {
if (hasThread && courseId !== null)
router.dismissTo(`/courses/${courseId}`);
else if (router.canGoBack()) router.back();
else router.replace("/");
}}
>
<Ionicons name="arrow-back" size={24} color="white" />
</Pressable>
<Text
className="font-display-medium flex-1 text-white"
numberOfLines={1}
style={{ marginRight: 16 }}
>
{course?.name ?? "Course threads"}
</Text>
<HeaderRight />
</View>
</View>
);
}

function AppNavigator() {
const insets = useSafeAreaInsets();
const { isWide } = useCourseLayout();
const { theme } = useUniwind();

return (
<CourseFrame header={<WideCourseHeader />}>
<Stack
screenOptions={({ route }) => {
const isWideCourse = isWide && route.name.startsWith("courses/");
return {
headerShown: !isWideCourse,
animation: isWideCourse ? "none" : "default",
headerStyle: { backgroundColor: "#70069e" },
headerTintColor: "white",
headerTitle: "",
headerBackVisible: true,
headerLeft: () => <HeaderLeft />,
headerRight: () => <HeaderRight />,
contentStyle: {
...(route.name.startsWith("courses/") && {
backgroundColor: theme === "dark" ? "#000000" : "#ffffff",
}),
paddingBottom: Platform.OS === "android" ? insets.bottom : 0,
},
};
}}
/>
</CourseFrame>
);
}

export default function RootLayout() {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<Suspense fallback={<ActivityIndicator size="large" />}>
Expand All @@ -81,27 +176,14 @@ export default function RootLayout() {
<NotificationProvider>
<NetworkProvider>
<HighlighterProvider>
<ModalProvider>
<View style={{ flex: 1 }}>
<OfflineBanner />
<Stack
screenOptions={{
headerStyle: {
backgroundColor: "#70069e",
},
headerTintColor: "white",
headerTitle: "",
headerBackVisible: true,
headerLeft: () => <HeaderLeft />,
headerRight: () => <HeaderRight />,
contentStyle: {
paddingBottom:
Platform.OS === "android" ? insets.bottom : 0,
},
}}
/>
</View>
</ModalProvider>
<CourseLayoutProvider>
<ModalProvider>
<View style={{ flex: 1 }}>
<OfflineBanner />
<AppNavigator />
</View>
</ModalProvider>
</CourseLayoutProvider>
</HighlighterProvider>
</NetworkProvider>
</NotificationProvider>
Expand Down
17 changes: 14 additions & 3 deletions app/courses/[courseid]/[thread]/[commentid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useLocalSearchParams } from "expo-router";
import { useDb } from "@/src/providers/dbProvider";
import { useThreadDetail } from "@/src/hooks/useThreadDetail";
import { useThreadVotes } from "@/src/hooks/useThreadVotes";
import { useCourseLayout } from "@/src/providers/courseLayoutProvider";
import ThreadFullscreenButton from "@/src/components/ThreadFullscreenButton";
import {
renderComment,
findCommentById,
Expand All @@ -11,6 +13,7 @@ import {
import "@/global.css";

export default function CommentThreadPage() {
const { isWide } = useCourseLayout();
const { courseid, thread, commentid } = useLocalSearchParams();
const courseIdNum = Number(Array.isArray(courseid) ? courseid[0] : courseid);
const threadNumber = Number(Array.isArray(thread) ? thread[0] : thread);
Expand All @@ -32,15 +35,15 @@ export default function CommentThreadPage() {

if (loading && !t) {
return (
<View className="flex h-full items-center justify-center">
<View className="flex h-full items-center justify-center bg-white dark:bg-black">
<ActivityIndicator size="large" color="#70069e" />
</View>
);
}

if (!t) {
return (
<View className="flex h-full items-center justify-center">
<View className="flex h-full items-center justify-center bg-white dark:bg-black">
<Text className="font-display text-gray-500">
Thread not found, You may be offline
</Text>
Expand All @@ -53,7 +56,7 @@ export default function CommentThreadPage() {

if (!targetComment) {
return (
<View className="flex h-full items-center justify-center">
<View className="flex h-full items-center justify-center bg-white dark:bg-black">
<Text className="font-display text-gray-500">Comment not found</Text>
</View>
);
Expand All @@ -62,6 +65,14 @@ export default function CommentThreadPage() {
return (
<ScrollView className="flex h-full bg-white dark:bg-black">
<View className="p-4">
{isWide && (
<View className="mb-3 flex-row items-start justify-between">
<Text className="font-display-bold mr-2 flex-1 text-xl dark:text-slate-100">
{t.title}
</Text>
<ThreadFullscreenButton />
</View>
)}
{renderComment(
targetComment,
usersMap,
Expand Down
18 changes: 14 additions & 4 deletions app/courses/[courseid]/[thread]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { settings } from "@/src/lib/storage";
import { useDb } from "@/src/providers/dbProvider";
import { useThreadDetail } from "@/src/hooks/useThreadDetail";
import { useThreadVotes } from "@/src/hooks/useThreadVotes";
import { useCourseLayout } from "@/src/providers/courseLayoutProvider";
import ThreadFullscreenButton from "@/src/components/ThreadFullscreenButton";
import {
AnimatedToggleIcon,
renderComment,
Expand All @@ -31,6 +33,7 @@ import {
import "@/global.css";

export default function ThreadPage() {
const { isWide } = useCourseLayout();
const { courseid, thread } = useLocalSearchParams();
const courseIdNum = Number(Array.isArray(courseid) ? courseid[0] : courseid);
const threadNumber = Number(Array.isArray(thread) ? thread[0] : thread);
Expand All @@ -57,15 +60,15 @@ export default function ThreadPage() {

if (loading && !t) {
return (
<View className="flex h-full items-center justify-center">
<View className="flex h-full items-center justify-center bg-white dark:bg-black">
<ActivityIndicator size="large" color="#70069e" />
</View>
);
}

if (!t) {
return (
<View className="flex h-full items-center justify-center">
<View className="flex h-full items-center justify-center bg-white dark:bg-black">
<Text className="font-display text-gray-500">
{isHidden
? "This thread has been deleted or made private."
Expand All @@ -91,9 +94,13 @@ export default function ThreadPage() {
{t.title}
</Text>
{t.is_pinned && <PushPinIcon size={18} color="#70069e" />}
<ThreadFullscreenButton />
</View>

<View className="mb-3 flex-row items-center gap-x-2">
<View
className="mb-3 flex-row items-center gap-x-2"
style={isWide ? { flexWrap: "wrap", rowGap: 8 } : undefined}
>
{!t.is_anonymous && author?.avatar ? (
<Image
source={{
Expand All @@ -112,7 +119,10 @@ export default function ThreadPage() {
<Text className="font-display-semibold dark:text-slate-100">
{t.is_anonymous ? "Anonymous" : (author?.name ?? "Unknown")}
</Text>
<View className="flex flex-row items-center gap-x-4">
<View
className="flex flex-row items-center gap-x-4"
style={isWide ? { flexWrap: "wrap" } : undefined}
>
<Text className="font-display dark:text-slate-100">
{t.updated_at
? `Updated: ${new Date(t.updated_at).toLocaleDateString()}`
Expand Down
Loading
Loading