Commit 93521cce authored by kavusi98's avatar kavusi98
Browse files

Merge branch '15-cleanup' of...

Merge branch '15-cleanup' of https://gitlab.stud.idi.ntnu.no/it2810-h21/team-29/iwhattowatch into 15-cleanup
parents 90be0025 b5ac6d8c
......@@ -6,7 +6,7 @@ interface FavButtonProps {
isFavorited: boolean;
userName: string;
id: string;
onPressed: (newValue: boolean) => void;
onPressed: (newValue: boolean, id: string) => void;
}
/**
......@@ -42,6 +42,9 @@ const FavButton: React.FC<FavButtonProps> =({isFavorited, userName, id, onPresse
}
}
/* Sets movie as favorite through API and changes local state through callback
to parent component. The state is changed to keep track of local favorites not stored in redux store. */
function clickFavorite(didUserFavorite: boolean) {
if (didUserFavorite) {
setFavorite();
......
......@@ -33,11 +33,13 @@ const LoginModal:React.FC<SignInProps> = ({isLoginModalVisible, setIsModalVisibl
'Quicksand-Regular': require('../../assets/fonts/Quicksand-Regular.ttf'),
})
/* Calls redux dispatch to change state when logging out and removes modal */
const handleLogOut = () => {
logOut()
setIsModalVisible(false);
}
/* Calls redux dispatch to log in and set user and removes modal */
const handleSubmit = () => {
setUser(value);
setIsModalVisible(false);
......
......@@ -6,6 +6,7 @@ const initialState: IUserState = {
userName: undefined,
};
/* Reducer and actions that changes state */
const UserSlice = createSlice({
name: "userSlice",
initialState,
......
......@@ -32,6 +32,7 @@ const MovieModal: React.FC<ModalProps> = ({movie, setIsModalVisible, isModalVisi
'Quicksand-SemiBold': require('../../assets/fonts/Quicksand-Medium.ttf'),
})
/* Returns an array with the current user (username) removed */
function getReducedArray(array: Array<string>): Array<string> {
if (userName === undefined) {
return []
......@@ -44,6 +45,7 @@ const MovieModal: React.FC<ModalProps> = ({movie, setIsModalVisible, isModalVisi
return temp;
}
/* Shows the modal based on the prop value from parent component */
if(isModalVisible){
return (
<Modal
......
......@@ -16,6 +16,7 @@ import { LogBox } from 'react-native';
* The movies are fetched form the database.
*/
/* Interface for object with movie */
interface IMovieObject {
item: searchMovies_getMoviesBySearch;
}
......@@ -24,6 +25,7 @@ interface MovieTableProps {
fetchMore: () => void;
}
/* Interface for object with favorite information */
type favoritedMovie = {
id:string;
isFavorited:boolean;
......@@ -42,6 +44,8 @@ const MovieTable: React.FC<MovieTableProps> = ({fetchMore}) => {
'Quicksand-Regular': require('../../assets/fonts/Quicksand-Regular.ttf')
})
/* Returns true or false based on component state. If component state does not contain a value for the movie,
the favorited value for the logged in user of the movie is returned */
function isFavorited(movie: searchMovies_getMoviesBySearch): boolean {
if (movie === null || !userName ) {
return false;
......@@ -59,8 +63,8 @@ const MovieTable: React.FC<MovieTableProps> = ({fetchMore}) => {
}, [])
/* Returns a reduced array with the favorited movie only occuring once, if it already exists, update with new value */
function handleFavorize(newValue: boolean, id: string) {
let alreadyInFavorites = favoritedInSession.filter(favoritedInSession => favoritedInSession.id === id)
if (alreadyInFavorites.length > 0) {
let newFav = alreadyInFavorites[0]
......
......@@ -63,12 +63,13 @@ export const MainPage: FunctionComponent = () => {
}
};
/* Fetches new set of movies if one of the filtering or sorting values are changed */
useEffect(() => {
fetchMovies();
}, [filterSearchQuery, filterGenre, filterDateStart, filterDateEnd, sortBy]);
/* Shows login modal to opposite of previous state */
useEffect(() => {
}, [width, height])
const [isLoginModalVisible, setIsLoginModalVisible] = useState(false);
const toggleLogInModal = () => {
......
......@@ -12,10 +12,12 @@ const initialState: IMoviesList = {
sortByCriteria: "",
};
/* Redux toolkit reducers with action and reducer in one method */
const MainPageSlice = createSlice({
name: "mainPage",
initialState,
reducers: {
/* Adds payload to movie state and increases page offset */
setMovies(state, action) {
state.nextPage += 1;
if (state.movies !== null) {
......
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