Loading mobile/src/profile/hooks/useChangeInterests.ts 0 → 100644 +33 −0 Original line number Diff line number Diff line import { useEffect, useState } from "react"; import { useGetInterests } from "./useGetInterests"; import { IOption } from "../../common/domain/entities/option"; import { ApiRequestStatus } from "../../common/constants/api_request_states"; import { useDataContext } from "../../common/contexts/data_context"; export const useChangeInterests = () => { const { profileRepository } = useDataContext(); const [interests, setInterests] = useState<IOption[]>([]); const toogleInterest = (id: number) => { const newInterests = interests.map((interest) => { if (interest.id === id) { return { ...interest, isSelected: !interest.isSelected }; } return interest; }); setInterests(newInterests); }; const onSubmit = async () => { const selectedInterests = interests .filter((interest) => interest.isSelected); await profileRepository!.saveInterests(selectedInterests); }; const setAllInterests = (interests: IOption[]) => { setInterests(interests); }; return { toogleInterest, interests, onSubmit, setAllInterests }; }; Loading
mobile/src/profile/hooks/useChangeInterests.ts 0 → 100644 +33 −0 Original line number Diff line number Diff line import { useEffect, useState } from "react"; import { useGetInterests } from "./useGetInterests"; import { IOption } from "../../common/domain/entities/option"; import { ApiRequestStatus } from "../../common/constants/api_request_states"; import { useDataContext } from "../../common/contexts/data_context"; export const useChangeInterests = () => { const { profileRepository } = useDataContext(); const [interests, setInterests] = useState<IOption[]>([]); const toogleInterest = (id: number) => { const newInterests = interests.map((interest) => { if (interest.id === id) { return { ...interest, isSelected: !interest.isSelected }; } return interest; }); setInterests(newInterests); }; const onSubmit = async () => { const selectedInterests = interests .filter((interest) => interest.isSelected); await profileRepository!.saveInterests(selectedInterests); }; const setAllInterests = (interests: IOption[]) => { setInterests(interests); }; return { toogleInterest, interests, onSubmit, setAllInterests }; };