Skip to content

Commit

Permalink
feat: improve sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuk1ko committed Oct 31, 2024
1 parent 1006382 commit 48ea333
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/views/Links.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<script setup>
import { onMounted, shallowRef, computed } from 'vue';
import { isEqual } from 'lodash';
import { groupBy, isEqual } from 'lodash';
import { createInstance } from 'localforage';
import LinkCard from '@/components/links/LinkCard.vue';
import { useCeobeApiUtils } from '@/utils/ceobeCanteen';
Expand All @@ -24,11 +24,16 @@ const storage = createInstance({ name: 'recommended-links' });
const linkList = shallowRef([]);
const sortedLinkList = computed(() =>
[...linkList.value].sort((a, b) =>
getLocalizedText(a.localized_name).localeCompare(getLocalizedText(b.localized_name)),
),
);
const sortedLinkList = computed(() => {
const startWithAlphabetRegexp = /^[a-z]/i;
const { true: first = [], false: second = [] } = groupBy(linkList.value, item =>
startWithAlphabetRegexp.test(getLocalizedText(item.localized_name)),
);
const sortMethod = (a, b) =>
getLocalizedText(a.localized_name).localeCompare(getLocalizedText(b.localized_name));
return [first, second].flatMap(list => list.sort(sortMethod));
});
onMounted(() => {
initLinkList();
Expand Down

0 comments on commit 48ea333

Please sign in to comment.