Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into remove-normalised-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Apr 29, 2024
2 parents 008fa0c + 9126332 commit 8aaa8c2
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 151 deletions.
110 changes: 110 additions & 0 deletions apps/mobile/src/components/header/DynamicHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { DrawerNavigationHelpers } from '@react-navigation/drawer/lib/typescript/src/types';
import { RouteProp, useNavigation } from '@react-navigation/native';
import { NativeStackHeaderProps } from '@react-navigation/native-stack';
import { ArrowLeft, DotsThreeOutline, MagnifyingGlass } from 'phosphor-react-native';
import { Platform, Pressable, Text, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { tw, twStyle } from '~/lib/tailwind';
import { getExplorerStore, useExplorerStore } from '~/stores/explorerStore';
import { Icon } from '../icons/Icon';


type Props = {
headerRoute?: NativeStackHeaderProps; //supporting title from the options object of navigation
optionsRoute?: RouteProp<any, any>; //supporting params passed
kind: 'tag' | 'location'; //the kind of icon to display
explorerMenu?: boolean; //whether to show the explorer menu
};

export default function DynamicHeader({
headerRoute,
optionsRoute,
kind,
explorerMenu = true
}: Props) {
const navigation = useNavigation<DrawerNavigationHelpers>();
const headerHeight = useSafeAreaInsets().top;
const isAndroid = Platform.OS === 'android';
const explorerStore = useExplorerStore();

return (
<View
style={twStyle('relative h-auto w-full border-b border-app-cardborder bg-app-header', {
paddingTop: headerHeight + (isAndroid ? 15 : 0)
})}
>
<View style={tw`mx-auto h-auto w-full justify-center px-5 pb-3`}>
<View style={tw`w-full flex-row items-center justify-between`}>
<View style={tw`flex-row items-center gap-3`}>
<Pressable
hitSlop={24}
onPress={() => navigation.goBack()}
>
<ArrowLeft size={23} color={tw.color('ink')} />
</Pressable>
<View style={tw`flex-row items-center gap-1.5`}>
<HeaderIconKind routeParams={optionsRoute?.params} kind={kind} />
<Text
numberOfLines={1}
style={tw`max-w-[200px] text-xl font-bold text-white`}
>
{headerRoute?.options.title}
</Text>
</View>
</View>
<View style={tw`flex-row gap-3`}>
{explorerMenu && <Pressable
hitSlop={12}
onPress={() => {
getExplorerStore().toggleMenu = !explorerStore.toggleMenu;
}}
>
<DotsThreeOutline
size={24}
color={tw.color(
explorerStore.toggleMenu ? 'text-accent' : 'text-zinc-300'
)}
/>
</Pressable>}
<Pressable
hitSlop={12}
onPress={() => {
navigation.navigate('SearchStack', {
screen: 'Search'
});
}}
>
<MagnifyingGlass
size={24}
weight="bold"
color={tw.color('text-zinc-300')}
/>
</Pressable>
</View>
</View>
</View>
</View>
);
}

interface HeaderIconKindProps {
routeParams?: any;
kind: Props['kind'];
}

const HeaderIconKind = ({routeParams, kind }: HeaderIconKindProps) => {
switch (kind) {
case 'location':
return <Icon size={30} name="Folder" />;
case 'tag':
return (
<View
style={twStyle('h-[24px] w-[24px] rounded-full', {
backgroundColor: routeParams.color
})}
/>
);
default:
return null;
}
};
146 changes: 25 additions & 121 deletions apps/mobile/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,25 @@
import { DrawerNavigationHelpers } from '@react-navigation/drawer/lib/typescript/src/types';
import { useNavigation } from '@react-navigation/native';
import { NativeStackHeaderProps } from '@react-navigation/native-stack';
import { ArrowLeft, DotsThreeOutline, List, MagnifyingGlass } from 'phosphor-react-native';
import { RouteProp, useNavigation } from '@react-navigation/native';
import { ArrowLeft, List, MagnifyingGlass } from 'phosphor-react-native';
import { Platform, Pressable, Text, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { tw, twStyle } from '~/lib/tailwind';
import { getExplorerStore, useExplorerStore } from '~/stores/explorerStore';

import { Icon } from '../icons/Icon';
import Search from '../search/Search';

type HeaderProps = {
title?: string; //title of the page
showSearch?: boolean; //show the search button
showDrawer?: boolean; //show the drawer button
searchType?: 'explorer' | 'location' | 'categories' | 'tags'; //Temporary
navBack?: boolean; //navigate back to the previous screen
headerKind?: 'default' | 'location' | 'tag'; //kind of header
route?: never;
routeTitle?: never;
type Props = {
route?: RouteProp<any, any>; // supporting title from the options object of navigation
navBack?: boolean; // whether to show the back icon
search?: boolean; // whether to show the search icon
title?: string; // in some cases - we want to override the route title
};

//you can pass in a routeTitle only if route is passed in
type Props =
| HeaderProps
| ({
route: NativeStackHeaderProps;
routeTitle?: boolean;
} & Omit<HeaderProps, 'route' | 'routeTitle'>);

// Default header with search bar and button to open drawer
export default function Header({
title,
searchType,
navBack,
route,
routeTitle,
headerKind = 'default',
showDrawer = false,
showSearch = false,
navBack,
title,
search = false
}: Props) {
const navigation = useNavigation<DrawerNavigationHelpers>();
const explorerStore = useExplorerStore();
const routeParams = route?.route.params as any;
const headerHeight = useSafeAreaInsets().top;
const isAndroid = Platform.OS === 'android';

Expand All @@ -55,35 +32,22 @@ export default function Header({
<View style={tw`mx-auto h-auto w-full justify-center px-5 pb-3`}>
<View style={tw`w-full flex-row items-center justify-between`}>
<View style={tw`flex-row items-center gap-3`}>
{navBack && (
{navBack ? (
<Pressable
hitSlop={24}
onPress={() => {
navigation.goBack();
}}
>
<ArrowLeft size={23} color={tw.color('ink')} />
</Pressable>
)}
<View style={tw`flex-row items-center gap-2`}>
<HeaderIconKind headerKind={headerKind} routeParams={routeParams} />
{showDrawer && (
<Pressable onPress={() => navigation.openDrawer()}>
<List size={24} color={tw.color('text-zinc-300')} />
</Pressable>
)}
<Text
numberOfLines={1}
style={tw`max-w-[200px] text-xl font-bold text-white`}
>
{title || (routeTitle && route?.options.title)}
</Text>
</View>
hitSlop={24}
onPress={() => navigation.goBack()}
>
<ArrowLeft size={24} color={tw.color('ink')} />
</Pressable>

) : (
<Pressable onPress={() => navigation.openDrawer()}>
<List size={24} color={tw.color('ink')} />
</Pressable>
)}
<Text style={tw`text-xl font-bold text-ink`}>{title || route?.name}</Text>
</View>
<View style={tw`relative flex-row items-center gap-3`}>
{showSearch && (
<View style={tw`flex-row items-center gap-2`}>
<Pressable
{search && <Pressable
hitSlop={24}
onPress={() => {
navigation.navigate('SearchStack', {
Expand All @@ -96,69 +60,9 @@ export default function Header({
weight="bold"
color={tw.color('text-zinc-300')}
/>
</Pressable>
</View>
)}
{(headerKind === 'location' || headerKind === 'tag') && (
<Pressable
hitSlop={24}
onPress={() => {
getExplorerStore().toggleMenu = !explorerStore.toggleMenu;
}}
>
<DotsThreeOutline
size={24}
color={tw.color(
explorerStore.toggleMenu ? 'text-accent' : 'text-zinc-300'
)}
/>
</Pressable>
)}
</View>
</Pressable>}
</View>
{searchType && <HeaderSearchType searchType={searchType} />}
</View>
</View>
);
}

interface HeaderSearchTypeProps {
searchType: HeaderProps['searchType'];
}

const HeaderSearchType = ({ searchType }: HeaderSearchTypeProps) => {
switch (searchType) {
case 'explorer':
return 'Explorer'; //TODO
case 'location':
return <Search placeholder="Location name..." />;
case 'tags':
return <Search placeholder="Tag name..." />;
case 'categories':
return <Search placeholder="Category name..." />;
default:
return null;
}
};

interface HeaderIconKindProps {
headerKind: HeaderProps['headerKind'];
routeParams?: any;
}

const HeaderIconKind = ({ headerKind, routeParams }: HeaderIconKindProps) => {
switch (headerKind) {
case 'location':
return <Icon size={30} name="Folder" />;
case 'tag':
return (
<View
style={twStyle('h-[24px] w-[24px] rounded-full', {
backgroundColor: routeParams.color
})}
/>
);
default:
return null;
}
};
53 changes: 53 additions & 0 deletions apps/mobile/src/components/header/SearchHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { DrawerNavigationHelpers } from '@react-navigation/drawer/lib/typescript/src/types';
import { RouteProp, useNavigation } from '@react-navigation/native';
import { ArrowLeft } from 'phosphor-react-native';
import { Platform, Pressable, Text, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { tw, twStyle } from '~/lib/tailwind';
import Search from '../search/Search';


const searchPlaceholder = {
locations: 'Search location name...',
tags: 'Search tag name...',
categories: 'Search category name...',
}

type Props = {
route?: RouteProp<any, any>; // supporting title from the options object of navigation
kind: keyof typeof searchPlaceholder; // the kind of search we are doing
title?: string; // in some cases - we want to override the route title
};

export default function SearchHeader({
route,
kind,
title
}: Props) {
const navigation = useNavigation<DrawerNavigationHelpers>();
const headerHeight = useSafeAreaInsets().top;
const isAndroid = Platform.OS === 'android';

return (
<View
style={twStyle('relative h-auto w-full border-b border-app-cardborder bg-app-header', {
paddingTop: headerHeight + (isAndroid ? 15 : 0)
})}
>
<View style={tw`mx-auto h-auto w-full justify-center px-5 pb-3`}>
<View style={tw`w-full flex-row items-center justify-between`}>
<View style={tw`flex-row items-center gap-3`}>
<Pressable
hitSlop={24}
onPress={() => navigation.goBack()}
>
<ArrowLeft size={24} color={tw.color('ink')} />
</Pressable>
<Text style={tw`text-xl font-bold text-ink`}>{title || route?.name}</Text>
</View>
</View>
<Search placeholder={searchPlaceholder[kind]} />
</View>
</View>
);
}
2 changes: 1 addition & 1 deletion apps/mobile/src/navigation/SearchStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function SearchStack() {
component={FiltersScreen}
options={{
header: () => {
return <Header navBack showSearch={false} title="Search filters" />;
return <Header navBack title="Search filters" />;
}
}}
/>
Expand Down
Loading

0 comments on commit 8aaa8c2

Please sign in to comment.