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

219 lines
7.9 KiB
Vue
Raw Normal View History

<template>
2020-11-16 11:43:44 -08:00
<div v-if="profile">
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>
2020-12-08 14:14:40 -08:00
<div class="text-right">
<nuxt-link v-if="$user() && $user().username === username" to="/editor"
class="btn btn-outline-primary btn-sm mb-2"
>
<Icon v="edit"/>
<T>profile.edit</T>
</nuxt-link>
</div>
2020-10-24 12:50:08 -07:00
<div class="list-group" v-if="Object.keys(profiles).length > 1">
2020-12-06 08:15:08 -08:00
<a :href="`https://pronouns.page/@${username}`" v-if="$user() && $user().username === username"
class="list-group-item list-group-item-action small px-4 py-2 text-center"
>
<Icon v="external-link"/>
pronouns.page/@{{username}}
</a>
2020-10-24 12:50:08 -07:00
<LocaleLink v-for="(options, locale) in locales" :key="locale" v-if="profiles[locale] !== undefined"
:locale="locale" :link="`/@${username}`"
2020-12-06 08:15:08 -08:00
:class="['list-group-item list-group-item-action small px-4 py-2 text-center', locale === config.locale ? 'active disabled' : '']">
2020-10-24 12:50:08 -07:00
{{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">
<li v-for="flag in profile.flags" v-if="allFlags[flag]" class="list-inline-item pr-2">
2020-12-18 09:22:35 -08:00
<Flag :name="flag.startsWith('-') ? allFlags[flag] : $translateForPronoun(allFlags[flag], mainPronoun)" :alt="allFlags[flag]" :img="`/flags/${flag}.png`" :terms="terms"/>
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">
2020-12-10 07:23:39 -08:00
<Opinion :word="pronoun.name(glue) + (pronoun.smallForm ? '/' + pronoun.morphemes[pronoun.smallForm] : '')" :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-11-27 10:57:14 -08:00
<section class="clearfix">
2020-10-23 11:24:43 -07:00
<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>
2020-11-23 09:14:46 -08:00
<section>
<OpinionLegend/>
</section>
</div>
2020-11-16 11:43:44 -08:00
<div v-else-if="Object.keys(profiles).length">
2020-10-28 08:22:29 -07:00
<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)}`),
2020-12-18 09:22:35 -08:00
terms: await app.$axios.$get(`/terms`),
};
},
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-24 15:54:02 -08:00
const link = decodeURIComponent(
pronoun
2020-12-04 14:26:59 -08:00
.toLowerCase()
2020-12-05 13:01:12 -08:00
.trim()
2020-11-24 15:54:02 -08:00
.replace(new RegExp('^' + this.$base), '')
.replace(new RegExp('^' + this.$base.replace(/^https?:\/\//, '')), '')
.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
},
2020-12-08 14:14:40 -08:00
mainPronoun() {
let mainPronoun = buildPronoun(pronouns, this.config.profile.flags.defaultPronoun);
let mainOpinion = -1;
for (let {pronoun, opinion} of this.pronounOpinions) {
if (opinion === 2) {
opinion = 0.5;
}
if (opinion > mainOpinion) {
mainPronoun = pronoun;
mainOpinion = opinion;
}
}
return mainPronoun;
},
},
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-11-23 14:14:31 -08:00
@import "assets/variables";
2020-10-28 08:22:29 -07:00
.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>