<template>
  <router-view v-if="resourcesReady && project" :project="project"></router-view>
  <loading-page v-else></loading-page>
</template>

<script>
  import { mapGetters } from 'vuex'

  import ResourcesLoader from 'src/components/mixins/ResourcesLoader'

  export default {
    props: {
      projectSlug: { type: String, required: true },
    },

    mixins: [ResourcesLoader],

    computed: {
      ...mapGetters({
        project: 'projects/current',
      }),
    },

    watch: {
      projectSlug: function (projectSlug) {
        this.$store.commit('projects/setCurrent', projectSlug)
      },
    },

    mounted () {
      this.$store.commit('projects/setCurrent', this.projectSlug)
    },

    destroyed () {
      this.$store.commit('projects/setCurrent', null)
    },
  }
</script>

<template>
  <router-view v-if="resourcesReady && project" :project="project"></router-view>
  <not-found-page v-else-if="resourcesReady && !project"></not-found-page>
  <loading-page v-else></loading-page>
</template>

<script>
  import { mapGetters } from 'vuex'

  import ResourcesLoader from 'src/components/mixins/ResourcesLoader'

  import NotFoundPage from 'src/components/general/NotFoundPage'

  export default {
    props: {
      projectSlug: { type: String, required: true },
    },

    mixins: [ResourcesLoader],

    components: {
      NotFoundPage,
    },

    computed: {
      ...mapGetters({
        project: 'projects/current',
      }),
    },

    watch: {
      projectSlug: function (projectSlug) {
        this.$store.commit('projects/setCurrent', projectSlug)
      },

      resourcesReady: function (ready) {
        if (ready) {
          this.$store.commit('projects/setCurrent', this.projectSlug)
        }
      },
    },

    mounted () {
      this.$store.commit('projects/setCurrent', this.projectSlug)
    },

    destroyed () {
      this.$store.commit('projects/setCurrent', null)
    },
  }
</script>

Fix accessing project URL directly
fix: Fix accessing project URL directly

We were setting current project based on its slug on
`ProjectContainer.mounted` method. But resources (and so, projects) are
not in store yet. To fix that, we need to set current project once
resources are loaded.

We still need to set current project on `mounted` because resources can
already be loaded.

Also, user can try to access a project that doesn't exist and so we need
to show a "not found" page in this case.
