More timeline stuff

pull/37/head
Varun Patil 2022-08-15 01:15:18 +00:00
parent d04ed4d4c8
commit 42970fa87c
1 changed files with 32 additions and 36 deletions

View File

@ -1,6 +1,5 @@
<template> <template>
<div> <div>
<button @click="genList()">oka.</button><br/>
<RecycleScroller <RecycleScroller
class="scroller" class="scroller"
:items="list" :items="list"
@ -28,6 +27,7 @@ export default {
count: 0, count: 0,
nrows: 0, nrows: 0,
ncols: 5, ncols: 5,
heads: {},
} }
}, },
@ -36,20 +36,18 @@ export default {
}, },
methods: { methods: {
genList() {
this.count++;
this.list[0].name = 'bloop' + this.count;
return;
this.list.splice(50, 0, {
id: this.count,
name: 'bla' + this.count,
size: 64,
head: true,
})
},
scrollChange(startIndex, endIndex) { scrollChange(startIndex, endIndex) {
console.log('scrollChange', startIndex, endIndex); for (let i = startIndex; i <= endIndex; i++) {
let item = this.list[i];
if (!item) {
continue;
}
let head = this.heads[item.dayId];
if (head && !head.loaded) {
this.fetchDay(item.dayId);
}
}
}, },
async fetchDays() { async fetchDays() {
@ -61,13 +59,17 @@ export default {
continue; continue;
} }
this.list.push({ const head = {
id: ++this.nrows, id: ++this.nrows,
name: new Date(Number(day.day_id)*86400*1000).toLocaleDateString( name: new Date(Number(day.day_id)*86400*1000).toLocaleDateString(
"en-US", { dateStyle: 'full', timeZone: 'UTC' }), "en-US", { dateStyle: 'full', timeZone: 'UTC' }),
size: 40, size: 60,
head: true, head: true,
}); loaded: false,
dayId: day.day_id,
};
this.heads[day.day_id] = head;
this.list.push(head);
const nrows = Math.ceil(day.count / this.ncols); const nrows = Math.ceil(day.count / this.ncols);
for (let i = 0; i < nrows; i++) { for (let i = 0; i < nrows; i++) {
@ -75,30 +77,22 @@ export default {
id: ++this.nrows, id: ++this.nrows,
photos: [], photos: [],
size: 100, size: 100,
dayId: day.day_id,
}); });
} }
} }
},
async fetchDay(dayId) {
const head = this.heads[dayId];
head.loaded = true;
return; const res = await fetch(`/apps/betterphotos/api/days/${dayId}`);
// const nrows = Math.ceil(data.length / this.ncols) + 5; const data = await res.json();
this.list.push({ const nrows = Math.ceil(data.length / this.ncols);
id: -1,
size: 64,
head: true,
});
// Add n rows to the list const headIdx = this.list.findIndex(item => item.id === head.id);
for (let i = 0; i < nrows; i++) {
this.list.push({
id: i,
photos: [],
size: 100,
})
}
const headIdx = 0;
let rowIdx = headIdx + 1; let rowIdx = headIdx + 1;
// Add all rows // Add all rows
@ -139,7 +133,7 @@ export default {
<style scoped> <style scoped>
.scroller { .scroller {
height: 300px; height: 100%;
} }
.photo { .photo {
@ -149,9 +143,11 @@ export default {
height: 100px; height: 100px;
width: 100px; width: 100px;
object-fit: cover; object-fit: cover;
padding: 2px;
} }
.head { .head {
height: 40px; height: 60px;
padding-top: 25px;
font-size: 20px; font-size: 20px;
font-weight: lighter; font-weight: lighter;
} }