From da32d2ca35fc25f165ff9dcd282e45915118c117 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 11 Dec 2020 22:01:16 +0100 Subject: [PATCH] feat(contacts/nui): alert on actions --- .../apps/contacts/components/ContactsApp.tsx | 46 ++++++++++--------- phone/src/apps/contacts/hooks/useAlert.ts | 8 ++++ .../apps/contacts/hooks/useContactsService.ts | 15 +++--- phone/src/common/interfaces/contact.ts | 4 ++ 4 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 phone/src/apps/contacts/hooks/useAlert.ts create mode 100644 phone/src/common/interfaces/contact.ts diff --git a/phone/src/apps/contacts/components/ContactsApp.tsx b/phone/src/apps/contacts/components/ContactsApp.tsx index 7ef050c..2357026 100644 --- a/phone/src/apps/contacts/components/ContactsApp.tsx +++ b/phone/src/apps/contacts/components/ContactsApp.tsx @@ -1,25 +1,26 @@ -import React from "react"; -import { AppWrapper } from "../../../ui/components"; -import { makeStyles, createStyles, Theme } from "@material-ui/core/styles"; -import { AppTitle } from "../../../ui/components/AppTitle"; -import { AppContent } from "../../../ui/components/AppContent"; -import { ContactList } from "./List/ContactList"; -import { useApp } from "../../../os/apps/hooks/useApps"; -import { AddContactModal } from "./ContactModal"; -import { useModal } from "../hooks/useModal"; -import { SearchContacts } from "./List/SearchContacts"; -import PersonAddIcon from "@material-ui/icons/PersonAdd"; -import Fab from "@material-ui/core/Fab"; -import { useContactModal } from "../hooks/useContactModal"; -import { InfoModal } from "./modal/InfoModal"; -import { useContactDetail } from "../hooks/useContactDetail"; +import React from 'react'; +import { AppWrapper } from '../../../ui/components'; +import { makeStyles, createStyles, Theme } from '@material-ui/core/styles'; +import { AppTitle } from '../../../ui/components/AppTitle'; +import { AppContent } from '../../../ui/components/AppContent'; +import { ContactList } from './List/ContactList'; +import { useApp } from '../../../os/apps/hooks/useApps'; +import { AddContactModal } from './ContactModal'; +import { useModal } from '../hooks/useModal'; +import { SearchContacts } from './List/SearchContacts'; +import PersonAddIcon from '@material-ui/icons/PersonAdd'; +import Fab from '@material-ui/core/Fab'; +import { useContactModal } from '../hooks/useContactModal'; +import { InfoModal } from './modal/InfoModal'; +import { useContactDetail } from '../hooks/useContactDetail'; +import { ContactAlert } from './alert/ContactAlert'; const useStyles = makeStyles((theme: Theme) => createStyles({ backgroundModal: { - background: "black", - opacity: "0.6", - position: "absolute", + background: 'black', + opacity: '0.6', + position: 'absolute', top: 0, left: 0, right: 0, @@ -27,7 +28,7 @@ const useStyles = makeStyles((theme: Theme) => zIndex: 5, }, absolute: { - position: "sticky", + position: 'sticky', bottom: theme.spacing(2), left: theme.spacing(3), }, @@ -37,7 +38,7 @@ const useStyles = makeStyles((theme: Theme) => export const ContactsApp = () => { const classes = useStyles(); const { showModal, setShowModal } = useModal(); - const contacts = useApp("CONTACTS"); + const contacts = useApp('CONTACTS'); const { contactDetail } = useContactDetail(); const openModal = () => { @@ -45,7 +46,7 @@ export const ContactsApp = () => { }; return ( - + @@ -55,11 +56,12 @@ export const ContactsApp = () => { + ); diff --git a/phone/src/apps/contacts/hooks/useAlert.ts b/phone/src/apps/contacts/hooks/useAlert.ts new file mode 100644 index 0000000..028fe3b --- /dev/null +++ b/phone/src/apps/contacts/hooks/useAlert.ts @@ -0,0 +1,8 @@ +import { useRecoilState } from 'recoil'; +import { IContactAlert } from '../../../common/interfaces/contact'; +import { contactsState } from './state'; + +export const useContactAlert = (): IContactAlert => { + const [alert, setAlert] = useRecoilState(contactsState.contactAlert); + return { alert, setAlert }; +}; diff --git a/phone/src/apps/contacts/hooks/useContactsService.ts b/phone/src/apps/contacts/hooks/useContactsService.ts index a959c87..82a985d 100644 --- a/phone/src/apps/contacts/hooks/useContactsService.ts +++ b/phone/src/apps/contacts/hooks/useContactsService.ts @@ -1,10 +1,13 @@ -import { useNuiEvent } from "../../../os/nui-events/hooks/useNuiEvent"; -import { useSetRecoilState } from "recoil"; -import { contactsState } from "./state"; -import { useContacts } from "./useContacts"; +import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; +import { useSetRecoilState } from 'recoil'; +import { contactsState } from './state'; +import { useContacts } from './useContacts'; +import { useContactAlert } from './useAlert'; export const useContactsService = () => { const setContacts = useSetRecoilState(contactsState.contacts); - useNuiEvent("CONTACTS", "setContacts", setContacts); - return useContacts(); + const setAlert = useSetRecoilState(contactsState.contactAlert); + useNuiEvent('CONTACTS', 'setContacts', setContacts); + useNuiEvent('CONTACTS', 'setAlert', setAlert); + return { useContacts, useContactAlert }; }; diff --git a/phone/src/common/interfaces/contact.ts b/phone/src/common/interfaces/contact.ts new file mode 100644 index 0000000..fa46e10 --- /dev/null +++ b/phone/src/common/interfaces/contact.ts @@ -0,0 +1,4 @@ +export interface IContactAlert { + alert: string; + setAlert: (type: string) => void; +}