Explorar o código

Sort category names, keeping 'All' as first

sbkwgh %!s(int64=8) %!d(string=hai) anos
pai
achega
ec28561e2b
Modificáronse 2 ficheiros con 15 adicións e 1 borrados
  1. 2 1
      src/components/routes/Index.vue
  2. 13 0
      src/store/index.js

+ 2 - 1
src/components/routes/Index.vue

@@ -94,7 +94,8 @@
 				});
 			},
 			categories () {
-				return this.$store.state.meta.categories
+				console.log(this.$store.getters.alphabetizedCategories)
+				return this.$store.getters.alphabetizedCategories
 			},
 			selectedCategory: {
 				set (val) {

+ 13 - 0
src/store/index.js

@@ -33,6 +33,19 @@ export default new Vuex.Store({
 			})
 
 			return categories.filter(category => category.value !== 'ALL' )
+		},
+		alphabetizedCategories (state) {
+			return state.meta.categories.sort((a, b) => {
+				if(a.name === 'All') return -1
+
+				if(a.name < b.name) {
+					return -1
+				} else if (a.name > b.name) {
+					return 1
+				}
+
+				return 0
+			})
 		}
 	},
 	mutations: {