2020-12-16 16:54:41 +00:00
|
|
|
<!--
|
2021-07-25 14:12:40 +00:00
|
|
|
- Copyright 2021 James Lyne
|
2020-12-16 16:54:41 +00:00
|
|
|
-
|
2021-07-25 14:12:40 +00:00
|
|
|
- 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
|
2020-12-16 16:54:41 +00:00
|
|
|
-
|
2021-07-25 14:12:40 +00:00
|
|
|
- http://www.apache.org/licenses/LICENSE-2.0
|
2020-12-16 16:54:41 +00:00
|
|
|
-
|
2021-07-25 14:12:40 +00:00
|
|
|
- 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-16 16:54:41 +00:00
|
|
|
-->
|
|
|
|
|
2020-11-20 21:44:02 +00:00
|
|
|
<template>
|
2021-07-21 15:19:18 +00:00
|
|
|
<CollapsibleSection name="players" class="players">
|
2021-07-28 21:27:43 +00:00
|
|
|
<template v-slot:heading>{{ messageHeading }}</template>
|
2021-05-25 18:26:14 +00:00
|
|
|
<template v-slot:default>
|
2021-07-21 15:19:18 +00:00
|
|
|
<div class="section__content">
|
|
|
|
<input v-if="players && searchEnabled" id="players__search" type="text" name="search"
|
|
|
|
v-model="searchQuery" :placeholder="messagePlayersSearchPlaceholder" @keydown="onKeydown">
|
|
|
|
<RadioList v-if="filteredPlayers.length" aria-labelledby="players-heading">
|
2021-07-24 03:09:33 +00:00
|
|
|
<PlayerListItem v-for="player in filteredPlayers" :key="player.name"
|
2021-07-21 15:19:18 +00:00
|
|
|
:player="player"></PlayerListItem>
|
|
|
|
</RadioList>
|
|
|
|
<div v-else-if="searchQuery" class="section__skeleton">{{ messageSkeletonPlayersSearch }}</div>
|
|
|
|
<div v-else class="section__skeleton">{{ messageSkeletonPlayers }}</div>
|
|
|
|
</div>
|
2021-05-25 18:26:14 +00:00
|
|
|
</template>
|
|
|
|
</CollapsibleSection>
|
2020-11-20 21:44:02 +00:00
|
|
|
</template>
|
|
|
|
|
2020-11-23 12:13:28 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import PlayerListItem from "./PlayerListItem.vue";
|
2021-07-21 15:19:18 +00:00
|
|
|
import {computed, defineComponent} from "@vue/runtime-core";
|
2020-11-23 12:13:28 +00:00
|
|
|
import {useStore} from "@/store";
|
2021-05-25 18:26:14 +00:00
|
|
|
import CollapsibleSection from "@/components/sidebar/CollapsibleSection.vue";
|
2021-05-27 23:13:46 +00:00
|
|
|
import RadioList from "@/components/util/RadioList.vue";
|
2021-07-21 15:19:18 +00:00
|
|
|
import {ref} from "vue";
|
2020-11-23 12:13:28 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
2021-05-27 23:13:46 +00:00
|
|
|
RadioList,
|
2021-05-25 18:26:14 +00:00
|
|
|
CollapsibleSection,
|
2020-11-23 12:13:28 +00:00
|
|
|
PlayerListItem
|
|
|
|
},
|
|
|
|
|
2021-07-21 15:19:18 +00:00
|
|
|
setup() {
|
|
|
|
const store = useStore(),
|
2021-07-28 21:27:43 +00:00
|
|
|
messageHeading = computed(() => {
|
|
|
|
return store.state.messages.playersHeading
|
2021-07-29 02:39:28 +00:00
|
|
|
.replace('{cur}', players.value.length.toString())
|
|
|
|
.replace('{max}', maxPlayers.value.toString());
|
2021-07-28 21:27:43 +00:00
|
|
|
}),
|
2021-07-21 15:19:18 +00:00
|
|
|
messageSkeletonPlayers = computed(() => store.state.messages.playersSkeleton),
|
|
|
|
messageSkeletonPlayersSearch = computed(() => store.state.messages.playersSearchSkeleton),
|
|
|
|
messagePlayersSearchPlaceholder = computed(() => store.state.messages.playersSearchPlaceholder),
|
2021-05-20 15:39:41 +00:00
|
|
|
|
2021-07-21 15:19:18 +00:00
|
|
|
searchEnabled = computed(() => store.state.ui.playersSearch),
|
|
|
|
searchQuery = ref(""),
|
2020-12-11 23:01:42 +00:00
|
|
|
|
2021-07-21 15:19:18 +00:00
|
|
|
players = computed(() => store.state.sortedPlayers),
|
|
|
|
filteredPlayers = computed(() => {
|
|
|
|
const query = searchQuery.value.toLowerCase();
|
2020-11-23 12:13:28 +00:00
|
|
|
|
2021-07-21 15:19:18 +00:00
|
|
|
return query ? store.state.sortedPlayers.filter(p => {
|
2021-07-24 01:27:25 +00:00
|
|
|
return p.name.toLowerCase().indexOf(query) > -1;
|
2021-07-21 15:19:18 +00:00
|
|
|
}) : store.state.sortedPlayers;
|
|
|
|
}),
|
2021-07-28 22:50:59 +00:00
|
|
|
maxPlayers = computed(() => store.state.maxPlayers || 0),
|
2021-07-21 15:19:18 +00:00
|
|
|
|
|
|
|
onKeydown = (e: KeyboardEvent) => {
|
|
|
|
e.stopImmediatePropagation();
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
messageHeading,
|
|
|
|
messageSkeletonPlayers,
|
|
|
|
messageSkeletonPlayersSearch,
|
|
|
|
messagePlayersSearchPlaceholder,
|
|
|
|
|
|
|
|
searchEnabled,
|
|
|
|
searchQuery,
|
|
|
|
|
|
|
|
players,
|
|
|
|
filteredPlayers,
|
|
|
|
maxPlayers,
|
|
|
|
onKeydown
|
2020-11-23 12:13:28 +00:00
|
|
|
}
|
2021-05-25 18:26:14 +00:00
|
|
|
}
|
2020-11-23 12:13:28 +00:00
|
|
|
});
|
2020-11-20 21:44:02 +00:00
|
|
|
</script>
|
2021-07-21 15:19:18 +00:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.players {
|
|
|
|
#players__search {
|
|
|
|
margin-bottom: 1.5rem;
|
|
|
|
padding: 0.5rem 1rem;
|
|
|
|
box-sizing: border-box;
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
& + .section__skeleton {
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|