-
Notifications
You must be signed in to change notification settings - Fork 1
Add Expo kitchen sink example #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
batuhan
wants to merge
1
commit into
main
Choose a base branch
from
feat/examples-kitchen-sink-cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files | ||
|
|
||
| # dependencies | ||
| node_modules/ | ||
| package-lock.json | ||
|
|
||
| # Expo | ||
| .expo/ | ||
| dist/ | ||
| web-build/ | ||
| expo-env.d.ts | ||
|
|
||
| # Native | ||
| .kotlin/ | ||
| *.orig.* | ||
| *.jks | ||
| *.p8 | ||
| *.p12 | ||
| *.key | ||
| *.mobileprovision | ||
|
|
||
| # Metro | ||
| .metro-health-check* | ||
|
|
||
| # debug | ||
| npm-debug.* | ||
| yarn-debug.* | ||
| yarn-error.* | ||
|
|
||
| # macOS | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # local env files | ||
| .env*.local | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
|
|
||
| # generated native folders | ||
| /ios | ||
| /android |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "expo": { | ||
| "name": "EasyMatrix SDK Lab", | ||
| "slug": "easymatrix-sdk-lab", | ||
| "version": "1.0.0", | ||
| "orientation": "portrait", | ||
| "icon": "./assets/icon.png", | ||
| "userInterfaceStyle": "light", | ||
| "splash": { | ||
| "image": "./assets/splash-icon.png", | ||
| "resizeMode": "contain", | ||
| "backgroundColor": "#ffffff" | ||
| }, | ||
| "ios": { | ||
| "supportsTablet": true | ||
| }, | ||
| "android": { | ||
| "adaptiveIcon": { | ||
| "backgroundColor": "#E6F4FE", | ||
| "foregroundImage": "./assets/android-icon-foreground.png", | ||
| "backgroundImage": "./assets/android-icon-background.png", | ||
| "monochromeImage": "./assets/android-icon-monochrome.png" | ||
| }, | ||
| "predictiveBackGestureEnabled": false | ||
| }, | ||
| "scheme": "easymatrix-sdk-lab", | ||
| "experiments": { | ||
| "typedRoutes": true | ||
| }, | ||
| "web": { | ||
| "bundler": "metro", | ||
| "output": "static", | ||
| "favicon": "./assets/favicon.png" | ||
| }, | ||
| "plugins": [ | ||
| "expo-router", | ||
| "expo-secure-store", | ||
| "expo-sqlite" | ||
| ] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { Tabs } from "expo-router"; | ||
|
|
||
| export default function TabsLayout() { | ||
| return ( | ||
| <Tabs | ||
| screenOptions={{ | ||
| headerShown: false, | ||
| tabBarActiveTintColor: "#13212f", | ||
| tabBarInactiveTintColor: "#8c7c6d", | ||
| tabBarStyle: { | ||
| backgroundColor: "#fff8ef", | ||
| borderTopColor: "#ebdcc9", | ||
| }, | ||
| }} | ||
| > | ||
| <Tabs.Screen name="index" options={{ title: "Inbox" }} /> | ||
| <Tabs.Screen name="search" options={{ title: "Search" }} /> | ||
| <Tabs.Screen name="lab" options={{ title: "Lab" }} /> | ||
| <Tabs.Screen name="settings" options={{ title: "Settings" }} /> | ||
| </Tabs> | ||
| ); | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| import { useEffect, useMemo, useState } from "react"; | ||
| import { router } from "expo-router"; | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| import { Pressable, Text, TextInput, View, useWindowDimensions } from "react-native"; | ||
|
|
||
| import { ActiveProfileBanner } from "@/components/active-profile-banner"; | ||
| import { ChatRow } from "@/components/chat-row"; | ||
| import { EmptyState } from "@/components/empty-state"; | ||
| import { ScreenShell } from "@/components/screen-shell"; | ||
| import { SectionCard } from "@/components/section-card"; | ||
| import { ThreadPanel } from "@/components/thread-panel"; | ||
| import { useActiveProfile } from "@/hooks/use-active-profile"; | ||
| import { useRealtimeTransport } from "@/hooks/use-realtime-transport"; | ||
| import { chatsQueryOptions } from "@/lib/query/queries"; | ||
|
|
||
| export default function InboxScreen() { | ||
| const { activeProfile } = useActiveProfile(); | ||
| const transport = useRealtimeTransport(activeProfile, ["*"]); | ||
| const [filter, setFilter] = useState(""); | ||
| const [selectedChatID, setSelectedChatID] = useState<string | null>(null); | ||
| const { width } = useWindowDimensions(); | ||
| const wideLayout = width >= 1080; | ||
|
|
||
| const chatsQuery = useQuery( | ||
| activeProfile | ||
| ? { | ||
| ...chatsQueryOptions(activeProfile, { limit: 80 }), | ||
| enabled: Boolean(activeProfile.baseURL && activeProfile.accessToken), | ||
| refetchInterval: transport.mode === "polling" ? 15_000 : false, | ||
| } | ||
| : { | ||
| queryKey: ["profile", "none", "chats", { limit: 80 }], | ||
| queryFn: async () => [], | ||
| enabled: false, | ||
| }, | ||
| ); | ||
|
|
||
| const filteredChats = useMemo(() => { | ||
| const items = chatsQuery.data ?? []; | ||
| const token = filter.trim().toLowerCase(); | ||
| if (!token) { | ||
| return items; | ||
| } | ||
| return items.filter( | ||
| (item) => | ||
| item.title.toLowerCase().includes(token) || | ||
| item.subtitle.toLowerCase().includes(token) || | ||
| item.accountID.toLowerCase().includes(token), | ||
| ); | ||
| }, [chatsQuery.data, filter]); | ||
|
|
||
| useEffect(() => { | ||
| if (wideLayout && !selectedChatID && filteredChats[0]?.id) { | ||
| setSelectedChatID(filteredChats[0].id); | ||
| } | ||
| }, [filteredChats, selectedChatID, wideLayout]); | ||
|
|
||
| return ( | ||
| <ScreenShell | ||
| eyebrow="SDK Inbox" | ||
| title="Chat list and thread state" | ||
| description="This screen exercises `chats.list`, `messages.list`, and `messages.send` against the active Desktop API target." | ||
| > | ||
| {activeProfile ? <ActiveProfileBanner profile={activeProfile} transportMode={transport.mode} /> : null} | ||
|
|
||
| {!activeProfile ? ( | ||
| <EmptyState title="No profile selected" description="Create a connection profile in Settings before loading chats." /> | ||
| ) : null} | ||
|
|
||
| {activeProfile && !activeProfile.accessToken ? ( | ||
| <EmptyState title="Token missing" description="Save an access token in Settings to start querying chats and messages." /> | ||
| ) : null} | ||
|
|
||
| {activeProfile ? ( | ||
| <SectionCard | ||
| title="Inbox" | ||
| description="The list is cached per profile and invalidated from websocket events or polling." | ||
| > | ||
| <TextInput | ||
| placeholder="Filter loaded chats" | ||
| value={filter} | ||
| onChangeText={setFilter} | ||
| style={{ | ||
| padding: 14, | ||
| borderRadius: 16, | ||
| backgroundColor: "#fff", | ||
| borderWidth: 1, | ||
| borderColor: "#dfd1bc", | ||
| }} | ||
| /> | ||
|
|
||
| {chatsQuery.isPending ? ( | ||
| <EmptyState title="Loading chats" description="Fetching the latest conversation list." /> | ||
| ) : null} | ||
|
|
||
| {chatsQuery.isError ? ( | ||
| <EmptyState | ||
| title="Inbox failed to load" | ||
| description={chatsQuery.error instanceof Error ? chatsQuery.error.message : "Unknown inbox error"} | ||
| /> | ||
| ) : null} | ||
|
|
||
| {!wideLayout && filteredChats.length > 0 ? ( | ||
| <View style={{ gap: 10 }}> | ||
| {filteredChats.map((chat) => ( | ||
| <ChatRow | ||
| key={chat.id} | ||
| chat={chat} | ||
| selected={false} | ||
| onPress={() => router.push({ pathname: "/chat/[chatID]", params: { chatID: chat.id } })} | ||
| /> | ||
| ))} | ||
| </View> | ||
| ) : null} | ||
|
|
||
| {wideLayout ? ( | ||
| <View style={{ flexDirection: "row", gap: 16, alignItems: "stretch" }}> | ||
| <View style={{ flex: 0.95, gap: 10 }}> | ||
| {filteredChats.map((chat) => ( | ||
| <ChatRow | ||
| key={chat.id} | ||
| chat={chat} | ||
| selected={chat.id === selectedChatID} | ||
| onPress={() => setSelectedChatID(chat.id)} | ||
| /> | ||
| ))} | ||
| </View> | ||
| <View style={{ flex: 1.25 }}> | ||
| {selectedChatID ? ( | ||
| <ThreadPanel chatID={selectedChatID} profile={activeProfile} transportMode={transport.mode} /> | ||
| ) : ( | ||
| <EmptyState title="Pick a chat" description="Select one of the loaded chats to render the thread panel." /> | ||
| )} | ||
| </View> | ||
| </View> | ||
| ) : null} | ||
|
|
||
| {!chatsQuery.isPending && filteredChats.length === 0 ? ( | ||
| <EmptyState title="No chats matched" description="Try another filter or verify the current profile against `/v1/info` in Lab or Settings." /> | ||
| ) : null} | ||
| </SectionCard> | ||
| ) : null} | ||
|
|
||
| {wideLayout ? null : ( | ||
| <Pressable | ||
| onPress={() => router.push({ pathname: "/settings" })} | ||
| style={{ | ||
| paddingVertical: 14, | ||
| paddingHorizontal: 18, | ||
| borderRadius: 18, | ||
| backgroundColor: "#efe4d5", | ||
| alignSelf: "flex-start", | ||
| }} | ||
| > | ||
| <Text selectable style={{ color: "#583d28", fontWeight: "700" }}> | ||
| Open Settings | ||
| </Text> | ||
| </Pressable> | ||
| )} | ||
| </ScreenShell> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep
selectedChatIDin sync with the visible list.After a filter change or profile switch,
selectedChatIDcan point at a chat that is no longer infilteredChats, so the wide layout keeps rendering a stale thread. Re-select the first visible chat or clear the selection when the current one drops out.Suggested fix
useEffect(() => { - if (wideLayout && !selectedChatID && filteredChats[0]?.id) { - setSelectedChatID(filteredChats[0].id); + if (!wideLayout) { + return; + } + + const firstVisibleChatID = filteredChats[0]?.id ?? null; + if (!firstVisibleChatID) { + if (selectedChatID !== null) { + setSelectedChatID(null); + } + return; + } + + if (!selectedChatID || !filteredChats.some((chat) => chat.id === selectedChatID)) { + setSelectedChatID(firstVisibleChatID); } }, [filteredChats, selectedChatID, wideLayout]);📝 Committable suggestion
🤖 Prompt for AI Agents