Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webapp): 🍰 Sort Categories By Name #5709

Merged
merged 6 commits into from
Nov 29, 2022
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: 3 additions & 1 deletion webapp/components/CategoriesSelect/CategoriesSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import CategoryQuery from '~/graphql/CategoryQuery'
import { CATEGORIES_MAX } from '~/constants/categories.js'
import xor from 'lodash/xor'
import SortCategories from '~/mixins/sortCategoriesMixin.js'

export default {
inject: {
$parentForm: {
default: null,
},
},
mixins: [SortCategories],
props: {
existingCategoryIds: { type: Array, default: () => [] },
model: { type: String, required: true },
Expand Down Expand Up @@ -72,7 +74,7 @@ export default {
return CategoryQuery()
},
result({ data: { Category } }) {
this.categories = Category
this.categories = this.sortCategories(Category)
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion webapp/components/FilterMenu/CategoriesFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ import CategoryQuery from '~/graphql/CategoryQuery.js'
import SaveCategories from '~/graphql/SaveCategories.js'
import FilterMenuSection from '~/components/FilterMenu/FilterMenuSection'
import LabeledButton from '~/components/_new/generic/LabeledButton/LabeledButton'
import SortCategories from '~/mixins/sortCategoriesMixin.js'

export default {
components: {
FilterMenuSection,
LabeledButton,
},
mixins: [SortCategories],
props: {
showMobileMenu: { type: Boolean, default: false },
},
Expand Down Expand Up @@ -84,7 +86,7 @@ export default {
},
update({ Category }) {
if (!Category) return []
this.categories = Category
this.categories = this.sortCategories(Category)
},
fetchPolicy: 'cache-and-network',
},
Expand Down
25 changes: 25 additions & 0 deletions webapp/mixins/sortCategoriesMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default {
methods: {
sortCategories(categories) {
const miscSlug = 'miscellaneous'
const misc = categories.find((cat) => cat.slug === miscSlug)
const sortedCategories = categories
.filter((cat) => cat.slug !== miscSlug)
.sort((a, b) => {
if (
this.$t(`contribution.category.name.${a.slug}`) <
this.$t(`contribution.category.name.${b.slug}`)
)
return -1
if (
this.$t(`contribution.category.name.${a.slug}`) >
this.$t(`contribution.category.name.${b.slug}`)
)
return 1
return 0
})
if (misc) sortedCategories.push(misc)
return sortedCategories
},
},
}
99 changes: 51 additions & 48 deletions webapp/pages/group/_id/_slug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
/>
<!-- TODO: implement later on -->
<!-- @mute="muteUser"
@unmute="unmuteUser"
@block="blockUser"
@unblock="unblockUser"
@delete="deleteUser" -->
@unmute="unmuteUser"
@block="blockUser"
@unblock="unblockUser"
@delete="deleteUser" -->
</client-only>
<ds-space margin="small">
<!-- group name -->
Expand Down Expand Up @@ -65,38 +65,38 @@
</client-only>
</ds-flex-item>
<!-- <ds-flex-item>
<client-only>
<ds-number :label="$t('profile.followers')">
<count-to
slot="count"
:start-val="followedByCountStartValue"
:end-val="user.followedByCount"
/>
</ds-number>
</client-only>
</ds-flex-item> -->
<client-only>
<ds-number :label="$t('profile.followers')">
<count-to
slot="count"
:start-val="followedByCountStartValue"
:end-val="user.followedByCount"
/>
</ds-number>
</client-only>
</ds-flex-item> -->
<!-- <ds-flex-item>
<client-only>
<ds-number :label="$t('profile.following')">
<count-to slot="count" :end-val="user.followingCount" />
</ds-number>
</client-only>
</ds-flex-item> -->
<client-only>
<ds-number :label="$t('profile.following')">
<count-to slot="count" :end-val="user.followingCount" />
</ds-number>
</client-only>
</ds-flex-item> -->
</ds-flex>
<div class="action-buttons">
<!-- <base-button v-if="user.isBlocked" @click="unblockUser(user)">
{{ $t('settings.blocked-users.unblock') }}
</base-button>
<base-button v-if="user.isMuted" @click="unmuteUser(user)">
{{ $t('settings.muted-users.unmute') }}
</base-button>
<follow-button
v-if="!user.isMuted && !user.isBlocked"
:follow-id="user.id"
:is-followed="user.followedByCurrentUser"
@optimistic="optimisticFollow"
@update="updateFollow"
/> -->
{{ $t('settings.blocked-users.unblock') }}
</base-button>
<base-button v-if="user.isMuted" @click="unmuteUser(user)">
{{ $t('settings.muted-users.unmute') }}
</base-button>
<follow-button
v-if="!user.isMuted && !user.isBlocked"
:follow-id="user.id"
:is-followed="user.followedByCurrentUser"
@optimistic="optimisticFollow"
@update="updateFollow"
/> -->
<!-- Group join / leave -->
<join-leave-button
:group="group || {}"
Expand All @@ -108,7 +108,7 @@
@update="updateJoinLeave"
/>
<!-- implement:
v-if="!user.isMuted && !user.isBlocked" -->
v-if="!user.isMuted && !user.isBlocked" -->
</div>
<hr />
<ds-space margin-top="small" margin-bottom="small">
Expand Down Expand Up @@ -161,7 +161,9 @@
<ds-space margin="xx-small" />
<div class="categories">
<div
v-for="(category, index) in group.categories"
v-for="(category, index) in sortCategories(
group && group.categories ? group.categories : [],
)"
:key="category.id"
align="center"
>
Expand Down Expand Up @@ -211,19 +213,19 @@
@fetchAllProfiles="fetchAllMembers"
/>
<!-- <ds-space />
<follow-list
:loading="$apollo.loading"
:user="user"
type="followedBy"
@fetchAllConnections="fetchAllConnections"
/>
<ds-space />
<follow-list
:loading="$apollo.loading"
:user="user"
type="following"
@fetchAllConnections="fetchAllConnections"
/> -->
<follow-list
:loading="$apollo.loading"
:user="user"
type="followedBy"
@fetchAllConnections="fetchAllConnections"
/>
<ds-space />
<follow-list
:loading="$apollo.loading"
:user="user"
type="following"
@fetchAllConnections="fetchAllConnections"
/> -->
<!-- <social-media :user-name="groupName" :user="user" /> -->
</ds-flex-item>

Expand Down Expand Up @@ -326,6 +328,7 @@ import MasonryGridItem from '~/components/MasonryGrid/MasonryGridItem.vue'
import PostTeaser from '~/components/PostTeaser/PostTeaser.vue'
import ProfileAvatar from '~/components/_new/generic/ProfileAvatar/ProfileAvatar'
import ProfileList from '~/components/features/ProfileList/ProfileList'
import SortCategories from '~/mixins/sortCategoriesMixin.js'
// import SocialMedia from '~/components/SocialMedia/SocialMedia'
// import TabNavigation from '~/components/_new/generic/TabNavigation/TabNavigation'

Expand Down Expand Up @@ -356,7 +359,7 @@ export default {
// SocialMedia,
// TabNavigation,
},
mixins: [postListActions],
mixins: [postListActions, SortCategories],
transition: {
name: 'slide-up',
mode: 'out-in',
Expand Down
4 changes: 3 additions & 1 deletion webapp/pages/post/_id/_slug/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<ds-space margin="xx-large" />
<ds-space margin="xx-small" />
<hc-category
v-for="category in post.categories"
v-for="category in sortCategories(post.categories)"
:key="category.id"
:icon="category.icon"
:name="$t(`contribution.category.name.${category.slug}`)"
Expand Down Expand Up @@ -146,6 +146,7 @@ import PostQuery from '~/graphql/PostQuery'
import { groupQuery } from '~/graphql/groups'
import PostMutations from '~/graphql/PostMutations'
import links from '~/constants/links.js'
import SortCategories from '~/mixins/sortCategoriesMixin.js'

export default {
name: 'PostSlug',
Expand All @@ -164,6 +165,7 @@ export default {
PageParamsLink,
UserTeaser,
},
mixins: [SortCategories],
head() {
return {
title: this.title,
Expand Down