interface: add concrete instances of VirtualScroller

This commit is contained in:
Liam Fitzgerald 2021-06-16 15:35:36 +10:00
parent 3d6ec8440f
commit e473f5af9c
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
2 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,27 @@
import { GraphNode } from '@urbit/api';
import bigInt, { BigInteger } from 'big-integer';
import React from 'react';
import VirtualScroller, { VirtualScrollerProps } from './VirtualScroller';
type GraphScrollerProps = Omit<
VirtualScrollerProps<BigInteger, GraphNode>,
'keyEq' | 'keyToString' | 'keyBunt'
>;
const keyEq = (a: BigInteger, b: BigInteger) => a.eq(b);
const keyToString = (a: BigInteger) => a.toString();
export const GraphScroller = React.forwardRef<
VirtualScroller<BigInteger, GraphNode>,
GraphScrollerProps
>((props, ref) => {
return (
<VirtualScroller
ref={ref}
{...props}
keyEq={keyEq}
keyToString={keyToString}
keyBunt={bigInt.zero}
/>
);
});

View File

@ -0,0 +1,48 @@
import { BigInteger } from 'big-integer';
import React from 'react';
import VirtualScroller, { VirtualScrollerProps } from './VirtualScroller';
import { arrToString } from '@urbit/api/lib/BigIntArrayOrderedMap';
import { FlatGraphNode } from '@urbit/api';
type ThreadScrollerProps = Omit<
VirtualScrollerProps<BigInteger[], FlatGraphNode>,
'keyEq' | 'keyToString' | 'keyBunt'
>;
export function keyEq(a: BigInteger[], b: BigInteger[]) {
const aLen = a.length;
const bLen = b.length;
if (aLen === bLen) {
let i = 0;
while (i < aLen && i < bLen) {
if (a[i].eq(b[i])) {
if (i === aLen - 1) {
return true;
}
i++;
} else {
return false;
}
}
}
return false;
}
const keyBunt = [];
export const ThreadScroller = React.forwardRef<
VirtualScroller<BigInteger[], FlatGraphNode>,
ThreadScrollerProps
>((props: ThreadScrollerProps, ref) => {
return (
<VirtualScroller<BigInteger[], FlatGraphNode>
ref={ref}
{...props}
keyEq={keyEq}
keyToString={arrToString}
keyBunt={keyBunt}
/>
);
});