This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/routes/profile.vue

184 lines
6.3 KiB
Vue
Raw Normal View History

<template>
2020-10-28 08:22:29 -07:00
<div v-if="profile" class="container">
2020-10-24 12:50:08 -07:00
<div class="mb-3 d-flex justify-content-between flex-column flex-md-row">
2020-10-23 11:24:43 -07:00
<h2 class="text-nowrap">
<Avatar :user="profile"/>
@{{username}}
</h2>
2020-10-24 12:50:08 -07:00
<div>
<nuxt-link v-if="$user() && $user().username === username" to="/editor"
2020-10-31 13:33:59 -07:00
class="btn btn-outline-primary btn-sm mb-2"
2020-10-24 12:50:08 -07:00
>
<Icon v="edit"/>
<T>profile.edit</T>
</nuxt-link>
<div class="list-group" v-if="Object.keys(profiles).length > 1">
<LocaleLink v-for="(options, locale) in locales" :key="locale" v-if="profiles[locale] !== undefined"
:locale="locale" :link="`/@${username}`"
:class="['list-group-item list-group-item-action small px-3 py-2 text-center', locale === config.locale ? 'active disabled' : '']">
{{options.name}}
</LocaleLink>
</div>
</div>
2020-10-23 11:24:43 -07:00
</div>
<section v-if="profile.age ||profile.description.trim().length">
2020-10-23 11:24:43 -07:00
<p v-for="line in profile.description.split('\n')" class="mb-1">
{{ line }}
</p>
<p v-if="profile.age">
<Icon v="birthday-cake"/>
{{ profile.age }}
</p>
2020-10-23 11:24:43 -07:00
</section>
2020-10-26 16:47:56 -07:00
<section v-if="profile.flags.length">
2020-10-23 11:24:43 -07:00
<ul class="list-inline">
2020-10-26 16:47:56 -07:00
<li v-for="flag in profile.flags" class="list-inline-item pr-2">
<Flag :name="allFlags[flag]" :src="`/flags/${flag}.png`"/>
2020-10-23 11:24:43 -07:00
</li>
</ul>
</section>
2020-10-26 16:47:56 -07:00
<section v-if="profile.links.length">
2020-10-23 11:24:43 -07:00
<ul class="list-inline">
2020-10-26 16:47:56 -07:00
<li v-for="link in profile.links" class="list-inline-item pr-2">
<ProfileLink :link="link"/>
2020-10-23 11:24:43 -07:00
</li>
</ul>
</section>
<section class="d-flex">
<div class="w-50" v-if="Object.keys(profile.names).length">
<h3>
<Icon v="signature"/>
<T>profile.names</T>
</h3>
2020-10-23 11:24:43 -07:00
<ul class="list-unstyled">
<li v-for="(opinion, name) in profile.names"><Opinion :word="name" :opinion="opinion"/></li>
</ul>
2020-10-23 11:24:43 -07:00
</div>
<div class="w-50" v-if="Object.keys(profile.pronouns).length">
<h3>
<Icon v="tags"/>
<T>profile.pronouns</T>
</h3>
2020-10-23 11:24:43 -07:00
<ul class="list-unstyled">
<li v-for="{link, pronoun, opinion} in pronounOpinions">
<Opinion :word="pronoun.name(glue)" :opinion="opinion" :link="`/${link}`"/>
2020-10-24 12:50:08 -07:00
</li>
2020-10-23 11:24:43 -07:00
</ul>
</div>
</section>
2020-10-23 11:24:43 -07:00
<section>
<h3>
<Icon v="scroll-old"/>
<T>profile.words</T>
</h3>
2020-10-25 04:00:45 -07:00
<div>
<div v-for="group in profile.words" v-if="Object.keys(profile.words).length" class="float-left w-50 w-md-25">
<ul class="list-unstyled">
2020-10-23 11:24:43 -07:00
<li v-for="(opinion, word) in group"><Opinion :word="word" :opinion="opinion"/></li>
</ul>
</div>
2020-10-23 11:24:43 -07:00
</div>
</section>
</div>
2020-10-28 08:22:29 -07:00
<div v-else-if="Object.keys(profiles).length" class="container">
<h2 class="text-nowrap mb-3">
<Avatar :user="profiles[Object.keys(profiles)[0]]"/>
@{{username}}
</h2>
<div class="list-group">
<LocaleLink v-for="(options, locale) in locales" :key="locale" v-if="profiles[locale] !== undefined"
:locale="locale" :link="`/@${username}`"
class="list-group-item list-group-item-action list-group-item-hoverable">
<div class="h3">
{{options.name}}
</div>
</LocaleLink>
</div>
</div>
<NotFound v-else/>
</template>
<script>
import { head } from "../src/helpers";
import { pronouns } from "~/src/data";
import { buildPronoun } from "../src/buildPronoun";
export default {
data() {
2020-10-28 08:22:29 -07:00
return {
username: this.$route.params.pathMatch,
profiles: {},
glue: ' ' + this.$t('pronouns.or') + ' ',
2020-10-26 16:42:42 -07:00
allFlags: process.env.FLAGS,
}
},
async asyncData({ app, route }) {
return {
profiles: await app.$axios.$get(`/profile/get/${encodeURIComponent(route.params.pathMatch)}`),
};
},
computed: {
profile() {
for (let locale in this.profiles) {
if (locale === this.config.locale) {
return this.profiles[locale];
}
}
return null;
},
pronounOpinions() {
const pronounOpinions = [];
2020-10-24 12:50:08 -07:00
for (let pronoun in this.profile.pronouns) {
if (!this.profile.pronouns.hasOwnProperty(pronoun)) { continue; }
2020-11-10 14:41:56 -08:00
const link = pronoun.replace(new RegExp('^' + this.$base), '').replace(new RegExp('^/'), '');
const pronounEntity = buildPronoun(pronouns, link);
2020-10-24 12:50:08 -07:00
if (pronounEntity) {
pronounOpinions.push({
2020-10-24 12:50:08 -07:00
link,
pronoun: pronounEntity,
opinion: this.profile.pronouns[pronoun],
2020-10-24 12:50:08 -07:00
});
}
}
return pronounOpinions;
2020-10-24 12:50:08 -07:00
},
},
head() {
return head({
title: `@${this.username}`,
2020-10-31 13:33:59 -07:00
banner: `api/banner/@${this.username}.png`,
});
},
}
</script>
<style lang="scss" scoped>
2020-10-28 08:22:29 -07:00
@import "assets/style";
.avatar {
width: 100%;
max-width: 5rem;
max-height: 5rem;
}
2020-10-28 08:22:29 -07:00
.list-group-item-hoverable {
&:hover {
color: $primary;
border-left: 3px solid $primary;
padding-left: calc(#{$list-group-item-padding-x} - 2px);
}
}
</style>