Limit tags or accounts shown in infobar.

Also, do not sort tags or accounts, so users can decide which one are more important and shown first.
This commit is contained in:
Marcel Hellkamp 2024-02-10 12:50:01 +01:00
parent 93316741f2
commit b84f3e9efa
2 changed files with 39 additions and 17 deletions

View File

@ -1,31 +1,53 @@
<script setup lang="ts">
import { type Config } from '@/types';
import { computed } from 'vue';
defineProps<{
const props = defineProps<{
config: Config
}>()
const tagLimit = 5;
const accountLimit = 2;
const tagsHidden = computed(()=> Math.max(0, props.config.tags.length - tagLimit))
const accountsHidden = computed(()=> Math.max(0, props.config.accounts.length - accountLimit))
const tags = computed(()=>{
const limited = props.config.tags.slice(0, tagLimit)
return limited
})
const accounts = computed(()=>{
const limited = props.config.accounts.slice(0,accountLimit)
return limited
})
function sep(index: number, length: number, sep: string, lastsep: string) {
if(index < length - 2)
return sep
else if(index == length - 2)
return lastsep
}
</script>
<template>
<div>
This Fediwall shows
<template v-if="config.tags.length">
posts tagged with
<template v-for="(t, index) in config.tags" :key="t">
<code>#{{ t }}</code>
<template v-if="index < config.tags.length - 2">, </template>
<template v-else-if="index == config.tags.length - 2"> or </template>
This Fediwall shows posts
<template v-if="tags.length">
tagged with
<template v-for="(t, index) in tags" :key="index">
<code>#{{ t }}</code>{{ sep(index, tags.length, ", ", tagsHidden ? ", " : " or ") }}
</template>
<span v-if="tagsHidden"> and more</span>
</template>
<template v-if="config.accounts.length && config?.tags.length"> and </template>
<template v-if="config.accounts.length">
posts or boosts by
<template v-for="(acc, index) in config.accounts" :key="acc">
<code>@{{ acc }}</code>
<template v-if="index < config.accounts.length - 2">, </template>
<template v-else-if="index == config.accounts.length - 2"> or </template>
<template v-if="accounts.length">
<template v-if="tags.length"> as well as posts </template>
by
<template v-for="(acc, index) in accounts" :key="index">
<code>@{{ acc }}</code>{{ sep(index, accounts.length, ", ", accountsHidden ? ", " : " or ") }}
</template>
<span v-if="accountsHidden"> and more</span>
</template>
</div>
</template>

View File

@ -247,8 +247,8 @@ export function sanatizeConfig(config: any): Config {
const result: Partial<Config> = {}
result.servers = arrayUnique((Array.isArray(config.servers) ? [...config.servers] : [...fallback.servers]).filter(isServer));
result.tags = arrayUnique((Array.isArray(config.tags) ? [...config.tags] : [...fallback.tags]).map(stripTag).filter(isTag).sort() as string[]);
result.accounts = arrayUnique((Array.isArray(config.accounts) ? [...config.accounts] : [...fallback.accounts]).filter(isAccount).sort());
result.tags = arrayUnique((Array.isArray(config.tags) ? [...config.tags] : [...fallback.tags]).map(stripTag).filter(isTag) as string[]);
result.accounts = arrayUnique((Array.isArray(config.accounts) ? [...config.accounts] : [...fallback.accounts]).filter(isAccount));
result.loadFederated = boolOr(config.loadFederated, fallback.loadFederated)
result.loadPublic = boolOr(config.loadPublic, fallback.loadPublic)