Skip to content

Commit de89937

Browse files
committed
small UI tweaks for bookmarks, simplify button styling
1 parent 38b5840 commit de89937

File tree

5 files changed

+12
-28
lines changed

5 files changed

+12
-28
lines changed

components/BookmarkButton.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,30 @@ import { HoverEffect } from '~/common/styleguide';
44
import { Bookmark, BookmarkFilled } from '~/components/Icons';
55
import Tooltip from '~/components/Tooltip';
66
import { useBookmarks } from '~/context/BookmarksContext';
7+
import tw from '~/util/tailwind';
78

89
type BookmarkButtonProps = {
910
bookmarkId: string;
1011
style?: StyleProp<ViewStyle>;
1112
iconStyle?: StyleProp<ViewStyle>;
12-
filledIconStyle?: StyleProp<ViewStyle>;
1313
};
1414

15-
export default function BookmarkButton({
16-
bookmarkId,
17-
style,
18-
iconStyle,
19-
filledIconStyle,
20-
}: BookmarkButtonProps) {
21-
const { isBookmarked: checkIsBookmarked, toggleBookmark: toggleBookmarkGlobal } = useBookmarks();
15+
export default function BookmarkButton({ bookmarkId, style, iconStyle }: BookmarkButtonProps) {
16+
const { checkIsBookmarked, toggleBookmark } = useBookmarks();
2217
const isBookmarked = checkIsBookmarked(bookmarkId);
2318

2419
function handleToggleBookmark() {
25-
toggleBookmarkGlobal(bookmarkId);
20+
toggleBookmark(bookmarkId);
2621
}
2722

2823
return (
2924
<Tooltip
3025
trigger={
3126
<HoverEffect onPress={handleToggleBookmark} style={style}>
3227
{isBookmarked ? (
33-
<BookmarkFilled style={filledIconStyle ?? iconStyle} />
28+
<BookmarkFilled style={[tw`size-4 text-primary-dark dark:text-primary`, iconStyle]} />
3429
) : (
35-
<Bookmark style={iconStyle} />
30+
<Bookmark style={[tw`size-4 text-palette-gray5 dark:text-palette-gray4`, iconStyle]} />
3631
)}
3732
</HoverEffect>
3833
}>

components/Filters/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { type StyleProp, View, type ViewStyle } from 'react-native';
22

33
import FiltersSection from '~/components/Filters/FiltersSection';
44
import { Tag } from '~/components/Tag';
5-
import { useBookmarks } from '~/context/BookmarksContext';
65
import { type Query } from '~/types';
76
import { getPageQuery } from '~/util/search';
87
import tw from '~/util/tailwind';
@@ -27,8 +26,6 @@ type FiltersProps = {
2726
export function Filters({ query, style, basePath = '/packages' }: FiltersProps) {
2827
const pageQuery = getPageQuery(basePath, query);
2928
const isMainSearch = basePath === '/packages';
30-
const { bookmarkedIds } = useBookmarks();
31-
const hasBookmarks = bookmarkedIds.size > 0;
3229

3330
return (
3431
<View style={[tw`flex-1 items-center bg-palette-gray1 py-2 dark:bg-very-dark`, style]}>
@@ -72,9 +69,7 @@ export function Filters({ query, style, basePath = '/packages' }: FiltersProps)
7269
basePath={basePath}
7370
/>
7471
))}
75-
{hasBookmarks && (
76-
<ToggleLink query={pageQuery} filterParam={FILTER_BOOKMARKS} basePath={basePath} />
77-
)}
72+
<ToggleLink query={pageQuery} filterParam={FILTER_BOOKMARKS} basePath={basePath} />
7873
</FiltersSection>
7974
<View style={tw`w-full max-w-layout flex-row flex-wrap content-start`}>
8075
<FiltersSection title="Compatibility">

components/Library/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ export default function Library({
5656
<BookmarkButton
5757
bookmarkId={bookmarkId}
5858
style={tw`absolute right-2 top-2 z-10 rounded border border-palette-gray2 p-1.5 dark:border-palette-gray6`}
59-
iconStyle={tw`size-4 text-palette-gray4 dark:text-palette-gray5`}
60-
filledIconStyle={tw`size-4 text-primary-dark dark:text-primary`}
6159
/>
6260
<View style={[tw`flex-1 p-4 pb-3.5 pl-5`, isSmallScreen && tw`px-3.5 pb-3 pt-2.5`]}>
6361
{library.unmaintained && (

components/Package/PackageHeader.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ export default function PackageHeader({ library, registryData, rightSlot }: Prop
6060
/>
6161
</A>
6262
</HoverEffect>
63-
<BookmarkButton
64-
bookmarkId={bookmarkId}
65-
style={tw`size-5`}
66-
iconStyle={tw`size-5 text-palette-gray5 dark:text-palette-gray4`}
67-
filledIconStyle={tw`size-5 text-primary-dark dark:text-primary`}
68-
/>
63+
<BookmarkButton bookmarkId={bookmarkId} style={tw`size-5`} iconStyle={tw`size-5`} />
6964
</View>
7065
{rightSlot}
7166
</View>

context/BookmarksContext.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const COOKIE_MAX_AGE = TimeRange.YEAR;
77

88
type BookmarksContextType = {
99
bookmarkedIds: Set<string>;
10-
isBookmarked: (id: string) => boolean;
10+
checkIsBookmarked: (id: string) => boolean;
1111
toggleBookmark: (id: string) => void;
1212
isLoading: boolean;
1313
};
@@ -63,7 +63,7 @@ export function BookmarksProvider({ children }: PropsWithChildren) {
6363
setIsLoading(false);
6464
}, []);
6565

66-
function isBookmarked(id: string) {
66+
function checkIsBookmarked(id: string) {
6767
return bookmarkedIds.has(id);
6868
}
6969

@@ -80,7 +80,8 @@ export function BookmarksProvider({ children }: PropsWithChildren) {
8080
}
8181

8282
return (
83-
<BookmarksContext.Provider value={{ bookmarkedIds, isBookmarked, toggleBookmark, isLoading }}>
83+
<BookmarksContext.Provider
84+
value={{ bookmarkedIds, checkIsBookmarked, toggleBookmark, isLoading }}>
8485
{children}
8586
</BookmarksContext.Provider>
8687
);

0 commit comments

Comments
 (0)