mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
cleanup: Recoil State Type Safety + Misc Cleanup (#189)
* chore(phone/settings): Removed unused state * cleanup(phone/photos): Added type safety to photo state * tweak(phone/marketplace): Added type safety to marketplace state * chore(phone/match): Removed unnecessary console.log * tweak(phone/messages): Added type safety to messages state Also fixed ESLint warning for exported anonymous hook in useMessages.ts * tweak(phone/match): Added type safety to match state * tweak(phone/dialer): Cleanup & type safety for state Renamed some types to better represent their data * cleanup(phone/gen): Added NUI event enums for phone events * tweak(phone/contacts): Type safety for contacts state & variable rename Renamed and type variable in setFilteredContacts to better represent its use * tweak(phone/gen-state): Added type-safety to gen phone global state * tweak(phone/settings): Type safety for settings state * tweak(phone/photos): Tweaked type for photo referral * fix(phone/notification-comp): Fix reference to old theme config * chore(phone/hooks): Remove keyboard service Removed as this was unused and ESLint was not happy with it * chore(phone): Cleaned up eslint warnings No more warnings hooray! * tweak(phone): Set time in dev mode * fix(phone): Remove useNuiService that appeared somehow * fix(phone/gallery): Fixed missing import for gallery * Revert removing the keyboard service as this is built upon in another PR This reverts commit 82d12255a84e918da087d988b599af98ce1fe54d. * fix(phone/keyboard): Add useKeyboardService hook back to Phone.tsx * fix(phone/gallery): Fix and standardized GalleryPhoto type
This commit is contained in:
35 files changed
+137
-148
No files matched your search
@@ -6,9 +6,8 @@ import DeleteIcon from '@material-ui/icons/Delete';
|
||||
import ShareIcon from '@material-ui/icons/Share';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { ICameraPhoto } from '../../hooks/useCamera';
|
||||
import { ShareModal } from './ShareModal';
|
||||
import { PhotoEvents } from '../../../../../../typings/photo';
|
||||
import { GalleryPhoto, PhotoEvents } from '../../../../../../typings/photo';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
|
||||
export const GalleryModal = () => {
|
||||
@@ -20,8 +19,8 @@ export const GalleryModal = () => {
|
||||
|
||||
const [shareOpen, setShareOpen] = useState(null);
|
||||
|
||||
const meta: ICameraPhoto = useMemo(
|
||||
() => ({ id: query.id as string, image: query.image as string }),
|
||||
const meta: GalleryPhoto = useMemo(
|
||||
() => ({ id: parseInt(query.id), image: query.image as string }),
|
||||
[query],
|
||||
);
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ import MessageIcon from '@material-ui/icons/Message';
|
||||
import { setClipboard } from '../../../../os/phone/hooks/useClipboard';
|
||||
|
||||
import useStyles from './modal.styles';
|
||||
import { ICameraPhoto } from '../../hooks/useCamera';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { GalleryPhoto } from '../../../../../../typings/photo';
|
||||
|
||||
interface IShareModalProps {
|
||||
meta: ICameraPhoto;
|
||||
meta: GalleryPhoto;
|
||||
referal: string;
|
||||
onClose(): void;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { atom } from 'recoil';
|
||||
import { GalleryPhoto } from '../../../../../typings/photo';
|
||||
|
||||
export const photoState = {
|
||||
photos: atom({
|
||||
photos: atom<GalleryPhoto[]>({
|
||||
key: 'galleryPhotos',
|
||||
default: [],
|
||||
}),
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { SetterOrUpdater, useRecoilState } from 'recoil';
|
||||
import { PhotoEvents } from '../../../../../typings/photo';
|
||||
import { useNuiEvent, useNuiCallback } from 'fivem-nui-react-lib/dist/index';
|
||||
import { GalleryPhoto, PhotoEvents } from '../../../../../typings/photo';
|
||||
import { useNuiEvent, useNuiCallback } from 'fivem-nui-react-lib/';
|
||||
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { photoState } from './state';
|
||||
|
||||
export interface ICameraPhoto {
|
||||
id: string;
|
||||
image: string;
|
||||
}
|
||||
|
||||
interface IUseCamera {
|
||||
photos: ICameraPhoto[];
|
||||
setPhotos: SetterOrUpdater<ICameraPhoto[]>;
|
||||
photos: GalleryPhoto[];
|
||||
setPhotos: SetterOrUpdater<GalleryPhoto[]>;
|
||||
takePhoto: () => void;
|
||||
isLoading: boolean;
|
||||
}
|
||||
@@ -22,7 +17,7 @@ export const useCamera = (): IUseCamera => {
|
||||
const { t } = useTranslation();
|
||||
const { addAlert } = useSnackbar();
|
||||
|
||||
const [photos, setPhotos] = useRecoilState<ICameraPhoto[] | null>(photoState.photos);
|
||||
const [photos, setPhotos] = useRecoilState<GalleryPhoto[]>(photoState.photos);
|
||||
|
||||
const [isUploading, setUploading] = useState(false);
|
||||
|
||||
@@ -43,7 +38,7 @@ export const useCamera = (): IUseCamera => {
|
||||
[addAlert, t],
|
||||
);
|
||||
|
||||
const [_takePhoto] = useNuiCallback<void, ICameraPhoto>(
|
||||
const [_takePhoto] = useNuiCallback<void, GalleryPhoto>(
|
||||
'CAMERA',
|
||||
PhotoEvents.TAKE_PHOTO,
|
||||
onPhotoSuccess,
|
||||
|
||||
@@ -1,24 +1,17 @@
|
||||
import { atom } from 'recoil';
|
||||
import { Contact } from '../../../../../typings/contact';
|
||||
|
||||
export const contactsState = {
|
||||
contacts: atom({
|
||||
contacts: atom<Contact[]>({
|
||||
key: 'contactsList',
|
||||
default: [],
|
||||
}),
|
||||
showModal: atom({
|
||||
showModal: atom<boolean>({
|
||||
key: 'showModal',
|
||||
default: false,
|
||||
}),
|
||||
filterContacts: atom({
|
||||
filterContacts: atom<string>({
|
||||
key: 'filterContacts',
|
||||
default: '',
|
||||
}),
|
||||
showContactsModal: atom({
|
||||
key: 'showContactModal',
|
||||
default: false,
|
||||
}),
|
||||
contactDetail: atom({
|
||||
key: 'contactDetail',
|
||||
default: null,
|
||||
}),
|
||||
};
|
||||
@@ -3,7 +3,7 @@ import { contactsState } from './state';
|
||||
|
||||
interface FilterdContactsProps {
|
||||
filteredContacts: string;
|
||||
setFilteredContacts: (contact: any) => void;
|
||||
setFilteredContacts: (searchTerm: string) => void;
|
||||
}
|
||||
|
||||
export const useFilteredContacts = (): FilterdContactsProps => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ListItem } from '../../../../ui/components/ListItem';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
||||
import { CallEvents, ICall } from '../../../../../../typings/call';
|
||||
import { CallEvents, CallHistoryItem } from '../../../../../../typings/call';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
@@ -56,7 +56,7 @@ export const DialerHistory = ({ calls }) => {
|
||||
|
||||
return (
|
||||
<List disablePadding>
|
||||
{calls.map((call: ICall) =>
|
||||
{calls.map((call: CallHistoryItem) =>
|
||||
call.transmitter === myNumber ? (
|
||||
<ListItem key={call.id} divider>
|
||||
<ListItemIcon>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { atom } from 'recoil';
|
||||
import { CallHistoryItem } from '../../../../../typings/call';
|
||||
|
||||
export const dialState = {
|
||||
history: atom({
|
||||
history: atom<CallHistoryItem[]>({
|
||||
key: 'dialHistory',
|
||||
default: [],
|
||||
}),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { ICall } from '../../../../../typings/call';
|
||||
import { dialState } from './state';
|
||||
|
||||
export const useDialHistory = () => {
|
||||
return useRecoilValue<ICall[]>(dialState.history);
|
||||
return useRecoilValue(dialState.history);
|
||||
};
|
||||
@@ -1,7 +1,8 @@
|
||||
import { atom } from 'recoil';
|
||||
import { MarketplaceListing } from '../../../../../typings/marketplace';
|
||||
|
||||
export const selloutState = {
|
||||
listing: atom({
|
||||
listing: atom<MarketplaceListing[]>({
|
||||
key: 'listing',
|
||||
default: [],
|
||||
}),
|
||||
|
||||
@@ -15,8 +15,6 @@ const useStyles = makeStyles({
|
||||
export function MatchBottomNavigation({ activePage, handleChange }) {
|
||||
const classes = useStyles();
|
||||
|
||||
console.log(activePage);
|
||||
|
||||
return (
|
||||
<BottomNavigation value={activePage} onChange={handleChange} className={classes.root}>
|
||||
<BottomNavigationAction component={Link} to="/match" icon={<HomeIcon />} />
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { atom } from 'recoil';
|
||||
import { FormattedMatch, FormattedProfile } from '../../../../../typings/match';
|
||||
|
||||
export const matchState = {
|
||||
profiles: atom({
|
||||
profiles: atom<FormattedProfile[]>({
|
||||
key: 'profiles',
|
||||
default: null,
|
||||
}),
|
||||
@@ -9,19 +10,19 @@ export const matchState = {
|
||||
key: 'errorLoadingProfiles',
|
||||
default: false,
|
||||
}),
|
||||
matches: atom({
|
||||
matches: atom<FormattedMatch[]>({
|
||||
key: 'matches',
|
||||
default: null,
|
||||
}),
|
||||
errorLoadingMatches: atom({
|
||||
errorLoadingMatches: atom<boolean>({
|
||||
key: 'errorLoadingMatches',
|
||||
default: false,
|
||||
}),
|
||||
myProfile: atom({
|
||||
myProfile: atom<FormattedProfile | null>({
|
||||
key: 'myProfile',
|
||||
default: null,
|
||||
}),
|
||||
noProfileExists: atom({
|
||||
noProfileExists: atom<boolean>({
|
||||
key: 'noProfileExists',
|
||||
default: false,
|
||||
}),
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
import { atom } from 'recoil';
|
||||
import { CreateMessageGroupResult, Message, MessageGroup } from '../../../../../typings/messages';
|
||||
|
||||
export const messageState = {
|
||||
messageGroups: atom({
|
||||
messageGroups: atom<MessageGroup[]>({
|
||||
key: 'messageGroups',
|
||||
default: null,
|
||||
default: [],
|
||||
}),
|
||||
messages: atom({
|
||||
messages: atom<Message[]>({
|
||||
key: 'messages',
|
||||
default: null,
|
||||
}),
|
||||
activeMessageGroup: atom({
|
||||
activeMessageGroup: atom<MessageGroup>({
|
||||
key: 'activeMessageGroup',
|
||||
default: null,
|
||||
}),
|
||||
showNewMessageGroup: atom({
|
||||
showNewMessageGroup: atom<boolean>({
|
||||
key: 'showNewMessageGroup',
|
||||
default: false,
|
||||
}),
|
||||
createMessageGroupResult: atom({
|
||||
createMessageGroupResult: atom<CreateMessageGroupResult>({
|
||||
key: 'createMessageGroupResult',
|
||||
default: null,
|
||||
}),
|
||||
imageModal: atom({
|
||||
imageModal: atom<boolean>({
|
||||
key: 'useImageModal',
|
||||
default: false,
|
||||
}),
|
||||
unreadMessagesCount: atom({
|
||||
unreadMessagesCount: atom<number>({
|
||||
key: 'unreadMessagesCount',
|
||||
default: 0,
|
||||
})
|
||||
}),
|
||||
};
|
||||
@@ -72,6 +72,6 @@ const useMessages = (): IUseMessages => {
|
||||
setActiveMessageGroup,
|
||||
goToConversation,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export default useMessages;
|
||||
@@ -104,7 +104,7 @@ const localStorageEffect = (key) => ({ setSelf, onSet }) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const settingsState = atom({
|
||||
export const settingsState = atom<IPhoneSettings>({
|
||||
key: 'settings',
|
||||
default: config.defaultSettings,
|
||||
effects_UNSTABLE: [localStorageEffect(NPWD_STORAGE_KEY)],
|
||||
|
||||
Reference in new issue
Block a user