Skip to content

Commit

Permalink
Merge pull request #38 from Peel-Organisation/feat/fetchOffset
Browse files Browse the repository at this point in the history
feat(fetchOffset): offset added when fetching compatible profiles from the API to send to the swipe page in main app
  • Loading branch information
DamienDrozd authored Feb 14, 2024
2 parents 6def4ca + d3e6995 commit 1530289
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
61 changes: 35 additions & 26 deletions src/components/Swipe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ const Swipe = (props) => {

const ModalCreateConversation = (
<>
<ModalTitle>{t('Instant_Message.title')}</ModalTitle>
<ModalQuestion>{t('Instant_Message.question')}</ModalQuestion>
<ModalWarning>{t('Instant_Message.warning')}</ModalWarning>
<ModalWarning>{t('Instant_Message.message_remaining')} {loggedUser.nbInstantConversationPossibilities}</ModalWarning>
<ModalButton onPress={() => {
const currentUser = this.swiper.state.topCard;
if (currentUser == "cardA") {
const user = this.swiper.state.cardA.props.user;
createInstantConversation(user._id);
} else if (currentUser == "cardB") {
const user = this.swiper.state.cardB.props.user;
createInstantConversation(user._id);
}
putStorage('user', { nbInstantConversationPossibilities: loggedUser.nbInstantConversationPossibilities - 1 });
setLoggedUser({ ...loggedUser, nbInstantConversationPossibilities: loggedUser.nbInstantConversationPossibilities - 1 });
closeModal();
}}
disabled={loggedUser.nbInstantConversationPossibilities == 0}
>
<ModalButtonText>{t('Instant_Message.send')}</ModalButtonText>
</ModalButton>
<ModalTitle>{t('Instant_Message.title')}</ModalTitle>
<ModalQuestion>{t('Instant_Message.question')}</ModalQuestion>
<ModalWarning>{t('Instant_Message.warning')}</ModalWarning>
<ModalWarning>{t('Instant_Message.message_remaining')} {loggedUser.nbInstantConversationPossibilities}</ModalWarning>
<ModalButton onPress={() => {
const currentUser = this.swiper.state.topCard;
if (currentUser == "cardA") {
const user = this.swiper.state.cardA.props.user;
createInstantConversation(user._id);
} else if (currentUser == "cardB") {
const user = this.swiper.state.cardB.props.user;
createInstantConversation(user._id);
}
putStorage('user', { nbInstantConversationPossibilities: loggedUser.nbInstantConversationPossibilities - 1 });
setLoggedUser({ ...loggedUser, nbInstantConversationPossibilities: loggedUser.nbInstantConversationPossibilities - 1 });
closeModal();
}}
disabled={loggedUser.nbInstantConversationPossibilities == 0}
>
<ModalButtonText>{t('Instant_Message.send')}</ModalButtonText>
</ModalButton>
</>
);

Expand All @@ -61,29 +61,38 @@ const Swipe = (props) => {
const checkSwipePossible = async (user, value) => {

let loggedUser = await getStorage('user');

let newUser = { swipeCount: loggedUser.swipeCount };

if (newUser.swipeCount == undefined) {
newUser.swipeCount = { count: 0, date: new Date() }
}

const swipeDate = new Date(newUser.swipeCount?.date).getDate();
const swipeMonth = new Date(newUser.swipeCount?.date).getMonth();
const swipeYear = new Date(newUser.swipeCount?.date).getFullYear();
const todayDate = new Date().getDate();
const todayMonth = new Date().getMonth();
const todayYear = new Date().getFullYear();

// if the date is not today, reset the counter
if (swipeDate !== todayDate || swipeMonth !== todayMonth || swipeYear !== todayYear) {
newUser.swipeCount = { count: 0, date: new Date() }
setLoggedUser({ ...loggedUser, swipeCount: newUser.swipeCount })
updateUser(newUser);
}

// increment the counter
newUser.swipeCount.count++;

//if the counter is a multiple of 10, notify the parent component
if (newUser.swipeCount.count % 10 === 0) {
props.onSwipeCountOffsetThreshold();
console.log("Nouvelle liste de matchs");
}

const mode = process.env.NODE_ENV

// if the counter is above 10, return true
if (mode != "development") {
newUser.swipeCount.count++;
Expand Down
14 changes: 8 additions & 6 deletions src/screens/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { PostMatchList } from "../../functions/api_request"
import Loading from "../../components/loading";
import Filter from "../../components/Filter";
import RetryButton from "../../components/Retry";
import { use } from "i18next";



const Match = () => {
const { t } = useTranslation();

const [loading, setLoading] = useState(true);
const [userList, setUserList] = useState([{}]);
const [userList, setUserList] = useState([]);
const [filter, setFilter] = useState(false);
const [retry, setRetry] = React.useState(false);
const [error, setError] = React.useState("");
Expand All @@ -37,17 +38,17 @@ const Match = () => {
});

useEffect(() => {
setLoading(true);
setRetry(false);
setError("");
crashlytics().log("Match screen mounted");
getMatchList()
}, [activeFilters]);

const getMatchList = () => {
setLoading(true);
setRetry(false);
setError("");
PostMatchList(activeFilters).then(matchList => {
if (matchList != undefined) {
setUserList(matchList);
setUserList(userList.concat(matchList.splice(0, 10)));
setLoading(false);
} else {
navigation.navigate('Public');
Expand All @@ -60,6 +61,7 @@ const Match = () => {
})
}


if (loading) {
return (
<Loading />
Expand All @@ -85,7 +87,7 @@ const Match = () => {
<FilterIconImg source={require('../../../assets/images/icons/sort.png')} />
</FilterIcon>
</Header>
<Swipe userList={userList} />
<Swipe userList={userList} onSwipeCountOffsetThreshold={() => getMatchList()} />

{
filter && (
Expand Down

0 comments on commit 1530289

Please sign in to comment.