Skip to content
Snippets Groups Projects
FridgeView.vue 3.38 KiB
Newer Older
<template><h1>Kjøleskap</h1><br><br>
        <ItemSearch v-if="searchVisible" @itemsAdded="updateFridge"></ItemSearch>

        <div id = "fridgeMsg"><p>Melding fra kjøleskapet:</p><span>{{this.fridgeMsg}}</span></div>
        <eat-fridge-item-modal @closeModal="hideModal" v-if="visible" :fridge-item="selectedItem"></eat-fridge-item-modal>
        <div id = "itemContainer" >
            <FridgeItem v-for="item in fridgeItems" :fridgeItem = "item"  @appleBtnPressed="showModal"></FridgeItem>
Ingrid's avatar
Ingrid committed
        <div id="addItemBtn-container">
          <button @click="showItemSearch" id="addItemBtn">
Ingrid's avatar
Ingrid committed
            <span class="plus">+</span>
          </button>
        </div>
    </main>
</template>

<script>
import FridgeItem from "@/components/FridgeItem.vue";
Ingrid's avatar
Ingrid committed
import EatFridgeItemModal from "@/components/EatFridgeItemModal.vue";
Ingrid's avatar
Ingrid committed
import {API} from "@/util/API";
import {mapState, mapStores} from "pinia";
import {useAuthStore} from "@/stores/authStore";
import {useFridgeStore} from "@/stores/fridgeStore";
import ItemSearch from "@/components/ItemSearch.vue";
import fridgeItem from "@/components/FridgeItem.vue";

export default {
    name: "FridgeView",
    components: {ItemSearch, EatFridgeItemModal, FridgeItem},
    computed:{
      ...mapState(useAuthStore, ['account']),
      ...mapStores(useFridgeStore),
    },
Ingrid's avatar
Ingrid committed
  data() {
      return {
          visible: false, //is the useitemModal visible
          selectedItem: null,
          fridgeItems: [],
          searchVisible: false,
Ingrid's avatar
Ingrid committed
      }
  },
  methods: {
      showModal(item){
        this.visible = true;
        this.selectedItem = item;
Ingrid's avatar
Ingrid committed
      },
Ingrid's avatar
Ingrid committed
        this.visible=false;
        },
      showItemSearch() {
        this.searchVisible=!this.searchVisible;
        window.scrollTo({ top: 0, behavior: 'smooth' });
      },
      hideItemSearch() {
          this.searchVisible=false;
      },
      updateFridgeMessage(msg){
          this.fridgeMsg=msg;
      },
      async updateFridge(addedItem) {
          this.fridgeItems = await API.getFridgeItems();
          this.fridgeItems = await API.getFridgeItems();
          this.hideItemSearch();
          this.updateFridgeMessage(addedItem.name + " ble lagt i kjøleskapet.")
Ingrid's avatar
Ingrid committed
  },
  async mounted() {
      this.fridgeItems = await API.getFridgeItems();
      if(this.fridgeItems.length===0){
          this.fridgeMsg="Kjøleskapet ditt er tomt. Legg inn varer ved å trykke på pluss-knappen nederst i høyre hjørne"
      }
}
</script>

<style scoped lang="scss">
main {
    color:black;
    background-color: base.$grey;
    padding: 2em;
    min-height: 600px;
Ingrid Martinsheimen Egge's avatar
Ingrid Martinsheimen Egge committed
h1 {
  width:100%;
  padding-left: 1em;
Ingrid Martinsheimen Egge's avatar
Ingrid Martinsheimen Egge committed
  font-weight: bold;
}

Ingrid's avatar
Ingrid committed
#itemContainer {
    background-color: base.$grey;
    padding-bottom: 5em;
Ingrid's avatar
Ingrid committed

#addItemBtn {
  width: 2.5em;
  height: 2.5em;
  border-radius: 50%;
  font-size: 30px;
  border:none;
  background-color: base.$light-green;
Ingrid's avatar
Ingrid committed
  color: white;
  box-shadow: 0px 0px 20px rgba(0,0,0,0.3);
}

#addItemBtn:hover {
  background-color: base.$light-green-hover;
  color: white;
  box-shadow: 0px 0px 20px rgba(0,0,0,0.5);
  cursor: pointer;
}
Ingrid Martinsheimen Egge's avatar
Ingrid Martinsheimen Egge committed

#addItemBtn-container {
Ingrid Martinsheimen Egge's avatar
Ingrid Martinsheimen Egge committed
  z-index: 9999;
  position: fixed;
  bottom: 15px;
  right: 1em;
Ingrid's avatar
Ingrid committed
}

#fridgeMsg {
  background-color: base.$light-green;
  padding: 1em;
}

#fridgeMsg span, #fridgeMsg p{

  font-weight: bolder;
  font-size: 1.2em;
}