summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository/mixins/preload.js
blob: a2ddcbf0e4c875fc125763da5bcbd3559bf608ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import filesQuery from 'shared_queries/repository/files.query.graphql';
import paginatedTreeQuery from 'shared_queries/repository/paginated_tree.query.graphql';
import projectPathQuery from '../queries/project_path.query.graphql';
import getRefMixin from './get_ref';

export default {
  mixins: [getRefMixin],
  apollo: {
    projectPath: {
      query: projectPathQuery,
    },
  },
  data() {
    return { projectPath: '', loadingPath: null };
  },
  beforeRouteUpdate(to, from, next) {
    this.preload(to.params.path, next);
  },
  methods: {
    preload(path = '/', next) {
      this.loadingPath = path.replace(/^\//, '');

      return this.$apollo
        .query({
          query: gon.features.paginatedTreeGraphqlQuery ? paginatedTreeQuery : filesQuery,
          variables: {
            projectPath: this.projectPath,
            ref: this.ref,
            path: this.loadingPath,
            nextPageCursor: '',
            pageSize: 100,
          },
        })
        .then(() => next());
    },
  },
};