Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,10 @@
"createTicketScreen": {
"insert": "Insert ticket",
"messageLabel": "Describe your problem and, if you want, attach a file",
"messageTitle": "Description",
"sendTicket": "Send ticket",
"subject": "Subject",
"subjectTitle": "Subject",
"subjectLabel": "Enter the subject of the ticket",
"subtitle": "Enter your request",
"subtopicDescription": "Select the subtopic",
Expand Down
2 changes: 2 additions & 0 deletions assets/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,11 @@
"addFile": "Aggiungi file",
"insert": "Inserimento ticket",
"messageLabel": "Descrivi il tuo problema e, se vuoi, allega un file",
"messageTitle": "Descrizione",
"sendTicket": "Invia ticket",
"subject": "Oggetto",
"subjectLabel": "Inserisci l'oggetto del ticket",
"subjectTitle": "Oggetto",
"subtitle": "Inserisci la tua richiesta",
"subtopicDescription": "Seleziona il sottoargomento",
"subtopicDropdownLabel": "Sottoargomento",
Expand Down
77 changes: 77 additions & 0 deletions lib/ui/components/NestedList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from 'react';
import { SectionList, StyleProp, ViewStyle } from 'react-native';

import { IndentedDivider } from '@lib/ui/components/IndentedDivider';
import { OverviewList } from '@lib/ui/components/OverviewList';
import { RefreshControl } from '@lib/ui/components/RefreshControl';
// import { useStylesheet } from '@lib/ui/hooks/useStylesheet';
// import { Theme } from '@lib/ui/types/Theme';
import { UseQueryResult } from '@tanstack/react-query';

export type NestedListSection<TItem, TSection> = {
title: string;
isExpanded?: boolean;
index: number;
data: TItem[];
sectionData?: TSection;
};

export type NestedListProps<TItem, TSection> = {
sections: NestedListSection<TItem, TSection>[];
loading?: boolean;
queries: UseQueryResult[];
onToggleSection: (index: number) => void;
renderItem: (props: {
item: TItem;
section: NestedListSection<TItem, TSection>;
}) => React.ReactElement | null;
renderSectionHeader: (props: {
section: NestedListSection<TItem, TSection>;
}) => React.ReactElement;
keyExtractor?: (item: TItem, index: number) => string;
style?: StyleProp<ViewStyle>;
indented?: boolean;
accordionMode?: boolean;
};

export const NestedList = <TItem, TSection>({
sections,
loading,
queries,
// onToggleSection,
renderItem,
renderSectionHeader,
keyExtractor = (_, index) => index.toString(),
style,
indented = true,
}: NestedListProps<TItem, TSection>) => {
// const styles = useStylesheet(createStyles);

return (
<OverviewList loading={loading} indented={indented} style={style}>
<SectionList
refreshControl={<RefreshControl queries={queries} manual />}
stickySectionHeadersEnabled
sections={sections}
keyExtractor={keyExtractor}
renderSectionFooter={({ section: { index } }) =>
index !== sections.length - 1 ? (
<IndentedDivider indent={indented ? 14 : 0} />
) : null
}
initialNumToRender={2}
renderSectionHeader={({ section }) => renderSectionHeader({ section })}
renderItem={({ item, section }) => renderItem({ item, section })}
/>
</OverviewList>
);
};

// const createStyles = ({ spacing }: Theme) =>
// StyleSheet.create({
// list: {
// flex: 1,
// },
// });

export default NestedList;
Loading