mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-02 15:13:25 +03:00
interface: add concrete instances of VirtualScroller
This commit is contained in:
parent
3d6ec8440f
commit
e473f5af9c
27
pkg/interface/src/views/components/GraphScroller.tsx
Normal file
27
pkg/interface/src/views/components/GraphScroller.tsx
Normal 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}
|
||||
/>
|
||||
);
|
||||
});
|
48
pkg/interface/src/views/components/ThreadScroller.tsx
Normal file
48
pkg/interface/src/views/components/ThreadScroller.tsx
Normal 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}
|
||||
/>
|
||||
);
|
||||
});
|
Loading…
Reference in New Issue
Block a user