Skip to content

Commit

Permalink
Merge pull request #2470 from nextcloud/fix/uniq-keywords
Browse files Browse the repository at this point in the history
Reopen of #2416
  • Loading branch information
christianlupus authored Aug 26, 2024
2 parents 0f940e4 + f525937 commit e002ea2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit e002ea2

Please sign in to comment.