Commit 2055af36 authored by Peter Skaar Nordby's avatar Peter Skaar Nordby
Browse files

La til refresh for ratingliste

parent e1d651f2
import * as React from "react"; import * as React from "react";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { FlatList, StyleSheet } from "react-native"; import { FlatList, RefreshControl, StyleSheet } from "react-native";
import { AirbnbRating } from "react-native-ratings"; import { AirbnbRating } from "react-native-ratings";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { Text, View } from "../components/Themed"; import { Text, View } from "../components/Themed";
...@@ -15,9 +15,18 @@ export default function UserRatings(): JSX.Element { ...@@ -15,9 +15,18 @@ export default function UserRatings(): JSX.Element {
const auth: AuthState = useSelector(({ auth }: ApplicationState) => auth); const auth: AuthState = useSelector(({ auth }: ApplicationState) => auth);
const [refreshing, setRefreshing] = React.useState(false);
const onRefresh = React.useCallback(() => {
setRefreshing(true);
if (auth.token) {
dispatch(getRatings({ token: auth.token }));
}
setRefreshing(false);
}, [refreshing]);
useEffect(() => { useEffect(() => {
if (auth.token) { if (auth.token) {
console.log(auth.token);
dispatch(getRatings({ token: auth.token })); dispatch(getRatings({ token: auth.token }));
} }
}, []); }, []);
...@@ -33,9 +42,12 @@ export default function UserRatings(): JSX.Element { ...@@ -33,9 +42,12 @@ export default function UserRatings(): JSX.Element {
<View <View
style={styles.separator} style={styles.separator}
lightColor="#rgba(0,0,0,0.2)" lightColor="#rgba(0,0,0,0.2)"
darkColor="rgba(255,255,255,0.2)" darkColor="#rgba(255,255,255,0.2)"
/> />
)} )}
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
}
/> />
); );
} }
......
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