2018-02-15 06:37:25 +00:00
|
|
|
<template>
|
|
|
|
<button class="mk-follow-button"
|
2018-06-02 04:11:28 +00:00
|
|
|
:class="{ wait: wait, active: u.isFollowing || u.hasPendingFollowRequestFromYou }"
|
2018-02-15 06:37:25 +00:00
|
|
|
@click="onClick"
|
|
|
|
:disabled="wait"
|
|
|
|
>
|
2018-06-01 15:15:17 +00:00
|
|
|
<template v-if="!wait">
|
2018-10-01 10:28:24 +00:00
|
|
|
<template v-if="u.hasPendingFollowRequestFromYou && u.isLocked">%fa:hourglass-half% %i18n:@request-pending%</template>
|
|
|
|
<template v-else-if="u.hasPendingFollowRequestFromYou && !u.isLocked">%fa:hourglass-start% %i18n:@follow-processing%</template>
|
2018-06-03 10:39:02 +00:00
|
|
|
<template v-else-if="u.isFollowing">%fa:minus% %i18n:@following%</template>
|
2018-06-02 03:58:56 +00:00
|
|
|
<template v-else-if="!u.isFollowing && u.isLocked">%fa:plus% %i18n:@follow-request%</template>
|
|
|
|
<template v-else-if="!u.isFollowing && !u.isLocked">%fa:plus% %i18n:@follow%</template>
|
2018-06-01 15:15:17 +00:00
|
|
|
</template>
|
|
|
|
<template v-else>%fa:spinner .pulse .fw%</template>
|
2018-02-15 06:37:25 +00:00
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
export default Vue.extend({
|
|
|
|
props: {
|
|
|
|
user: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2018-06-02 03:58:56 +00:00
|
|
|
u: this.user,
|
2018-02-15 06:37:25 +00:00
|
|
|
wait: false,
|
2018-10-07 02:06:17 +00:00
|
|
|
connection: null
|
2018-02-15 06:37:25 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2018-10-07 02:06:17 +00:00
|
|
|
this.connection = (this as any).os.stream.useSharedConnection('main');
|
2018-02-15 06:37:25 +00:00
|
|
|
|
|
|
|
this.connection.on('follow', this.onFollow);
|
|
|
|
this.connection.on('unfollow', this.onUnfollow);
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2018-10-07 02:06:17 +00:00
|
|
|
this.connection.dispose();
|
2018-02-15 06:37:25 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
onFollow(user) {
|
2018-06-02 03:58:56 +00:00
|
|
|
if (user.id == this.u.id) {
|
|
|
|
this.u.isFollowing = user.isFollowing;
|
2018-09-04 09:33:16 +00:00
|
|
|
this.u.hasPendingFollowRequestFromYou = user.hasPendingFollowRequestFromYou;
|
2018-02-15 06:37:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onUnfollow(user) {
|
2018-06-02 03:58:56 +00:00
|
|
|
if (user.id == this.u.id) {
|
|
|
|
this.u.isFollowing = user.isFollowing;
|
2018-09-04 09:33:16 +00:00
|
|
|
this.u.hasPendingFollowRequestFromYou = user.hasPendingFollowRequestFromYou;
|
2018-02-15 06:37:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-06-02 03:58:56 +00:00
|
|
|
async onClick() {
|
2018-02-15 06:37:25 +00:00
|
|
|
this.wait = true;
|
2018-06-02 03:58:56 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (this.u.isFollowing) {
|
|
|
|
this.u = await (this as any).api('following/delete', {
|
|
|
|
userId: this.u.id
|
2018-06-01 15:15:17 +00:00
|
|
|
});
|
|
|
|
} else {
|
2018-09-04 09:33:16 +00:00
|
|
|
if (this.u.hasPendingFollowRequestFromYou) {
|
2018-06-02 03:58:56 +00:00
|
|
|
this.u = await (this as any).api('following/requests/cancel', {
|
|
|
|
userId: this.u.id
|
|
|
|
});
|
|
|
|
} else if (this.u.isLocked) {
|
|
|
|
this.u = await (this as any).api('following/create', {
|
|
|
|
userId: this.u.id
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.u = await (this as any).api('following/create', {
|
|
|
|
userId: this.user.id
|
|
|
|
});
|
|
|
|
}
|
2018-06-01 15:15:17 +00:00
|
|
|
}
|
2018-06-02 03:58:56 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
} finally {
|
|
|
|
this.wait = false;
|
2018-02-15 06:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-09-26 11:19:35 +00:00
|
|
|
|
2018-03-03 04:47:55 +00:00
|
|
|
|
2018-02-15 06:37:25 +00:00
|
|
|
.mk-follow-button
|
|
|
|
display block
|
|
|
|
user-select none
|
|
|
|
cursor pointer
|
|
|
|
padding 0 16px
|
|
|
|
margin 0
|
2018-08-22 06:54:22 +00:00
|
|
|
min-width 100px
|
2018-06-01 15:15:17 +00:00
|
|
|
line-height 36px
|
|
|
|
font-size 14px
|
2018-06-03 10:39:02 +00:00
|
|
|
font-weight bold
|
2018-09-26 11:19:35 +00:00
|
|
|
color var(--primary)
|
2018-06-02 03:58:56 +00:00
|
|
|
background transparent
|
2018-02-15 06:37:25 +00:00
|
|
|
outline none
|
2018-09-26 11:19:35 +00:00
|
|
|
border solid 1px var(--primary)
|
2018-06-01 15:15:17 +00:00
|
|
|
border-radius 36px
|
2018-02-15 06:37:25 +00:00
|
|
|
|
2018-06-02 04:11:28 +00:00
|
|
|
&:hover
|
2018-09-26 11:19:35 +00:00
|
|
|
background var(--primaryAlpha01)
|
2018-06-02 04:11:28 +00:00
|
|
|
|
|
|
|
&:active
|
2018-09-26 11:19:35 +00:00
|
|
|
background var(--primaryAlpha02)
|
2018-02-15 06:37:25 +00:00
|
|
|
|
2018-06-02 04:11:28 +00:00
|
|
|
&.active
|
2018-09-26 11:19:35 +00:00
|
|
|
color var(--primaryForeground)
|
|
|
|
background var(--primary)
|
2018-02-15 06:37:25 +00:00
|
|
|
|
|
|
|
&:hover
|
2018-09-26 11:19:35 +00:00
|
|
|
background var(--primaryLighten10)
|
|
|
|
border-color var(--primaryLighten10)
|
2018-02-15 06:37:25 +00:00
|
|
|
|
|
|
|
&:active
|
2018-09-26 11:19:35 +00:00
|
|
|
background var(--primaryDarken10)
|
|
|
|
border-color var(--primaryDarken10)
|
2018-02-15 06:37:25 +00:00
|
|
|
|
|
|
|
&.wait
|
|
|
|
cursor wait !important
|
|
|
|
opacity 0.7
|
|
|
|
|
2018-06-02 04:11:28 +00:00
|
|
|
*
|
|
|
|
pointer-events none
|
2018-02-15 06:37:25 +00:00
|
|
|
|
|
|
|
</style>
|