diff --git a/src/app/CommandK.tsx b/src/app/CommandK.tsx
index a32066b0..36e12f14 100644
--- a/src/app/CommandK.tsx
+++ b/src/app/CommandK.tsx
@@ -14,6 +14,7 @@ import {
SHOW_RECIPES,
} from './config';
import { getUniqueFocalLengths } from '@/photo/db/query';
+import { sortCategoryByCount } from '@/category';
export default async function CommandK() {
const [
@@ -41,12 +42,12 @@ export default async function CommandK() {
]);
return ;
diff --git a/src/category/index.ts b/src/category/index.ts
index 970c97f9..713f7b79 100644
--- a/src/category/index.ts
+++ b/src/category/index.ts
@@ -66,3 +66,8 @@ export const getOrderedCategoriesFromString = (
.map(category => category.trim().toLocaleLowerCase() as CategoryKey)
.filter(category => CATEGORY_KEYS.includes(category))
: DEFAULT_CATEGORY_KEYS;
+
+export const sortCategoryByCount = (
+ a: { count: number },
+ b: { count: number },
+) => b.count - a.count;
diff --git a/src/photo/PhotoGridSidebar.tsx b/src/photo/PhotoGridSidebar.tsx
index 5c08be71..d379a87c 100644
--- a/src/photo/PhotoGridSidebar.tsx
+++ b/src/photo/PhotoGridSidebar.tsx
@@ -1,13 +1,11 @@
'use client';
-import { sortCamerasWithCount } from '@/camera';
import PhotoCamera from '@/camera/PhotoCamera';
import HeaderList from '@/components/HeaderList';
import PhotoTag from '@/tag/PhotoTag';
import { PhotoDateRange, dateRangeForPhotos, photoQuantityText } from '.';
import { TAG_FAVS, TAG_HIDDEN, addHiddenToTags } from '@/tag';
import PhotoFilmSimulation from '@/simulation/PhotoFilmSimulation';
-import { sortFilmSimulationsWithCount } from '@/simulation';
import FavsTag from '../tag/FavsTag';
import { useAppState } from '@/state/AppState';
import { useMemo } from 'react';
@@ -18,17 +16,15 @@ import {
safelyParseFormattedHtml,
} from '@/utility/html';
import { clsx } from 'clsx/lite';
-import { sortRecipesWithCount } from '@/recipe';
import PhotoRecipe from '@/recipe/PhotoRecipe';
import IconCamera from '@/components/icons/IconCamera';
import IconRecipe from '@/components/icons/IconRecipe';
import IconTag from '@/components/icons/IconTag';
import IconFilmSimulation from '@/components/icons/IconFilmSimulation';
import IconLens from '@/components/icons/IconLens';
-import { sortLensesWithCount } from '@/lens';
import PhotoLens from '@/lens/PhotoLens';
import IconFocalLength from '@/components/icons/IconFocalLength';
-import { PhotoSetCategories } from '@/category';
+import { PhotoSetCategories, sortCategoryByCount } from '@/category';
import PhotoFocalLength from '@/focal/PhotoFocalLength';
export default function PhotoGridSidebar({
@@ -61,7 +57,7 @@ export default function PhotoGridSidebar({
className="translate-x-[0.5px]"
/>}
items={cameras
- .sort(sortCamerasWithCount)
+ .sort(sortCategoryByCount)
.map(({ cameraKey, camera, count }) =>
}
items={lenses
- .sort(sortLensesWithCount)
+ .sort(sortCategoryByCount)
.map(({ lensKey, lens, count }) =>
}
- items={tagsIncludingHidden.map(({ tag, count }) => {
- switch (tag) {
- case TAG_FAVS:
- return ;
- case TAG_HIDDEN:
- return ;
- default:
- return ;
- }
- })}
+ items={tagsIncludingHidden
+ .map(({ tag, count }) => {
+ switch (tag) {
+ case TAG_FAVS:
+ return ;
+ case TAG_HIDDEN:
+ return ;
+ default:
+ return ;
+ }
+ })}
/>
: null;
@@ -147,7 +144,8 @@ export default function PhotoGridSidebar({
size={16}
className="translate-x-[-1px]"
/>}
- items={sortRecipesWithCount(recipes)
+ items={recipes
+ .sort(sortCategoryByCount)
.map(({ recipe, count }) =>
}
items={simulations
- .sort(sortFilmSimulationsWithCount)
+ .sort(sortCategoryByCount)
.map(({ simulation, count }) =>
export const isTagHidden = (tag: string) => tag.toLowerCase() === TAG_HIDDEN;
-export const addHiddenToTags = (tags: Tags, photosCountHidden = 0) => {
- if (photosCountHidden > 0) {
- return tags
+export const addHiddenToTags = (tags: Tags, photosCountHidden = 0) =>
+ photosCountHidden > 0
+ ? tags
.filter(({ tag }) => tag === TAG_FAVS)
.concat({ tag: TAG_HIDDEN, count: photosCountHidden })
- .concat(tags.filter(({ tag }) => tag !== TAG_FAVS));
- } else {
- return tags;
- }
-};
+ .concat(tags
+ .filter(({ tag }) => tag !== TAG_FAVS)
+ .sort(sortCategoryByCount),
+ )
+ : tags;
export const convertTagsForForm = (tags: Tags = []) =>
sortTagsObjectWithoutFavs(tags)