1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-31 16:39:37 +02:00

fix bookmarks display

fix apps search
search in urls in addition to names
This commit is contained in:
François Darveau 2021-12-10 12:28:03 -05:00
parent e7cd4d7705
commit 423670adb5
3 changed files with 24 additions and 14 deletions

View file

@ -26,15 +26,19 @@ export const AppGrid = (props: Props): JSX.Element => {
config: { config }
} = useSelector((state: State) => state);
const shouldBeShown = (category: Category) => {
return !config.hideEmptyCategories || category.apps.length > 0 || !fromHomepage
}
let apps: JSX.Element;
if (categories.length) {
if (categories.length && categories.some(shouldBeShown)) {
if (searching && !categories[0].apps.length) {
apps = <Message>No apps match your search criteria</Message>;
} else {
apps = (
<div className={classes.AppGrid}>
{categories.filter((category : Category) => !config.hideEmptyCategories || category.apps.length > 0).map(
{categories.filter(shouldBeShown).map(
(category: Category): JSX.Element => (
<AppCard
category={category}
@ -47,7 +51,7 @@ export const AppGrid = (props: Props): JSX.Element => {
);
}
} else {
if (totalCategories) {
if (totalCategories && !config.hideEmptyCategories) {
apps = (
<Message>
There are no pinned categories. You can pin them from the{' '}

View file

@ -26,15 +26,19 @@ export const BookmarkGrid = (props: Props): JSX.Element => {
config: { config }
} = useSelector((state: State) => state);
const shouldBeShown = (category: Category) => {
return !config.hideEmptyCategories || category.bookmarks.length > 0 || !fromHomepage
}
let bookmarks: JSX.Element;
if (categories.length) {
if (categories.length && categories.some(shouldBeShown)) {
if (searching && !categories[0].bookmarks.length) {
bookmarks = <Message>No bookmarks match your search criteria</Message>;
} else {
bookmarks = (
<div className={classes.BookmarkGrid}>
{categories.filter((category : Category) => !config.hideEmptyCategories || category.apps.length > 0).map(
{categories.filter(shouldBeShown).map(
(category: Category): JSX.Element => (
<BookmarkCard
category={category}
@ -47,7 +51,7 @@ export const BookmarkGrid = (props: Props): JSX.Element => {
);
}
} else {
if (totalCategories) {
if (totalCategories && !config.hideEmptyCategories) {
bookmarks = (
<Message>
There are no pinned categories. You can pin them from the{' '}

View file

@ -36,7 +36,7 @@ export const Home = (): JSX.Element => {
null | Category[]
>(null);
// Load apps
// Load apps and bookmarks
useEffect(() => {
if (!appCategories.length && !bookmarkCategories.length) {
getCategories();
@ -59,11 +59,12 @@ export const Home = (): JSX.Element => {
appCategory.apps = appCategories
.map(({ apps }) => apps)
.flat()
.filter(({ name }) =>
new RegExp(escapeRegex(localSearch), 'i').test(name)
.filter(({ name, url }) =>
new RegExp(escapeRegex(localSearch), 'i').test(name) ||
new RegExp(escapeRegex(localSearch), 'i').test(url)
);
setBookmarkSearchResult([appCategory]);
setAppSearchResult([appCategory]);
// Search through bookmarks
const bookmarkCategory = { ...bookmarkCategories[0] };
@ -72,8 +73,9 @@ export const Home = (): JSX.Element => {
bookmarkCategory.bookmarks = bookmarkCategories
.map(({ bookmarks }) => bookmarks)
.flat()
.filter(({ name }) =>
new RegExp(escapeRegex(localSearch), 'i').test(name)
.filter(({ name, url }) =>
new RegExp(escapeRegex(localSearch), 'i').test(name) ||
new RegExp(escapeRegex(localSearch), 'i').test(url)
);
setBookmarkSearchResult([bookmarkCategory]);
@ -122,6 +124,7 @@ export const Home = (): JSX.Element => {
}
totalCategories={appCategories.length}
searching={!!localSearch}
fromHomepage={true}
/>
)}
<div className={classes.HomeSpace}></div>
@ -130,8 +133,7 @@ export const Home = (): JSX.Element => {
<></>
)}
{!config.hideBookmarks &&
(isAuthenticated || bookmarkCategories.some((c) => c.isPinned)) ? (
{!config.hideBookmarks && (isAuthenticated || bookmarkCategories.some((c) => c.isPinned)) ? (
<Fragment>
<SectionHeadline title="Bookmarks" link="/bookmarks" />
{bookmarksLoading ? (