Skip to content

Commit

Permalink
feat: build group
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuever committed Dec 23, 2024
1 parent 714984f commit 2185442
Show file tree
Hide file tree
Showing 25 changed files with 69 additions and 41 deletions.
37 changes: 37 additions & 0 deletions core/utils/src/exportedUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export type ItemPossibleT<T> =
| T
| {
key: string;
}
| {
id: string;
};

export type ExtractKeyItem<T> = Extract<
T,
{
key: string;
}
>;

export type ExtractIdItem<T> = Extract<
T,
{
id: string;
}
>;

const isPresent = (v: any) => typeof v !== 'undefined';

export const defaultKeyExtractor = <T>(
item: ItemPossibleT<T>,
index: number
) => {
if (isPresent((item as ExtractKeyItem<ItemPossibleT<T>>).key)) {
return String((item as ExtractKeyItem<ItemPossibleT<T>>).key);
}
if (isPresent((item as ExtractIdItem<ItemPossibleT<T>>).id)) {
return String((item as ExtractIdItem<ItemPossibleT<T>>).id);
}
return `default_index_key_${index}`;
};
1 change: 1 addition & 0 deletions core/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { default as ListSpy } from './ListSpy';
export { default as ListSpyUtils } from './ListSpyUtils';
export { default as log } from './logger';
export { default as StillnessHelper } from './StillnessHelper';
export * from './exportedUtils';
1 change: 0 additions & 1 deletion ui/group/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
}
},
"dependencies": {
"@infinite-list/data-model": "workspace:*",
"@infinite-list/scroller": "workspace:*",
"@x-oasis/noop": "^0.1.14",
"@x-oasis/shallow-equal": "^0.1.14"
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react-native/GroupList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PropsWithChildren, useContext, useRef, FC } from 'react';
import React, { PropsWithChildren, useContext, useRef } from 'react';

import { DefaultItemT, GroupListProps } from '../types';
import context from './context';
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react-native/ListGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ListGroupDimensions } from '@infinite-list/data-model';
import { ListGroupDimensions } from '@infinite-list/group-dimensions';
import React, {
FC,
useCallback,
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react-native/PortalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, {
useState,
PropsWithChildren,
} from 'react';
import { RecycleStateResult } from '@infinite-list/data-model';
import { RecycleStateResult } from '@infinite-list/strategies';
import {
PortalContextProps,
GroupRecycleContentProps,
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react-native/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ListGroupDimensions } from '@infinite-list/data-model';
import { ListGroupDimensions } from '@infinite-list/group-dimensions';
import { createContext } from 'react';
import noop from '@x-oasis/noop';

Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react-native/hooks/useMountItem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useContext, useEffect, useMemo, useRef } from 'react';
import context from '../context';
import { Dimension } from '@infinite-list/data-model';
import { Dimension } from '@infinite-list/dimension';

// @ts-ignore
export default (props) => {
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react-native/hooks/useMountList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultKeyExtractor } from '@infinite-list/data-model';
import { defaultKeyExtractor } from '@infinite-list/utils';
import { useContext, useEffect, useRef } from 'react';
import context from '../context';

Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react/GroupListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext, useRef } from 'react';
import { GenericItemT } from '@infinite-list/data-model';
import { GenericItemT } from '@infinite-list/types';
import context from './context';
import useMountItem from './hooks/useMountItem';
import { genericMemo, GroupListItemImplProps } from './types';
Expand Down
3 changes: 2 additions & 1 deletion ui/group/src/react/ListGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GenericItemT, ListGroupDimensions } from '@infinite-list/data-model';
import { ListGroupDimensions } from '@infinite-list/group-dimensions';
import { GenericItemT } from '@infinite-list/item-meta';
import React, {
CSSProperties,
FC,
Expand Down
1 change: 0 additions & 1 deletion ui/group/src/react/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import shallowEqual from '@x-oasis/shallow-equal';
import React, {
ForwardedRef,
PropsWithChildren,
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react/PortalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, {
PropsWithChildren,
CSSProperties,
} from 'react';
import { GenericItemT, RecycleStateResult } from '@infinite-list/data-model';
import { GenericItemT, RecycleStateResult } from '@infinite-list/strategies';
import {
PortalContextProps,
GroupRecycleContentProps,
Expand Down
3 changes: 2 additions & 1 deletion ui/group/src/react/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GenericItemT, ListGroupDimensions } from '@infinite-list/data-model';
import { ListGroupDimensions } from '@infinite-list/group-dimensions';
import { GenericItemT } from '@infinite-list/item-meta';
import { createContext } from 'react';
import noop from '@x-oasis/noop';

Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react/hooks/useMountItem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useContext, useEffect, useMemo, useRef } from 'react';
import context from '../context';
import { Dimension, GenericItemT } from '@infinite-list/data-model';
import { Dimension, GenericItemT } from '@infinite-list/dimension';
import { GroupListItemImplProps } from '../types';

export default <ItemT extends GenericItemT>(
Expand Down
6 changes: 2 additions & 4 deletions ui/group/src/react/types/GroupList.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
ListDimensionsModelProps,
OnEndReachedHelperProps,
} from '@infinite-list/data-model';
import { ListDimensionsModelProps } from '@infinite-list/dimensions-model';
import { OnEndReachedHelperProps } from '@infinite-list/viewable';
import { DefaultItemT, TeleportItemProps } from './ListItem.types';
import { RenderItem } from './GroupListItemImpl.types';

Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react/types/GroupListItemImpl.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ItemMeta } from '@infinite-list/data-model';
import { ItemMeta } from '@infinite-list/item-meta';
import { ScrollComponentUseMeasureLayout } from './ListGroup.types';

import { ListItemProps, DefaultItemT } from './ListItem.types';
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react/types/ListGroup.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
OnViewableItemsChanged,
ViewabilityConfigCallbackPairs,
GenericItemT,
} from '@infinite-list/data-model';
} from '@infinite-list/viewable';
import { ComponentType, PropsWithChildren, MutableRefObject } from 'react';
import { View, LayoutChangeEvent } from 'react-native';

Expand Down
9 changes: 3 additions & 6 deletions ui/group/src/react/types/ListItem.types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
ItemMeta,
ListGroupDimensions,
ListDimensions,
GenericItemT,
} from '@infinite-list/data-model';
import { ItemMeta, GenericItemT } from '@infinite-list/item-meta';
import { ListDimensions } from '@infinite-list/list-dimensions';
import { ListGroupDimensions } from '@infinite-list/group-dimensions';
import React, { CSSProperties, ForwardedRef } from 'react';
import { LayoutChangeEvent } from 'react-native';
import { ScrollComponentUseMeasureLayout } from './ListGroup.types';
Expand Down
4 changes: 2 additions & 2 deletions ui/group/src/react/types/PortalContext.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
GenericItemT,
ListStateResult,
SpaceStateResult,
ListGroupDimensions,
} from '@infinite-list/data-model';
} from '@infinite-list/strategies';
import { ListGroupDimensions } from '@infinite-list/group-dimensions';
import { ScrollComponentUseMeasureLayout } from './ListGroup.types';

export type PortalContextProps<ItemT extends GenericItemT = GenericItemT> = {
Expand Down
6 changes: 2 additions & 4 deletions ui/group/src/types/GroupList.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
ListDimensionsModelProps,
OnEndReachedHelperProps,
} from '@infinite-list/data-model';
import { ListDimensionsModelProps } from '@infinite-list/dimensions-model';
import { OnEndReachedHelperProps } from '@infinite-list/viewable';
import { DefaultItemT } from './ListItem.types';

export interface GroupListProps<ItemT extends DefaultItemT>
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/types/GroupListItemImpl.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ItemMeta } from '@infinite-list/data-model';
import { ItemMeta } from '@infinite-list/item-meta';
import { ScrollComponentUseMeasureLayout } from './ListGroup.types';

import { ListItemProps, DefaultItemT } from './ListItem.types';
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/types/ListGroup.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ViewabilityConfig,
OnViewableItemsChanged,
ViewabilityConfigCallbackPairs,
} from '@infinite-list/data-model';
} from '@infinite-list/viewable';
import { ComponentType, PropsWithChildren, MutableRefObject } from 'react';
import { View, LayoutChangeEvent } from 'react-native';

Expand Down
9 changes: 3 additions & 6 deletions ui/group/src/types/ListItem.types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
ItemMeta,
ListGroupDimensions,
ListDimensions,
GenericItemT,
} from '@infinite-list/data-model';
import { ItemMeta, GenericItemT } from '@infinite-list/item-meta';
import { ListGroupDimensions } from '@infinite-list/group-dimensions';
import { ListDimensions } from '@infinite-list/list-dimensions';
import React, { ForwardedRef } from 'react';
import { ViewStyle, LayoutChangeEvent } from 'react-native';
import { ScrollComponentUseMeasureLayout } from './ListGroup.types';
Expand Down
4 changes: 2 additions & 2 deletions ui/group/src/types/PortalContext.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
GenericItemT,
ListStateResult,
SpaceStateResult,
ListGroupDimensions,
} from '@infinite-list/data-model';
} from '@infinite-list/strategies';
import { ListGroupDimensions } from '@infinite-list/group-dimensions';
import { ScrollComponentUseMeasureLayout } from './ListGroup.types';

export type PortalContextProps = {
Expand Down

0 comments on commit 2185442

Please sign in to comment.