Started code review + some fixes (unfinished)
[vchess.git] / client / src / views / Variants.vue
1 <template lang="pug">
2 main
3 .row
4 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
5 input#prefixFilter(v-model="curPrefix" :placeholder="st.tr['Prefix?']")
6 .variant.col-sm-12.col-md-5.col-lg-4(
7 v-for="(v,idx) in filteredVariants"
8 :class="{'col-md-offset-1': idx%2==0, 'col-lg-offset-2': idx%2==0}"
9 )
10 router-link(:to="getLink(v.name)")
11 h4.boxtitle.text-center {{ v.name }}
12 p.description.text-center {{ st.tr[v.desc] }}
13 </template>
14
15 <script>
16 import { store } from "@/store";
17 export default {
18 name: "my-variants",
19 data: function() {
20 return {
21 curPrefix: "",
22 st: store.state
23 };
24 },
25 computed: {
26 filteredVariants: function() {
27 const capitalizedPrefix = this.curPrefix.replace(/^\w/, c =>
28 c.toUpperCase()
29 );
30 const variants = this.st.variants
31 .filter(v => {
32 return v.name.startsWith(capitalizedPrefix);
33 })
34 .map(v => {
35 return {
36 name: v.name,
37 desc: v.description
38 };
39 })
40 .sort((a, b) => {
41 return a.name.localeCompare(b.name);
42 });
43 return variants;
44 }
45 },
46 methods: {
47 getLink: function(vname) {
48 return "/variants/" + vname;
49 }
50 }
51 };
52 </script>
53
54 <style lang="sass" scoped>
55 // TODO: box-shadow or box-sizing ? https://stackoverflow.com/a/13517809
56 input#prefixFilter
57 display: block
58 margin: 0 auto
59 .variant
60 box-sizing: border-box
61 border: 1px solid brown
62 background-color: lightyellow
63 &:hover
64 background-color: yellow
65 a
66 color: #663300
67 text-decoration: none
68 .boxtitle
69 font-weight: bold
70 margin-bottom: 0
71 .description
72 @media screen and (max-width: 767px)
73 margin-top: 0
74 </style>