From 3445cbac09103ab5f185cdf9d068ec0c154dacd8 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 4 Aug 2023 01:26:42 +0000 Subject: [PATCH] added scene sorting --- src/Components/Modal/index.js | 1 - .../Device/modals/ChooseScene/index.js | 60 ++++++- src/Screens/Device/scene.js | 170 +++++++++--------- 3 files changed, 138 insertions(+), 93 deletions(-) diff --git a/src/Components/Modal/index.js b/src/Components/Modal/index.js index c44ffac..210357f 100644 --- a/src/Components/Modal/index.js +++ b/src/Components/Modal/index.js @@ -172,7 +172,6 @@ export function MyDotsModal({ isOpen, closeModal, data }) { }} disabled={item.disabled} > - {console.log("dis", item.disabled)} s.deviceId === AppSelectedUserDevice.current.id + const deviceScenes = appContext.deviceScenes + .filter((s) => s.deviceId === AppSelectedUserDevice.current.id) + .sort((a, b) => { + if (isSortingAlphabeticalAscending) { + if (a.name < b.name) { + return -1; + } + + if (a.name > b.name) { + return 1; + } + + return 0; + } else { + if (a.name > b.name) { + return -1; + } + if (a.name < b.name) { + return 1; + } + return 0; + } + }); + + useFocusEffect( + useCallback(() => { + navigation.setOptions({ + headerRight: () => + deviceScenes.length > 0 && ( + { + setIsSortingAlphabeticalAscending( + !isSortingAlphabeticalAscending + ); + }} + /> + ), + }); + }, [isSortingAlphabeticalAscending]) ); return ( ) : ( - {deviceSceneActions === undefined || - deviceSceneActions.length === 0 ? ( - - ) : ( - item.actionId} - renderItem={({ item }) => { - console.log("item", item); + item.actionId} + ListEmptyComponent={ + + } + ListFooterComponent={ + + navigation.navigate("modalAddSceneAction", { + deviceFirmwareVersion: device.firmware.version, + }) + } + iconName="plus-circle-outline" + /> + } + renderItem={({ item }) => { + console.log("item", item); - return ( - - - navigation.navigate("modalLayersEditAction", { - actionId: item.actionId, - deviceFirmwareVersion: device.firmware.version, - }) - } + return ( + + + navigation.navigate("modalLayersEditAction", { + actionId: item.actionId, + deviceFirmwareVersion: device.firmware.version, + }) + } + > + - - {getActionTypeIcon(item.type)} - + {getActionTypeIcon(item.type)} + + + Rainbow + + + - Rainbow + Set to - - - Set to - - - - - - + + + - - - - - - ); - }} - /> - )} + + - + + + ); }} - style={{ padding: 8 }} - actionColor={ - deviceSceneActions === undefined || - deviceSceneActions.length === 0 - } - onPress={() => - navigation.navigate("modalAddSceneAction", { - deviceFirmwareVersion: device.firmware.version, - }) - } - iconName="plus-circle-outline" /> )}