Sharkey/src/client/app/mobile/views/components/users-list.vue

136 lines
2.8 KiB
Vue
Raw Normal View History

2018-02-16 05:59:19 +02:00
<template>
<div class="mk-users-list">
<nav>
<span :data-active="mode == 'all'" @click="mode = 'all'">{{ $t('all') }}<span>{{ count }}</span></span>
<span v-if="$store.getters.isSignedIn && youKnowCount" :data-active="mode == 'iknow'" @click="mode = 'iknow'">{{ $t('known') }}<span>{{ youKnowCount }}</span></span>
2018-02-16 05:59:19 +02:00
</nav>
<div class="users" v-if="!fetching && users.length != 0">
<mk-user-preview v-for="u in users" :user="u" :key="u.id"/>
</div>
<button class="more" v-if="!fetching && next != null" @click="more" :disabled="moreFetching">
<span v-if="!moreFetching">{{ $t('@.load-more') }}</span>
<span v-if="moreFetching">{{ $t('@.loading') }}<mk-ellipsis/></span>
2018-02-16 05:59:19 +02:00
</button>
<p class="no" v-if="!fetching && users.length == 0">
<slot></slot>
</p>
2018-11-13 15:45:28 +02:00
<p class="fetching" v-if="fetching"><fa icon="spinner" pulse fixed-width/>{{ $t('@.loading') }}<mk-ellipsis/></p>
2018-02-16 05:59:19 +02:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
2018-02-16 05:59:19 +02:00
export default Vue.extend({
i18n: i18n('mobile/views/components/users-list.vue'),
2018-02-16 05:59:19 +02:00
props: ['fetch', 'count', 'youKnowCount'],
data() {
return {
limit: 30,
mode: 'all',
fetching: true,
moreFetching: false,
users: [],
next: null
};
},
2018-02-22 15:51:33 +02:00
watch: {
mode() {
this._fetch();
}
},
2018-02-16 05:59:19 +02:00
mounted() {
this._fetch(() => {
this.$emit('loaded');
});
},
methods: {
2018-02-22 15:51:33 +02:00
_fetch(cb?) {
2018-02-16 05:59:19 +02:00
this.fetching = true;
this.fetch(this.mode == 'iknow', this.limit, null, obj => {
this.users = obj.users;
this.next = obj.next;
2018-02-19 16:37:09 +02:00
this.fetching = false;
2018-02-16 05:59:19 +02:00
if (cb) cb();
});
},
more() {
this.moreFetching = true;
this.fetch(this.mode == 'iknow', this.limit, this.next, obj => {
this.moreFetching = false;
this.users = this.users.concat(obj.users);
this.next = obj.next;
});
}
}
});
</script>
<style lang="stylus" scoped>
2018-09-26 14:19:35 +03:00
2018-03-03 06:47:55 +02:00
2018-02-16 05:59:19 +02:00
.mk-users-list
> nav
display flex
justify-content center
margin 0 auto
max-width 600px
2018-04-29 02:51:17 +03:00
border-bottom solid 1px rgba(#000, 0.2)
2018-02-16 05:59:19 +02:00
> span
display block
flex 1 1
text-align center
line-height 52px
font-size 14px
color #657786
border-bottom solid 2px transparent
2018-04-26 08:38:37 +03:00
&[data-active]
2018-02-16 05:59:19 +02:00
font-weight bold
2018-09-26 14:19:35 +03:00
color var(--primary)
border-color var(--primary)
2018-02-16 05:59:19 +02:00
> span
display inline-block
margin-left 4px
padding 2px 5px
font-size 12px
line-height 1
color #fff
2018-04-29 02:51:17 +03:00
background rgba(#000, 0.3)
2018-02-16 05:59:19 +02:00
border-radius 20px
> .users
margin 8px auto
max-width 500px
width calc(100% - 16px)
background #fff
border-radius 8px
2018-04-29 02:51:17 +03:00
box-shadow 0 0 0 1px rgba(#000, 0.2)
2018-02-16 05:59:19 +02:00
@media (min-width 500px)
margin 16px auto
width calc(100% - 32px)
> *
2018-04-29 02:51:17 +03:00
border-bottom solid 1px rgba(#000, 0.05)
2018-02-16 05:59:19 +02:00
> .no
margin 0
padding 16px
text-align center
color #aaa
> .fetching
margin 0
padding 16px
text-align center
color #aaa
> [data-icon]
2018-02-16 05:59:19 +02:00
margin-right 4px
</style>