<template>
  <div class="portfolio__page">
    <div class="portfolio">
      <add-project class="portfolio__add-project"/>

      <project-widget
        v-bind="project"
        :user-id="userId"
        :key="project.id"
        class="portfolio__project"
        v-for="project in projects"
      />
    </div>
  </div>
</template>

<script>
  import ProjectWidget from '@/components/portfolio/ProjectWidget';
  import AddProject from '@/components/portfolio/AddProject';

  import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';
  import PROJECTS_QUERY from '@/graphql/gql/queries/allProjects.gql';

  export default {
    components: {
      ProjectWidget,
      AddProject
    },

    apollo: {
      projects: {
        query: PROJECTS_QUERY,
        update(data) {
          return this.$getRidOfEdges(data).projects;
        },
        pollInterval: 5000,
      },
      me: {
        query: ME_QUERY
      }
    },

    data() {
      return {
        projects: [],
        me: {}
      };
    },

    computed: {
      userId() {
        return this.me.id;
      }
    },
  };
</script>

<style scoped lang="scss">
  @import "@/styles/_variables.scss";

  .portfolio {
    display: flex;
    flex-direction: column;
    @supports (display: grid) {
      display: grid;
      grid-template-columns: minmax(min-content, 840px);
    }
    grid-row-gap: 30px;
    grid-auto-rows: 225px;
    max-width: 840px;
    width: 100vw;
    /*justify-self: center;*/
    box-sizing: border-box;
    padding: $large-spacing $medium-spacing;

    &__page {
      display: flex;
      flex-direction: column;
      @supports (display: grid) {
        display: grid;
        align-content: start;
        justify-content: center;
      }
      align-items: center;

      padding-top: $large-spacing;
    }

    /*IE10*/
    &__add-project {
      margin-bottom: $large-spacing;
      @supports (display: grid) {
        margin-bottom: 0;
      }
    }
  }
</style>
