Skip to content

Commit

Permalink
Limit tags or accounts shown in infobar.
Browse files Browse the repository at this point in the history
Also, do not sort tags or accounts, so users can decide which one are more important and shown first.
  • Loading branch information
defnull committed Feb 10, 2024
1 parent 9331674 commit b84f3e9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
52 changes: 37 additions & 15 deletions src/components/InfoBar.vue
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b84f3e9

Please sign in to comment.