mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
Moved the sorting function to helper file to prevent duplicate code.
This commit is contained in:
parent
43a3b57dd9
commit
38d7ab9661
@ -33,3 +33,18 @@ export function deletePostMutation(postId) {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function sortTagsAlphabetically(tags) {
|
||||
// Make sure the property is valid.
|
||||
if (!tags || !tags.length) return false
|
||||
/* Using .slice(0) to make a shallow copy. Otherwise a vue/no-side-effects-in-computed-properties error
|
||||
would be thrown because sort() sorts in place. A shallow copy is fine because only first level objects are
|
||||
affected by the sort, the original tags object remains unchanged.
|
||||
*/
|
||||
return tags.slice(0).sort(function (a, b) {
|
||||
// Converting to lowercase to make sort case insensitive.
|
||||
const tagA = a.id.toLowerCase()
|
||||
const tagB = b.id.toLowerCase()
|
||||
return tagA < tagB ? -1 : tagA > tagB ? 1 : 0
|
||||
})
|
||||
}
|
||||
|
||||
@ -116,7 +116,11 @@ import UserTeaser from '~/components/UserTeaser/UserTeaser'
|
||||
import HcShoutButton from '~/components/ShoutButton.vue'
|
||||
import CommentForm from '~/components/CommentForm/CommentForm'
|
||||
import CommentList from '~/components/CommentList/CommentList'
|
||||
import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostHelpers'
|
||||
import {
|
||||
postMenuModalsData,
|
||||
deletePostMutation,
|
||||
sortTagsAlphabetically,
|
||||
} from '~/components/utils/PostHelpers'
|
||||
import PostQuery from '~/graphql/PostQuery'
|
||||
import HcEmotions from '~/components/Emotions/Emotions'
|
||||
import PostMutations from '~/graphql/PostMutations'
|
||||
@ -180,18 +184,7 @@ export default {
|
||||
return this.$store.getters['auth/user'].id === author.id
|
||||
},
|
||||
sortedTags() {
|
||||
// Make sure the property is valid.
|
||||
if (!this.post.tags || !this.post.tags.length) return false
|
||||
/* Using .slice(0) to make a shallow copy. Otherwise a vue/no-side-effects-in-computed-properties error
|
||||
would be thrown because sort() sorts in place. A shallow copy is fine because only first level objects are
|
||||
affected by the sort, the original this.post.tags object remains unchanged.
|
||||
*/
|
||||
return this.post.tags.slice(0).sort(function (a, b) {
|
||||
// Converting to lowercase to make sort case insensitive.
|
||||
const tagA = a.id.toLowerCase()
|
||||
const tagB = b.id.toLowerCase()
|
||||
return tagA < tagB ? -1 : tagA > tagB ? 1 : 0
|
||||
})
|
||||
return sortTagsAlphabetically(this.post.tags)
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
||||
@ -44,6 +44,7 @@ import HcHashtag from '~/components/Hashtag/Hashtag'
|
||||
import { relatedContributions } from '~/graphql/PostQuery'
|
||||
import MasonryGrid from '~/components/MasonryGrid/MasonryGrid.vue'
|
||||
import MasonryGridItem from '~/components/MasonryGrid/MasonryGridItem.vue'
|
||||
import { sortTagsAlphabetically } from '~/components/utils/PostHelpers'
|
||||
|
||||
export default {
|
||||
transition: {
|
||||
@ -63,18 +64,7 @@ export default {
|
||||
return this.Post ? this.Post[0] || {} : {}
|
||||
},
|
||||
sortedTags() {
|
||||
// Make sure the property is valid.
|
||||
if (!this.post.tags || !this.post.tags.length) return false
|
||||
/* Using .slice(0) to make a shallow copy. Otherwise a vue/no-side-effects-in-computed-properties error
|
||||
would be thrown because sort() sorts in place. A shallow copy is fine because only first level objects are
|
||||
affected by the sort, the original this.post.tags object remains unchanged.
|
||||
*/
|
||||
return this.post.tags.slice(0).sort(function (a, b) {
|
||||
// Converting to lowercase to make sort case insensitive.
|
||||
const tagA = a.id.toLowerCase()
|
||||
const tagB = b.id.toLowerCase()
|
||||
return tagA < tagB ? -1 : tagA > tagB ? 1 : 0
|
||||
})
|
||||
return sortTagsAlphabetically(this.post.tags)
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user