mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 22:16:54 +00:00
* basic framework for match/tinder * working version of swiping * working version of profile editing * introducing backend * working matching system * working profile updating * fix all linting issues * updated events to Enum * working profile generation * documentation updates * general PR feedback * working profile loading, matches show matchedAt * slight modification to event strings * added sql imports
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { useRecoilState, useRecoilValue } from 'recoil';
|
|
import { matchState } from './state';
|
|
|
|
import { FormattedProfile, MatchEvents } from '../../../../../typings/match';
|
|
import Nui from '../../../os/nui-events/utils/Nui';
|
|
|
|
interface IUseProfiles {
|
|
profiles: FormattedProfile[];
|
|
activeProfile: FormattedProfile | null;
|
|
setViewed: (index: number, liked: boolean) => void;
|
|
error: boolean;
|
|
}
|
|
|
|
export const useProfiles = (): IUseProfiles => {
|
|
const [profiles, setProfiles] = useRecoilState(matchState.profiles);
|
|
const error = useRecoilValue(matchState.errorLoadingProfiles);
|
|
|
|
const setViewed = (id: number, liked: boolean) => {
|
|
setProfiles((profiles) =>
|
|
profiles.map((profile) => {
|
|
if (id === profile.id) return { ...profile, viewed: true, liked };
|
|
return profile;
|
|
}),
|
|
);
|
|
|
|
Nui.send(MatchEvents.SAVE_LIKES, [{ id, liked }]);
|
|
};
|
|
|
|
const filteredProfiles = profiles ? profiles.filter((profile) => !profile.viewed) : null;
|
|
const activeProfile = profiles ? filteredProfiles[0] : null;
|
|
|
|
return { profiles, activeProfile, error, setViewed };
|
|
};
|