Commit b19976a4 authored by kavusi98's avatar kavusi98
Browse files

(#15) Code cleanup

parent 93521cce
import React, { useState } from "react";
import React from "react";
import { selectUserIsLoggedIn, selectUserName } from "../../services/selectors"
import { useSelector } from "react-redux";
import {
......
......@@ -124,8 +124,8 @@ const MovieTable: React.FC<MovieTableProps> = ({fetchMore}) => {
}}
onEndReached={fetchMore}
>
{modalMovie ? <MovieModal isModalVisible={modalVisible} setIsModalVisible={setModalVisible} movie={modalMovie}/> : null}
</FlatList>
{modalMovie ? <MovieModal isModalVisible={modalVisible} setIsModalVisible={setModalVisible} movie={modalMovie}/> : null}
</SafeAreaView>
)
}
......
import * as React from "react";
import { useSelector } from "react-redux";
import { useAppDispatch } from "../../services/hooks";
import { Dispatch } from "redux";
import { setSearchQuery } from "../../pages/mainPageSlice";
import { logOut } from "../login/loginslice"
import { selectUserIsLoggedIn } from "../../services/selectors";
import { Appbar } from "react-native-paper";
import { useFonts} from '@expo-google-fonts/quicksand';
import AppLoading from "expo-app-loading";
const actionDispatch = (dispatch: Dispatch) => ({
setSearch: (query: string) => dispatch(setSearchQuery(query)),
setLogOut: () => dispatch(logOut()),
});
interface NavBarProps{
isLoginModalVisible:boolean;
onCloseClick: () => void;
closeSideBar: () => void;
isSideBarVisible:boolean;
......@@ -25,12 +15,10 @@ interface NavBarProps{
* This is the header for our app. We use AppBar component from MUI.
* The component both have the search function and userLogIn.
*
* @param isLoginModalVisible, onCloseClick
* @returns header to show.
*/
const NavBar: React.FC<NavBarProps> = ({isLoginModalVisible, onCloseClick, closeSideBar, isSideBarVisible}) => {
const {setLogOut} = actionDispatch(useAppDispatch());
const isLoggedIn = useSelector(selectUserIsLoggedIn)
const NavBar: React.FC<NavBarProps> = ({onCloseClick, closeSideBar, isSideBarVisible}) => {
let [fontsLoaded] = useFonts({
'Quicksand-SemiBold': require('../../assets/fonts/Quicksand-SemiBold.ttf'),
......
......@@ -12,6 +12,7 @@ const actionDispatch = (dispatch: Dispatch) => ({
setFilter: (filter:object) => dispatch(setFilterGenres(filter)),
});
/* All genres */
const genres = [
{id:"1", name: "Action", isChecked: false},
{id: "2", name: "Adventure", isChecked: false},
......@@ -49,7 +50,12 @@ const FilterGenreComp: FunctionComponent = () => {
'Quicksand-Regular': require('../../assets/fonts/Quicksand-Regular.ttf'),
})
const onSelectionsChange = (id:string) => {
/**
* Updates selected genres.
*
* @param id id of genre
*/
const onSelectionsChange = (id:string) => {
let temp = selectedGenres.map((genre) => {
if (id === genre.id) {
return { ...genre, isChecked: !genre.isChecked };
......@@ -60,6 +66,11 @@ const FilterGenreComp: FunctionComponent = () => {
updateFilters(temp);
}
/**
* Method used to filter by genre.
*
* @param genreArray All selected genre to filter by
*/
function updateFilters(genreArray: Array<{ id: string; name: string; isChecked: boolean; }>) {
var filteredArray = genreArray.filter(genre => genre.isChecked === true).map(({name}) => name)
setFilter(filteredArray)
......
......@@ -51,7 +51,7 @@ const FilterByYear: FunctionComponent = () => {
>Filter by year</Title>
<TextInput
label="From"
keyboardType="numeric"
keyboardType="number-pad"
placeholder="Type year here"
maxLength={4}
onChangeText={(newValue: string) => {
......@@ -60,7 +60,7 @@ const FilterByYear: FunctionComponent = () => {
/>
<TextInput
label="To"
keyboardType="numeric"
keyboardType="number-pad"
placeholder="Type year here"
maxLength={4}
onChangeText={(newValue: string) => {
......
import React, { FunctionComponent, useEffect, useState } from "react";
import { StyleSheet, ScrollView, SafeAreaView, View, LogBox } from "react-native";
import React, { FunctionComponent, } from "react";
import { StyleSheet, ScrollView,View } from "react-native";
import FilterByYear from "./FilterByYear";
import FilterGenreComp from "./FilterByGenre";
......@@ -8,14 +8,9 @@ import SearchComp from './Search';
/**
* Global SideBar
* Menu that contains search and filter options
*/
interface SideBarProps {
isSideBarVisible: boolean;
closeSideBar: () => void;
}
const SideBar: FunctionComponent<SideBarProps> = ({isSideBarVisible, closeSideBar}) => {
const SideBar: FunctionComponent = () => {
......
......@@ -21,7 +21,6 @@ const actionDispatch = (dispatch: Dispatch) => ({
*
*/
export default function SortDropDown() {
const [open, setOpen] = useState(false);
const [sortBy, setSortBy] = useState('');
const { setCriteria } = actionDispatch(useAppDispatch());
......
import React from 'react';
import { View, Text } from 'react-native';
import { useSelector } from 'react-redux';
import {selectUserIsLoggedIn, selectUserName} from '../../services/selectors';
import {selectUserName} from '../../services/selectors';
import { StyleSheet } from 'react-native';
import { useFonts } from 'expo-font';
import AppLoading from 'expo-app-loading';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment