traxxx/assets/components/users/user.vue

251 lines
4.0 KiB
Vue
Raw Normal View History

<template>
<div
v-if="user"
class="user"
>
<div class="header">
<h2 class="username">{{ user.username }}</h2>
</div>
<section
2021-03-15 02:30:47 +00:00
v-if="user.stashes?.length > 0"
class="section"
>
<div class="section-header">
<h3 class="section-heading">Stashes</h3>
<button
v-if="isMe"
class="button button-secondary header-add"
@click="showAddStash = true"
>
<Icon icon="plus3" />Add stash
</button>
</div>
<ul class="section-body stashes nolist">
<li
2021-03-15 02:30:47 +00:00
v-for="stash in user.stashes"
:key="stash.id"
class="stashes-stash"
>
2021-03-20 01:49:17 +00:00
<Stash
:stash="stash"
:is-me="isMe"
@publish="() => fetchUser()"
2021-03-20 22:03:13 +00:00
@remove="() => fetchUser()"
2021-03-20 01:49:17 +00:00
/>
</li>
2021-03-20 02:22:08 +00:00
<!--
2021-03-20 02:22:08 +00:00
<li
v-if="isMe"
class="stashes-stash stashes-add"
2021-03-20 02:22:08 +00:00
@click="showAddStash = true"
>
<Icon icon="plus2" />
</li>
-->
</ul>
2021-04-04 22:48:03 +00:00
<AddStash
v-if="showAddStash"
@close="closeAddStash"
/>
</section>
2021-03-20 02:22:08 +00:00
<section class="section">
2021-04-04 22:48:03 +00:00
<div class="section-header">
<h3 class="section-heading">Alerts</h3>
<button
v-if="isMe"
class="button button-secondary header-add"
2021-04-04 22:48:03 +00:00
@click="showAddAlert = true"
>
<Icon icon="plus3" />Set alert
</button>
2021-04-04 22:48:03 +00:00
</div>
<ul class="section-body alerts nolist">
<li
v-for="alert in user.alerts"
:key="`alert-${alert.id}`"
class="alert"
>
<Alert
:alert="alert"
:is-me="isMe"
@remove="() => fetchUser()"
/>
</li>
<!--
2021-04-04 22:48:03 +00:00
<li
class="alerts-add"
@click="showAddAlert = true"
>
<Icon icon="plus2" />
</li>
-->
2021-04-04 22:48:03 +00:00
</ul>
<AddAlert
v-if="showAddAlert"
@close="closeAddAlert"
>Alert</AddAlert>
</section>
</div>
</template>
<script>
2021-03-20 01:49:17 +00:00
import Stash from './stash.vue';
2021-04-04 22:48:03 +00:00
import Alert from './alert.vue';
import AddStash from '../stashes/add.vue';
import AddAlert from '../alerts/add.vue';
async function fetchUser() {
2021-03-15 02:30:47 +00:00
this.user = await this.$store.dispatch('fetchUser', this.$route.params.username);
this.isMe = this.user?.id === this.$store.state.auth.user?.id;
2021-03-15 02:30:47 +00:00
this.pageTitle = this.user?.username;
}
async function closeAddStash(addedStash) {
this.showAddStash = false;
if (addedStash) {
await this.fetchUser();
}
}
2021-04-04 22:48:03 +00:00
async function closeAddAlert(addedAlert) {
this.showAddAlert = false;
if (addedAlert) {
await this.fetchUser();
}
}
async function mounted() {
await this.fetchUser();
}
export default {
components: {
2021-04-04 22:48:03 +00:00
AddAlert,
2021-03-20 02:22:08 +00:00
AddStash,
2021-04-04 22:48:03 +00:00
Alert,
2021-03-20 01:49:17 +00:00
Stash,
},
data() {
return {
user: this.$route.params.username === this.$store.state.auth.user?.username
? this.$store.state.auth.user
: null,
isMe: false,
2021-03-15 02:30:47 +00:00
pageTitle: null,
2021-03-20 02:22:08 +00:00
showAddStash: false,
2021-04-04 22:48:03 +00:00
showAddAlert: false,
};
},
mounted,
methods: {
2021-04-04 22:48:03 +00:00
closeAddAlert,
closeAddStash,
fetchUser,
},
};
</script>
<style lang="scss" scoped>
@import 'breakpoints';
.header {
display: flex;
justify-content: space-between;
background: var(--profile);
}
.username {
padding: .5rem 1rem;
margin: 0;
font-size: 1.5rem;
color: var(--text-light);
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.section {
padding: 1rem 0;
margin: 0 0 1rem 0;
}
2021-04-04 22:48:03 +00:00
.stashes,
.alerts {
display: grid;
grid-template-columns: 1fr 1fr;
2021-03-20 02:22:08 +00:00
grid-auto-rows: 15fr;
grid-gap: 1rem;
}
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 1rem 1rem 0;
}
.section-body {
padding: 0 1rem;
}
.section-heading {
color: var(--primary);
padding: 0 1rem;
margin: 0;
font-size: 1.25rem;
}
.header-add {
}
.stashes-stash {
min-width: 0;
}
2021-04-04 22:48:03 +00:00
.stashes-add,
.alerts-add {
2021-03-20 02:22:08 +00:00
height: 100%;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
padding: 1rem;
2021-03-20 22:03:13 +00:00
background: var(--shadow-touch);
2021-03-20 02:22:08 +00:00
.icon {
width: 1.5rem;
height: 1.5rem;
2021-03-20 22:03:13 +00:00
fill: var(--shadow-hint);
2021-03-20 02:22:08 +00:00
}
&:hover {
2021-03-20 22:03:13 +00:00
background: var(--shadow-hint);
2021-03-20 02:22:08 +00:00
cursor: pointer;
.icon {
2021-03-20 22:03:13 +00:00
fill: var(--shadow-weak);
2021-03-20 02:22:08 +00:00
}
}
}
@media(max-width: $breakpoint-kilo) {
2021-04-04 22:48:03 +00:00
.stashes,
.alerts {
grid-template-columns: 1fr;
}
}
</style>