Skip to content

Commit

Permalink
move visibility helpers to lib/visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlath committed Aug 6, 2022
1 parent 288be1c commit 2e47752
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
23 changes: 23 additions & 0 deletions app/modules/general/lib/visibility.js
Expand Up @@ -8,3 +8,26 @@ export const getGroupVisibilityKey = group => `group:${group._id}`

export const isGroupVisibilityKey = key => key.startsWith('group:')
export const isNotGroupVisibilityKey = key => !isGroupVisibilityKey(key)

export const getCorrespondingListing = visibility => {
if (visibility.length === 0) return 'private'
if (visibility.includes('public')) return 'public'
return 'network'
}

export const getIconLabel = visibility => {
if (visibility.length === 0) return 'private'
if (visibility.includes('public')) return 'public'

const groupKeyCount = visibility.filter(isGroupVisibilityKey).length
if (visibility.includes('friends') && visibility.includes('groups')) {
return 'friends and groups'
} else if (groupKeyCount > 0) {
if (visibility.includes('friends')) return 'friends and some groups'
else return 'some groups'
} else if (visibility.includes('groups')) {
return 'groups'
} else {
return 'friends'
}
}
28 changes: 2 additions & 26 deletions app/modules/shelves/models/shelf.js
@@ -1,7 +1,6 @@
import { getColorHexCodeFromModelId, getColorSquareDataUri } from '#lib/images'

import error_ from '#lib/error'
import { isGroupVisibilityKey } from '#general/lib/visibility'
import { getColorHexCodeFromModelId, getColorSquareDataUri } from '#lib/images'
import { getCorrespondingListing, getIconLabel } from '#general/lib/visibility'

export default Backbone.Model.extend({
initialize (attrs) {
Expand Down Expand Up @@ -49,26 +48,3 @@ export default Backbone.Model.extend({

getRss () { return app.API.feeds('shelf', this.id) },
})

const getCorrespondingListing = visibility => {
if (visibility.length === 0) return 'private'
if (visibility.includes('public')) return 'public'
return 'network'
}

const getIconLabel = visibility => {
if (visibility.length === 0) return 'private'
if (visibility.includes('public')) return 'public'

const groupKeyCount = visibility.filter(isGroupVisibilityKey).length
if (visibility.includes('friends') && visibility.includes('groups')) {
return 'friends and groups'
} else if (groupKeyCount > 0) {
if (visibility.includes('friends')) return 'friends and some groups'
else return 'some groups'
} else if (visibility.includes('groups')) {
return 'groups'
} else {
return 'friends'
}
}

0 comments on commit 2e47752

Please sign in to comment.