Browse Source

feat: filter menu by category

bregsiaju 1 year ago
parent
commit
6bfbb62d9f
3 changed files with 60 additions and 16 deletions
  1. 1
    0
      src/components/OrderList.vue
  2. 12
    5
      src/stores/menus.js
  3. 47
    11
      src/views/HomeView.vue

+ 1
- 0
src/components/OrderList.vue View File

170
     box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.25);
170
     box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.25);
171
     padding: 10px 0;
171
     padding: 10px 0;
172
     border: 1px solid transparent;
172
     border: 1px solid transparent;
173
+    cursor: pointer;
173
 
174
 
174
     &.selected {
175
     &.selected {
175
       color: white;
176
       color: white;

+ 12
- 5
src/stores/menus.js View File

6
     loading: false,
6
     loading: false,
7
     error: null
7
     error: null
8
   }),
8
   }),
9
-  getters: {
10
-    getMenuPerCategory: (state) => {
11
-      return (categoryName) => state.menus.filter((item) => item.category === categoryName)
12
-    }
13
-  },
14
   actions: {
9
   actions: {
15
     async fetchMenus() {
10
     async fetchMenus() {
16
       this.menus = []
11
       this.menus = []
22
       } finally {
17
       } finally {
23
         this.loading = false
18
         this.loading = false
24
       }
19
       }
20
+    },
21
+    async getMenuPerCategory(categoryName) {
22
+      await this.fetchMenus()
23
+      console.log('nama kategori ' + categoryName)
24
+
25
+      if (categoryName !== 'all') {
26
+        const filteredCategory = this.menus.filter((item) => item.category === categoryName)
27
+        console.log(filteredCategory)
28
+        this.menus = filteredCategory
29
+      } else {
30
+        await this.fetchMenus()
31
+      }
25
     }
32
     }
26
   }
33
   }
27
 })
34
 })

+ 47
- 11
src/views/HomeView.vue View File

5
         <div class="category">
5
         <div class="category">
6
           <h5 class="mb-3">Categories</h5>
6
           <h5 class="mb-3">Categories</h5>
7
           <div class="d-flex gap-3 category-list">
7
           <div class="d-flex gap-3 category-list">
8
-            <button v-for="item in categories" :key="item.id" class="btn btn-outline-dark"
9
-              :class="{ active: selectedCategories === item.id }" v-html="item.name"
10
-              @click="selectedCategories = item.id"></button>
8
+            <button v-for="category in categories" :key="category.id" class="btn btn-outline-dark"
9
+              :class="{ active: selectedCategories === category.id }" v-html="category.title"
10
+              @click="selectCategory(category)"></button>
11
           </div>
11
           </div>
12
         </div>
12
         </div>
13
         <MenuContainer />
13
         <MenuContainer />
20
 </template>
20
 </template>
21
 
21
 
22
 <script>
22
 <script>
23
+import { ref } from 'vue';
23
 import MenuContainer from '../components/MenuContainer.vue';
24
 import MenuContainer from '../components/MenuContainer.vue';
24
 import OrderList from '../components/OrderList.vue';
25
 import OrderList from '../components/OrderList.vue';
26
+import { useMenuStore } from '../stores/menus';
25
 
27
 
26
 export default {
28
 export default {
27
   components: {
29
   components: {
33
       categories: [
35
       categories: [
34
         {
36
         {
35
           id: 1,
37
           id: 1,
36
-          name: '&#129368; All Menu'
38
+          value: 'all',
39
+          title: '&#129368; All Menu'
37
         },
40
         },
38
         {
41
         {
39
           id: 2,
42
           id: 2,
40
-          name: '&#9749; Coffee'
43
+          value: 'coffee',
44
+          title: '&#9749; Coffee'
41
         },
45
         },
42
         {
46
         {
43
           id: 3,
47
           id: 3,
44
-          name: '&#127851; Chocolate'
48
+          value: 'tea',
49
+          title: '&#129483; Tea'
45
         },
50
         },
46
         {
51
         {
47
           id: 4,
52
           id: 4,
48
-          name: '&#127839; Snacks'
53
+          value: 'chocolate',
54
+          title: '&#127851; Chocolate'
49
         },
55
         },
50
         {
56
         {
51
           id: 5,
57
           id: 5,
52
-          name: '&#127848; Ice Cream'
58
+          value: 'snacks',
59
+          title: '&#127839; Snacks'
53
         },
60
         },
54
-      ],
55
-      selectedCategories: 1
61
+        {
62
+          id: 6,
63
+          value: 'ice cream',
64
+          title: '&#127848; Ice Cream'
65
+        },
66
+      ]
56
     }
67
     }
57
   }
68
   }
58
 }
69
 }
59
 </script>
70
 </script>
60
 
71
 
72
+<script setup>
73
+const { getMenuPerCategory } = useMenuStore()
74
+
75
+let selectedCategories = ref(1)
76
+
77
+const selectCategory = (category) => {
78
+  selectedCategories.value = category.id;
79
+  getMenuPerCategory(category.value)
80
+}
81
+</script>
82
+
61
 <style lang="scss" scoped>
83
 <style lang="scss" scoped>
62
 .menu {
84
 .menu {
63
   padding: 28px 8px 0 32px;
85
   padding: 28px 8px 0 32px;
75
 }
97
 }
76
 
98
 
77
 .category {
99
 .category {
78
-  margin-bottom: 30px;
100
+  margin-bottom: 20px;
79
 
101
 
80
   .category-list {
102
   .category-list {
103
+    overflow-x: auto;
104
+    padding-bottom: 10px;
105
+
106
+    &::-webkit-scrollbar {
107
+      height: 5px;
108
+      // background-color: #f5f5f5;
109
+    }
110
+
111
+    &::-webkit-scrollbar-thumb {
112
+      border-radius: 10px;
113
+      background-color: transparent;
114
+    }
115
+
81
     .btn {
116
     .btn {
82
       border-radius: 50px;
117
       border-radius: 50px;
83
       padding: 8px 16px;
118
       padding: 8px 16px;
84
       border-color: #5C5470;
119
       border-color: #5C5470;
85
       color: #5C5470;
120
       color: #5C5470;
86
       font-size: 14px;
121
       font-size: 14px;
122
+      white-space: nowrap;
87
 
123
 
88
       &:hover {
124
       &:hover {
89
         background: linear-gradient(232deg, rgba(185, 138, 238, 0.80) 0%, rgba(251, 190, 222, 0.80) 100%);
125
         background: linear-gradient(232deg, rgba(185, 138, 238, 0.80) 0%, rgba(251, 190, 222, 0.80) 100%);

Loading…
Cancel
Save