Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/current/2470-uniq-keywords-and-categories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Author: @nathanielhourt

# Fixed
- Prevent duplicated keywords and categories that differ only in case
19 changes: 16 additions & 3 deletions src/composables/useRecipeFilterControls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import { AndOperator, OrOperator } from '../../js/LogicOperators';
export default function useRecipeFilterControls(props) {
const store = useStore();

// Helper method that sorts strings case insensitively
const caseInsensitiveSort = (a, b) => {
const aUpper = a.toUpperCase();
const bUpper = b.toUpperCase();
if (aUpper < bUpper) return -1;
if (bUpper < aUpper) return 1;
return 0;
};

/**
* @type {import('vue').Ref<string>}
*/
Expand Down Expand Up @@ -114,7 +123,9 @@ export default function useRecipeFilterControls(props) {
* A unique set of all categories in the recipes.
* @type {import('vue').ComputedRef<Array<string>>}
*/
const uniqueCategories = computed(() => [...new Set(rawCategories.value)]);
const uniqueCategories = computed(() =>
[...new Set(rawCategories.value)].sort(caseInsensitiveSort),
);

/**
* An array of all keywords in the recipes. These are neither sorted nor unique
Expand All @@ -133,9 +144,11 @@ export default function useRecipeFilterControls(props) {
});

/**
* A unique set of all keywords in all recipes.
* A unique and sorted set of all keywords in all recipes.
*/
const uniqueKeywords = computed(() => [...new Set(rawKeywords.value)]);
const uniqueKeywords = computed(() =>
[...new Set(rawKeywords.value)].sort(caseInsensitiveSort),
);

return {
uniqueCategories,
Expand Down