Explore category to store

This commit is contained in:
Maarten 2024-08-08 14:18:32 +02:00
parent b619fe34f8
commit d8d8ac35f8
3 changed files with 16 additions and 15 deletions

View file

@ -8,7 +8,7 @@ import {
import { useEffect, useState } from 'react';
import RenderHtml from 'react-native-render-html';
import { useNavigation } from '@react-navigation/native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { useSelector } from 'react-redux';
import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';
@ -18,23 +18,18 @@ export default function CategoryScreen() {
const colorScheme = useColorScheme() ?? 'light';
const navigation = useNavigation();
const [ description, setDescription ] = useState( '' );
const viewCategory = useSelector((state: any) => state.data.viewCategory);
// Load item from storage
useEffect( () => {
AsyncStorage.getItem( 'activeCategory' ).then( (data) => {
const itemData: any = JSON.parse( data ?? '{}' );
const { name, description } = viewCategory;
if (itemData != null) {
const { name, description } = itemData;
// Set description
// @ts-ignore
setDescription( description );
// Set description
// @ts-ignore
setDescription( description );
// Set page title
navigation.setOptions( { title: name } );
}
} );
// Set page title
navigation.setOptions( { title: name } );
}, [] );
// HTML render props

View file

@ -13,7 +13,6 @@ import { router } from 'expo-router';
import type { AutocompleteDropdownRef } from 'react-native-autocomplete-dropdown'
import { AutocompleteDropdown } from 'react-native-autocomplete-dropdown';
import Modal from "react-native-modal";
import AsyncStorage from '@react-native-async-storage/async-storage';
import { ThemedText } from '@/components/ThemedText';
import { ThemedView } from '@/components/ThemedView';
@ -21,6 +20,8 @@ import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';
import { Request } from '@/services/request';
import List from '@/components/List';
import { store } from '@/store/store';
import { setViewCategory } from '@/store/dataStore';
export default function ExploreScreen() {
const colorScheme = useColorScheme() ?? 'light';
@ -67,7 +68,7 @@ export default function ExploreScreen() {
// View item in sub screen
const viewItem = async (item: any) => {
await AsyncStorage.setItem( 'activeCategory', JSON.stringify( item ) );
store.dispatch(setViewCategory(item));
router.push( '/(explore)/category' );
};