|
|
|
|
@ -6,24 +6,51 @@ |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
import {api} from "../js/modules/api"; |
|
|
|
|
import $ from 'jquery'; |
|
|
|
|
import ContestWork from "./blocks/ContestWork.vue"; |
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
name: "contest-works", |
|
|
|
|
props: ['contestId'], |
|
|
|
|
props: ['contestId', 'autoload'], |
|
|
|
|
data(){ |
|
|
|
|
return { |
|
|
|
|
page: 1, |
|
|
|
|
lastPage: null, |
|
|
|
|
loading: false, |
|
|
|
|
contestWorks: [], |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
mounted() { |
|
|
|
|
this.load(); |
|
|
|
|
if(this.autoload) { |
|
|
|
|
$(window).scroll(() => { |
|
|
|
|
const pos = $(this.$el).offset().top + this.$el.clientHeight - 100; |
|
|
|
|
if($(window).scrollTop() + $(window).height() >= pos |
|
|
|
|
&& !this.loading && !this.lastPage) { |
|
|
|
|
this.page += 1; |
|
|
|
|
this.load(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
load() { |
|
|
|
|
api.get(`/api/v1/contest-works/?contest=${this.contestId}`) |
|
|
|
|
this.loading = true; |
|
|
|
|
api.get(`/api/v1/contest-works/?contest=${this.contestId}&page=${this.page}`) |
|
|
|
|
.then((response) => { |
|
|
|
|
this.contestWorks = response.data.results; |
|
|
|
|
this.loading = false; |
|
|
|
|
if(this.page > 1){ |
|
|
|
|
this.contestWorks.concat(response.data.results); |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
this.contestWorks = response.data.results; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.catch((response) => { |
|
|
|
|
this.loading = false; |
|
|
|
|
if(response.response.status == 404){ |
|
|
|
|
this.lastPage = this.page; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|