LiveAtlas/src/components/sidebar/FollowTarget.vue

128 lines
3.3 KiB
Vue
Raw Normal View History

2020-12-16 16:54:41 +00:00
<!--
- Copyright 2020 James Lyne
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->
2020-12-01 23:20:38 +00:00
<template>
<section class="sidebar__section following">
2021-05-20 15:39:41 +00:00
<h2>{{ heading }}</h2>
2020-12-01 23:20:38 +00:00
<div :class="{'following__target': true, 'following__target--hidden': target.hidden}">
2020-12-31 13:55:05 +00:00
<img width="32" height="32" class="target__icon" :src="image" alt="" />
<span class="target__info">
<span class="target__name" v-html="target.displayName"></span>
2021-05-20 15:39:41 +00:00
<span class="target__status" v-show="target.hidden">{{ messageHidden }}</span>
</span>
2021-05-20 15:39:41 +00:00
<button class="target__unfollow" type="button" :title="messageUnfollowTitle"
@click.prevent="unfollow">{{ messageUnfollow }}</button>
2020-12-01 23:20:38 +00:00
</div>
</section>
</template>
<script lang="ts">
import {useStore} from "@/store";
import {MutationTypes} from "@/store/mutation-types";
2021-05-20 15:39:41 +00:00
import {computed, defineComponent, onMounted, ref, watch} from "@vue/runtime-core";
2021-01-26 20:37:29 +00:00
import {getMinecraftHead} from '@/util';
2021-05-15 19:25:03 +00:00
import defaultImage from '@/assets/images/player_face.png';
import {LiveAtlasPlayer} from "@/index";
2020-12-14 00:51:51 +00:00
2020-12-01 23:20:38 +00:00
export default defineComponent({
name: 'FollowTarget',
props: {
target: {
type: Object as () => LiveAtlasPlayer,
2020-12-01 23:20:38 +00:00
required: true
}
},
2020-12-31 13:55:05 +00:00
setup(props) {
const store = useStore(),
image = ref(defaultImage),
account = ref(props.target.name),
2020-12-31 13:55:05 +00:00
2021-05-20 15:39:41 +00:00
heading = computed(() => store.state.messages.followingHeading),
messageUnfollow = computed(() => store.state.messages.followingUnfollow),
messageUnfollowTitle = computed(() => store.state.messages.followingTitleUnfollow),
messageHidden = computed(() => store.state.messages.followingHidden),
2020-12-31 13:55:05 +00:00
unfollow = () => {
useStore().commit(MutationTypes.CLEAR_FOLLOW_TARGET, undefined);
},
2021-05-18 17:24:35 +00:00
updatePlayerImage = async () => {
2020-12-31 13:55:05 +00:00
image.value = defaultImage;
if(store.state.components.playerMarkers && store.state.components.playerMarkers.showSkinFaces) {
2021-05-18 17:24:35 +00:00
try {
const result = await getMinecraftHead(props.target, '16');
image.value = result.src;
} catch (e) {}
2020-12-31 13:55:05 +00:00
}
};
watch(account, () => updatePlayerImage());
onMounted(() => updatePlayerImage());
2020-12-14 00:51:51 +00:00
return {
2020-12-31 13:55:05 +00:00
image,
2021-05-20 15:39:41 +00:00
unfollow,
heading,
messageUnfollow,
messageUnfollowTitle,
messageHidden,
2020-12-14 00:51:51 +00:00
}
},
2020-12-01 23:20:38 +00:00
});
</script>
<style lang="scss" scoped>
.sidebar__section.following {
margin-top: auto;
min-height: 0;
flex: 0 0 auto;
.following__target {
display: flex;
align-items: center;
.target__unfollow {
position: absolute;
top: 2rem;
right: 1.5rem;
}
.target__info {
2020-12-01 23:20:38 +00:00
margin-left: 2rem;
display: flex;
flex-direction: column;
justify-content: flex-start;
.target__status {
font-size: 1.3rem;
}
}
&.following__target--hidden {
.target__icon {
filter: grayscale(1);
opacity: 0.5;
}
2020-12-01 23:20:38 +00:00
}
}
@media (max-width: 480px), (max-height: 480px) {
margin-top: 0;
}
2020-12-01 23:20:38 +00:00
}
</style>