From 9119c86ff94fd29086dfd342a616993f20fc5c75 Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Thu, 30 Apr 2020 20:51:38 -0400 Subject: added a search filter for names and descriptions --- iridescence/src/components/InventoryFilter.vue | 40 ++++++++++++++++++++++++++ iridescence/src/store/index.js | 21 ++++++++++++-- iridescence/src/views/Home.vue | 5 +++- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 iridescence/src/components/InventoryFilter.vue (limited to 'iridescence') diff --git a/iridescence/src/components/InventoryFilter.vue b/iridescence/src/components/InventoryFilter.vue new file mode 100644 index 0000000..365c1e8 --- /dev/null +++ b/iridescence/src/components/InventoryFilter.vue @@ -0,0 +1,40 @@ + + + diff --git a/iridescence/src/store/index.js b/iridescence/src/store/index.js index 4a851ef..eaf9a9f 100644 --- a/iridescence/src/store/index.js +++ b/iridescence/src/store/index.js @@ -78,12 +78,27 @@ export default new Vuex.Store({ imgPath: "/wind-chime.jpg", description: "Makes noise when the wind blows." } - ] + ], + term: "" }, getters: { - inventory: state => state.inventory + inventory(state) { + const term = state.term.toLowerCase(); + + return state.inventory.filter(item => { + // TODO: move into class for items + return ( + item.name.toLowerCase().indexOf(term) != -1 || + item.description.toLowerCase().indexOf(term) != -1 + ); + }); + } + }, + mutations: { + filterTerm(state, term) { + state.term = term; + } }, - mutations: {}, actions: {}, modules: {} }); diff --git a/iridescence/src/views/Home.vue b/iridescence/src/views/Home.vue index 1b071a3..c4a2184 100644 --- a/iridescence/src/views/Home.vue +++ b/iridescence/src/views/Home.vue @@ -4,17 +4,20 @@ cart. -->
+
-- cgit v1.2.3