Skip to content

Commit

Permalink
app: use menu to select sorting of untagged items
Browse files Browse the repository at this point in the history
  • Loading branch information
zetavg committed Jan 21, 2024
1 parent ab89e1b commit 2ab5909
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 21 deletions.
5 changes: 4 additions & 1 deletion App/app/consts/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ export const ICON_COLORS = [

export type IconColor = (typeof ICON_COLORS)[number];

export const MAJOR_VERSION_IOS =
Platform.OS === 'ios' ? parseInt(Platform.Version, 10) : 0;

function sfSymbolForOSVersion(
sfSymbolName: string,
{ ios }: { ios: number },
): string | undefined {
if (Platform.OS === 'ios') {
const majorVersionIOS = parseInt(Platform.Version, 10);
const majorVersionIOS = MAJOR_VERSION_IOS;
if (majorVersionIOS < ios) {
return undefined;
}
Expand Down
6 changes: 6 additions & 0 deletions App/app/data/hooks/useView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ export default function useView<T extends ViewName>(
}
}, [db, logger, cachedOptions, viewName]);

const prevLoadData = useRef(loadData);
useFocusEffect(
useCallback(() => {
if (cachedOptions.disable) return;

if (prevLoadData.current !== loadData) {
setLoading(true);
prevLoadData.current = loadData;
}

if (!dataRef.current) {
loadData();
} else {
Expand Down
102 changes: 82 additions & 20 deletions App/app/features/inventory/screens/RFIDUntaggedItemsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useCallback, useMemo, useRef, useState } from 'react';
import { SectionList } from 'react-native';
import { Platform, SectionList } from 'react-native';
import { useFocusEffect } from '@react-navigation/native';
import type { StackScreenProps } from '@react-navigation/stack';

import { InvalidDataTypeWithID, ValidDataTypeWithID } from '@deps/data/types';

import { MAJOR_VERSION_IOS } from '@app/consts/icons';

import useView from '@app/data/hooks/useView';

import type { StackParamList } from '@app/navigation/MainStack';
Expand All @@ -17,15 +19,24 @@ import ItemListItem from '../components/ItemListItem';
function RFIDUntaggedItemsScreen({
navigation,
}: StackScreenProps<StackParamList, 'RFIDUntaggedItems'>) {
const [sort, setSort] = useState<'updated_time' | 'created_time'>(
'updated_time',
);
const [order, setOrder] = useState<'asc' | 'desc'>('desc');
const {
data: rfidUntaggedItemsData,
loading: rfidUntaggedItemsDataLoading,
refresh: refreshRfidUntaggedItems,
refreshing: rfidUntaggedItemsRefreshing,
} = useView('rfid_untagged_items_by_updated_time', {
includeDocs: true,
descending: true,
});
} = useView(
sort === 'updated_time'
? 'rfid_untagged_items_by_updated_time'
: 'rfid_untagged_items_by_created_time',
{
includeDocs: true,
descending: order === 'desc',
},
);
const rfidUntaggedItems = rfidUntaggedItemsData
? rfidUntaggedItemsData
.map(d => d.data)
Expand All @@ -37,10 +48,15 @@ function RFIDUntaggedItemsScreen({
loading: rfidTagOutdatedItemsDataLoading,
refresh: refreshRfidTagOutdatedItems,
refreshing: rfidTagOutdatedItemsRefreshing,
} = useView('rfid_tag_outdated_items_by_updated_time', {
includeDocs: true,
descending: true,
});
} = useView(
sort === 'updated_time'
? 'rfid_tag_outdated_items_by_updated_time'
: 'rfid_tag_outdated_items_by_created_time',
{
includeDocs: true,
descending: order === 'desc',
},
);
const rfidTagOutdatedItems = rfidTagOutdatedItemsData
? rfidTagOutdatedItemsData
.map(d => d.data)
Expand All @@ -58,22 +74,29 @@ function RFIDUntaggedItemsScreen({
return [
{
title: 'untagged',
data: rfidUntaggedItems
? rfidUntaggedItems.length > 0
? rfidUntaggedItems
: (['null'] as const)
: (['loading'] as const),
data:
rfidUntaggedItems && !rfidUntaggedItemsDataLoading
? rfidUntaggedItems.length > 0
? rfidUntaggedItems
: (['null'] as const)
: (['loading'] as const),
},
{
title: 'tag-outdated',
data: rfidTagOutdatedItems
? rfidTagOutdatedItems.length > 0
? rfidTagOutdatedItems
: (['null'] as const)
: (['loading'] as const),
data:
rfidTagOutdatedItems && !rfidTagOutdatedItemsDataLoading
? rfidTagOutdatedItems.length > 0
? rfidTagOutdatedItems
: (['null'] as const)
: (['loading'] as const),
},
];
}, [rfidTagOutdatedItems, rfidUntaggedItems]);
}, [
rfidTagOutdatedItems,
rfidTagOutdatedItemsDataLoading,
rfidUntaggedItems,
rfidUntaggedItemsDataLoading,
]);

const loading =
rfidUntaggedItemsDataLoading || rfidTagOutdatedItemsDataLoading;
Expand Down Expand Up @@ -122,6 +145,45 @@ function RFIDUntaggedItemsScreen({
navigation={navigation}
title="Items"
headerLargeTitle={false}
action1Label="Order"
action1SFSymbolName={
MAJOR_VERSION_IOS >= 16
? 'arrow.up.and.down.text.horizontal'
: 'slider.vertical.3'
}
action1MaterialIconName="sort-ascending"
action1MenuActions={[
{
type: 'section',
children: [
{
title: 'Sort by Created Time',
state: sort === 'created_time' ? 'on' : 'off',
onPress: () => setSort('created_time'),
},
{
title: 'Sort by Updated Time',
state: sort === 'updated_time' ? 'on' : 'off',
onPress: () => setSort('updated_time'),
},
],
},
{
type: 'section',
children: [
{
title: 'Ascending',
state: order === 'asc' ? 'on' : 'off',
onPress: () => setOrder('asc'),
},
{
title: 'Descending',
state: order === 'desc' ? 'on' : 'off',
onPress: () => setOrder('desc'),
},
],
},
]}
>
<SectionList
ref={scrollViewRef}
Expand Down

0 comments on commit 2ab5909

Please sign in to comment.