akkoma-fe-chuckya/src/components/scope_selector/scope_selector.js
jadiunr d617a9596a Add support selectable visibility of repeat
Co-authored-by: Oneric <oneric@oneric.stub>
2025-05-18 22:52:55 +02:00

75 lines
1.6 KiB
JavaScript

import { library } from '@fortawesome/fontawesome-svg-core'
import {
faEnvelope,
faLock,
faLockOpen,
faGlobe
} from '@fortawesome/free-solid-svg-icons'
import scopeUtils from 'src/lib/scope_utils.js'
library.add(
faEnvelope,
faGlobe,
faLock,
faLockOpen
)
const ScopeSelector = {
props: [
'showAll',
'userDefault',
// scope of parent object
'originalScope',
'initialScope',
'onScopeChange'
],
data () {
return {
currentScope: this.initialScope
}
},
computed: {
showNothing () {
return !this.showPublic && !this.showUnlisted && !this.showPrivate && !this.showDirect
},
showPublic () {
return this.shouldShow('public')
},
showLocal () {
return this.shouldShow('local')
},
showUnlisted () {
return this.shouldShow('unlisted')
},
showPrivate () {
return this.shouldShow('private')
},
showDirect () {
return this.shouldShow('direct')
},
css () {
return {
public: { selected: this.currentScope === 'public' },
unlisted: { selected: this.currentScope === 'unlisted' },
private: { selected: this.currentScope === 'private' },
direct: { selected: this.currentScope === 'direct' },
local: { selected: this.currentScope === 'local' }
}
}
},
methods: {
shouldShow (scope) {
if (!this.originalScope)
return true
else
return scopeUtils.compare(scope, this.originalScope) <= 0
},
changeVis (scope) {
this.currentScope = scope
this.onScopeChange && this.onScopeChange(scope)
}
}
}
export default ScopeSelector