update src/redux/actions/index.js, src/redux/reducers/index.js, Header.js and src/screens/Splash/index.js

master
Reza_ashrafi 2 years ago
parent 2e87980bf9
commit e4c74efad6
  1. 10
      src/redux/actions/config.js
  2. 3
      src/redux/actions/index.js
  3. 25
      src/redux/reducers/config.js
  4. 3
      src/redux/reducers/index.js
  5. 6
      src/screens/Products/components/Header.js
  6. 22
      src/screens/Splash/index.js

@ -0,0 +1,10 @@
import proxy from "../proxy";
const config = {
getBottomNavigation:
(data = {}) =>
async (dispatch) =>
await proxy.get("config/bottomNavigations", data, { dispatch }),
};
export default config;

@ -16,4 +16,5 @@ export { default as transport } from "./transport";
export { default as activation } from "./activation"; export { default as activation } from "./activation";
export { default as form } from "./form"; export { default as form } from "./form";
export { default as comment } from "./comment"; export { default as comment } from "./comment";
export { default as vote } from "./vote"; export { default as vote } from "./vote";
export { default as config } from "./config";

@ -0,0 +1,25 @@
const initialState = {
loading: false,
error: null,
bottomNavigations: null,
};
export default function config(state = initialState, action) {
let { type, data } = action;
switch (type) {
case "config/bottomNavigations":
console.log(data);
return {
...state,
loading: false,
bottomNavigations: data,
error: null,
};
case "config/loading":
return { ...state, loading: true };
case "config/error":
return { ...state, loading: false, error: data.message };
default:
return state;
}
}

@ -15,4 +15,5 @@ export { default as transport } from "./transport";
export { default as activation } from "./activation"; export { default as activation } from "./activation";
export { default as form } from "./form"; export { default as form } from "./form";
export { default as comment } from "./comment"; export { default as comment } from "./comment";
export { default as vote } from "./vote"; export { default as vote } from "./vote";
export { default as config } from "./config";

@ -19,7 +19,7 @@ const Header = ({ setFilterOptions, filterOptions, levels, productTypes }) => {
value={filterOptions.search} value={filterOptions.search}
/> />
<View style={[tw("flex flex-1 flex-row justify-between items-center")]}> <View style={[tw("flex flex-1 flex-row justify-between items-center")]}>
{/* <Select <Select
defaultValue={productTypes[0]} defaultValue={productTypes[0]}
onChange={(name, value) => onChange={(name, value) =>
value !== "نوع محصول" value !== "نوع محصول"
@ -29,7 +29,7 @@ const Header = ({ setFilterOptions, filterOptions, levels, productTypes }) => {
options={productTypes} options={productTypes}
width={"48%"} width={"48%"}
name="productType" name="productType"
/> */} />
<Select <Select
defaultValue={Object.values(levels)[0]} defaultValue={Object.values(levels)[0]}
onChange={(name, value) => onChange={(name, value) =>
@ -38,7 +38,7 @@ const Header = ({ setFilterOptions, filterOptions, levels, productTypes }) => {
: setFilterOptions({ ...filterOptions, [name]: null }) : setFilterOptions({ ...filterOptions, [name]: null })
} }
options={Object.values(levels)} options={Object.values(levels)}
width={"100%"} width={"48%"}
name="grade" name="grade"
/> />
</View> </View>

@ -9,7 +9,13 @@ import {
} from "react-native"; } from "react-native";
import AsyncStorage from "@react-native-async-storage/async-storage"; import AsyncStorage from "@react-native-async-storage/async-storage";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { blog, book, userProduct, publicApi } from "../../redux/actions"; import {
blog,
book,
userProduct,
publicApi,
config,
} from "../../redux/actions";
import { useIsFocused } from "@react-navigation/native"; import { useIsFocused } from "@react-navigation/native";
import Logo from "../../assets/images/logo.png"; import Logo from "../../assets/images/logo.png";
@ -30,6 +36,8 @@ function Splash({
userProducts, userProducts,
getUserProducts, getUserProducts,
setIsDark, setIsDark,
getBottomNavigation,
bottomNavigation,
}) { }) {
const isFocused = useIsFocused(); const isFocused = useIsFocused();
const [out, setOut] = React.useState(false); const [out, setOut] = React.useState(false);
@ -63,12 +71,14 @@ function Splash({
routes: [{ name: "Login" }], routes: [{ name: "Login" }],
}); });
} else { } else {
if (blogs.length === 0) { if (!blogs.length) {
getBlogs(); getBlogs();
} else if (books.length === 0) { } else if (!books.length) {
getBooks({ vod: true }); getBooks({ vod: true });
} else if (userProducts.length === 0) { } else if (!userProducts.length) {
getUserProducts(); getUserProducts();
} else if (!bottomNavigation) {
getBottomNavigation();
} else { } else {
setOutHandler(true); setOutHandler(true);
navigation.reset({ navigation.reset({
@ -78,7 +88,7 @@ function Splash({
} }
} }
} }
}, [isLogin, books, userProducts, blogs]); }, [isLogin, books, userProducts, blogs, bottomNavigation]);
// if (isFocused && out) { // if (isFocused && out) {
// setOutHandler(false); // setOutHandler(false);
@ -139,6 +149,7 @@ const mapStateToProps = (state) => ({
books: state.book.list, books: state.book.list,
userProducts: state.userProduct.list, userProducts: state.userProduct.list,
theme: state.publicApi.theme, theme: state.publicApi.theme,
bottomNavigation: state.config.bottomNavigation,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {
@ -146,6 +157,7 @@ const mapDispatchToProps = {
getBooks: book.list, getBooks: book.list,
getUserProducts: userProduct.list, getUserProducts: userProduct.list,
setIsDark: publicApi.setIsDark, setIsDark: publicApi.setIsDark,
getBottomNavigation: config.getBottomNavigation,
}; };
export default connect(mapStateToProps, mapDispatchToProps)(Splash); export default connect(mapStateToProps, mapDispatchToProps)(Splash);

Loading…
Cancel
Save