interface: lazier notifications loading

This commit is contained in:
Liam Fitzgerald 2020-11-12 10:26:53 +10:00
parent fa9a7dc0f0
commit 0b7201ac08
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
2 changed files with 21 additions and 3 deletions

View File

@ -149,10 +149,21 @@ export class HarkApi extends BaseApi<StoreState> {
});
}
getMore() {
const offset = this.store.state.notifications.size;
const count = 10;
return this.getSubset(offset,count);
}
async getSubset(offset:number, count:number) {
const data = await this.scry("hark-store", `/recent/${offset}/${count}`);
this.store.handleEvent({ data });
}
async getTimeSubset(start?: Date, end?: Date) {
const s = start ? dateToDa(start) : "-";
const e = end ? dateToDa(end) : "-";
const result = await this.scry("hark-hook", `/time-subset/${s}/${e}`);
const result = await this.scry("hark-hook", `/recent/${s}/${e}`);
this.store.handleEvent({
data: result,
});

View File

@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React, { useEffect, useCallback } from "react";
import f from "lodash/fp";
import _ from "lodash";
import { Icon, Col, Row, Box, Text, Anchor } from "@tlon/indigo-react";
@ -67,8 +67,15 @@ export default function Inbox(props: {
f.values
)(notifications);
const onScroll = useCallback((e) => {
let container = e.target;
if(container.scrollHeight - container.scrollTop === container.clientHeight) {
api.hark.getMore();
}
}, [api]);
return (
<Col overflowY="auto" flexGrow="1">
<Col onScroll={onScroll} overflowY="auto" flexGrow="1">
{newNotifications && (
<DaySection
latest