Skip to content

Commit

Permalink
feat: Sort options come from state and persist (#2050)
Browse files Browse the repository at this point in the history
  • Loading branch information
NigelBreslaw authored Jul 17, 2024
1 parent db6ea6b commit 90a9522
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
31 changes: 26 additions & 5 deletions native/app/inventory/pages/OptionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { RefreshCcw } from "@/lib/icons/Refresh-ccw.tsx";
import Animated, { FadeIn } from "react-native-reanimated";
import { useGGStore } from "@/app/store/GGStore.ts";
import { getFullProfile } from "@/app/bungie/BungieApi.ts";
import { ArmorSort, WeaponsSort } from "@/app/store/Types.ts";

export default function OptionsMenu() {
"use memo";
Expand All @@ -33,6 +34,11 @@ export default function OptionsMenu() {
}
}, [activateInventoryMenu]);

const weaponsSort = useGGStore((state) => state.weaponsSort);
const setWeaponsSort = useGGStore((state) => state.setWeaponsSort);
const armorSort = useGGStore((state) => state.armorSort);
const setArmorSort = useGGStore((state) => state.setArmorSort);

return (
<View className="absolute top-0 right-0 w-16 h-16 active:bg-primary/5">
<DropdownMenu>
Expand All @@ -48,13 +54,22 @@ export default function OptionsMenu() {
</DropdownMenuSubTrigger>
<DropdownMenuSubContent>
<Animated.View entering={FadeIn.duration(70)}>
<DropdownMenuCheckboxItem checked={false} onCheckedChange={() => {}}>
<DropdownMenuCheckboxItem
checked={weaponsSort === WeaponsSort.Power}
onCheckedChange={() => setWeaponsSort(WeaponsSort.Power)}
>
<Text>By Power</Text>
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem checked={true} onCheckedChange={() => {}}>
<DropdownMenuCheckboxItem
checked={weaponsSort === WeaponsSort.Type}
onCheckedChange={() => setWeaponsSort(WeaponsSort.Type)}
>
<Text>By Type</Text>
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem checked={false} onCheckedChange={() => {}}>
<DropdownMenuCheckboxItem
checked={weaponsSort === WeaponsSort.TypeAndPower}
onCheckedChange={() => setWeaponsSort(WeaponsSort.TypeAndPower)}
>
<Text>By Type and Power</Text>
</DropdownMenuCheckboxItem>
</Animated.View>
Expand All @@ -67,10 +82,16 @@ export default function OptionsMenu() {
</DropdownMenuSubTrigger>
<DropdownMenuSubContent>
<Animated.View entering={FadeIn.duration(70)}>
<DropdownMenuCheckboxItem checked={true} onCheckedChange={() => {}}>
<DropdownMenuCheckboxItem
checked={armorSort === ArmorSort.Power}
onCheckedChange={() => setArmorSort(ArmorSort.Power)}
>
<Text>By Power</Text>
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem checked={false} onCheckedChange={() => {}}>
<DropdownMenuCheckboxItem
checked={armorSort === ArmorSort.Type}
onCheckedChange={() => setArmorSort(ArmorSort.Type)}
>
<Text>By Type</Text>
</DropdownMenuCheckboxItem>
</Animated.View>
Expand Down
13 changes: 13 additions & 0 deletions native/app/store/Account/AccountSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import type {
import { lightLevelBuckets, type UISections } from "@/app/inventory/logic/Helpers.ts";
import { iconUrl, screenshotUrl } from "@/app/core/ApiResponse.ts";
import { DamageType, DestinyClass, ItemSubType, ItemType, SectionBuckets, TierType } from "@/app/bungie/Enums.ts";
import { ArmorSort, WeaponsSort } from "@/app/store/Types.ts";

export type AccountSliceSetter = Parameters<StateCreator<IStore, [], [], AccountSlice>>[0];
export type AccountSliceGetter = Parameters<StateCreator<IStore, [], [], AccountSlice>>[1];
Expand All @@ -76,6 +77,8 @@ export interface AccountSlice {
animateToInventoryPage: { index: number; animate: boolean };
activateInventoryMenu: boolean;
initialAccountDataReady: boolean;
weaponsSort: WeaponsSort;
armorSort: ArmorSort;

ggCharacters: GGCharacterUiData[];
ggWeapons: UISections[][];
Expand All @@ -98,6 +101,8 @@ export interface AccountSlice {
setPullRefreshing: (pullRefreshing: boolean) => void;
setCurrentListIndex: (payload: number) => void;
setJumpToIndex: (payload: { index: number; animate: boolean }) => void;
setWeaponsSort: (weaponsSort: WeaponsSort) => void;
setArmorSort: (armorSort: ArmorSort) => void;
updateProfile: (profile: ProfileData) => void;
setQuantityToTransfer: (quantityToTransfer: number) => void;
setTimestamps: (responseMintedTimestamp: string, secondaryComponentsMintedTimestamp: string) => void;
Expand All @@ -123,6 +128,8 @@ export const createAccountSlice: StateCreator<IStore, [], [], AccountSlice> = (s
showingPerks: false,
activateInventoryMenu: false,
initialAccountDataReady: false,
weaponsSort: WeaponsSort.TypeAndPower,
armorSort: ArmorSort.Type,

ggCharacters: [],
ggWeapons: [],
Expand Down Expand Up @@ -152,6 +159,12 @@ export const createAccountSlice: StateCreator<IStore, [], [], AccountSlice> = (s
setCurrentListIndex: (currentListIndex) => {
set({ currentListIndex, animateToInventoryPage: { index: currentListIndex, animate: false } });
},
setWeaponsSort: (weaponsSort) => {
set({ weaponsSort });
},
setArmorSort: (armorSort) => {
set({ armorSort });
},
setJumpToIndex: (jumpToIndex) => {
set({ animateToInventoryPage: jumpToIndex });
},
Expand Down
6 changes: 5 additions & 1 deletion native/app/store/GGStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export const useGGStore = create<IStore>()(
{
name: "gg-storage",
storage: createJSONStorage(() => AsyncStorage),
partialize: (state) => ({ currentListIndex: state.currentListIndex }),
partialize: (state) => ({
currentListIndex: state.currentListIndex,
weaponsSort: state.weaponsSort,
armorSort: state.armorSort,
}),
},
),
);
11 changes: 11 additions & 0 deletions native/app/store/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import type { DefinitionKey } from "@/app/core/BungieDefinitions.ts";
export type StorageKey = "ITEM_DEFINITION" | "ACCOUNTS";
export type AsyncStorageKey = DefinitionKey;

export enum WeaponsSort {
Power = "POWER",
Type = "TYPE",
TypeAndPower = "TYPE_AND_POWER",
}

export enum ArmorSort {
Power = "POWER",
Type = "TYPE",
}

export const DatabaseStore = {
factoryName: "gg-data",
storeName: "key-values",
Expand Down

0 comments on commit 90a9522

Please sign in to comment.