-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,41 +1,90 @@ | ||
import { cn } from "@follow/utils" | ||
import { SafeAreaView, ScrollView, TouchableOpacity, useWindowDimensions } from "react-native" | ||
import { | ||
Image, | ||
SafeAreaView, | ||
ScrollView, | ||
TouchableOpacity, | ||
useWindowDimensions, | ||
View, | ||
} from "react-native" | ||
|
||
import { FallbackIcon } from "@/src/components/ui/icon/fallback-icon" | ||
import type { ViewDefinition } from "@/src/constants/views" | ||
import { views } from "@/src/constants/views" | ||
import { useList } from "@/src/store/list/hooks" | ||
import { useAllListSubscription } from "@/src/store/subscription/hooks" | ||
|
||
import { setCurrentView, useCurrentView } from "../subscription/atoms" | ||
import { selectCollection, useSelectedCollection } from "./atoms" | ||
|
||
export const CollectionPanel = () => { | ||
const winDim = useWindowDimensions() | ||
const lists = useAllListSubscription() | ||
|
||
return ( | ||
<SafeAreaView | ||
className="bg-secondary-system-background" | ||
style={{ width: Math.max(50, winDim.width * 0.15) }} | ||
> | ||
<ScrollView contentContainerClassName="flex py-3 gap-3"> | ||
{views.map((view) => ( | ||
<CollectionButton key={view.name} view={view} /> | ||
{views.map((viewDef) => ( | ||
<ViewButton key={viewDef.name} viewDef={viewDef} /> | ||
))} | ||
{lists.map((listId) => ( | ||
<ListButton key={listId} listId={listId} /> | ||
))} | ||
</ScrollView> | ||
</SafeAreaView> | ||
) | ||
} | ||
|
||
const CollectionButton = ({ view }: { view: ViewDefinition }) => { | ||
const selectedView = useCurrentView() | ||
const isActive = selectedView === view.view | ||
const ViewButton = ({ viewDef }: { viewDef: ViewDefinition }) => { | ||
const selectedCollection = useSelectedCollection() | ||
const isActive = selectedCollection.type === "view" && selectedCollection.viewId === viewDef.view | ||
|
||
return ( | ||
<TouchableOpacity | ||
className={cn( | ||
"mx-3 flex aspect-square items-center justify-center rounded-lg p-3", | ||
isActive ? "bg-system-fill" : "bg-system-background", | ||
)} | ||
onPress={() => | ||
selectCollection({ | ||
type: "view", | ||
viewId: viewDef.view, | ||
}) | ||
} | ||
> | ||
<viewDef.icon key={viewDef.name} color={viewDef.activeColor} /> | ||
</TouchableOpacity> | ||
) | ||
} | ||
|
||
const ListButton = ({ listId }: { listId: string }) => { | ||
const list = useList(listId) | ||
const selectedCollection = useSelectedCollection() | ||
const isActive = selectedCollection.type === "list" && selectedCollection.listId === listId | ||
if (!list) return null | ||
|
||
return ( | ||
<TouchableOpacity | ||
className={cn( | ||
"mx-3 flex aspect-square items-center justify-center rounded-lg p-3", | ||
isActive ? "bg-system-fill" : "bg-system-background", | ||
)} | ||
onPress={() => setCurrentView(view.view)} | ||
onPress={() => | ||
selectCollection({ | ||
type: "list", | ||
listId, | ||
}) | ||
} | ||
> | ||
<view.icon key={view.name} color={view.activeColor} /> | ||
<View className="overflow-hidden rounded"> | ||
{list.image ? ( | ||
<Image source={{ uri: list.image, width: 24, height: 24 }} resizeMode="cover" /> | ||
) : ( | ||
<FallbackIcon title={list.title} size={24} /> | ||
)} | ||
</View> | ||
</TouchableOpacity> | ||
) | ||
} |
This file contains 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
This file contains 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