Add theme provider for notes

This commit is contained in:
J Francisco Rader committed 2021-02-21 12:49:09 -05:00
1 parent 4acb214ec9
commit 9f04ac3243
13 files changed
+205 -198

No files matched your search

-7
View File
@@ -1,7 +0,0 @@
#notes-app .Mui-focused::after {
border-bottom: 3px solid #f9a825;
}
#notes-app .MuiOutlinedInput-root {
border: 2px soild #f9a825;
}
+33 -39
View File
@@ -4,17 +4,45 @@ import { AppContent } from '../../ui/components/AppContent';
import { AppTitle } from '../../ui/components/AppTitle'; import { AppTitle } from '../../ui/components/AppTitle';
import { useApp } from '../../os/apps/hooks/useApps'; import { useApp } from '../../os/apps/hooks/useApps';
import NoteList from './list/NoteList'; import NoteList from './list/NoteList';
import { useNotes } from './hooks/useNotes';
import { NoteModal } from './modal/NoteModal'; import { NoteModal } from './modal/NoteModal';
import { Fab } from '@material-ui/core'; import { Fab } from '@material-ui/core';
import AddIcon from '@material-ui/icons/Add'; import AddIcon from '@material-ui/icons/Add';
import { useNoteModal } from './hooks/useNoteModal';
import { useNoteDetail } from './hooks/useNoteDetail'; import { useNoteDetail } from './hooks/useNoteDetail';
import useStyles from './notes.styles'; import useStyles from './notes.styles';
import InjectDebugData from '../../os/debug/InjectDebugData'; import InjectDebugData from '../../os/debug/InjectDebugData';
import { NotesThemeProvider } from './providers/NotesThemeProvider';
import { Route, useHistory } from 'react-router-dom';
export const NotesApp = () => {
const classes = useStyles();
const history = useHistory();
const notesApp = useApp('NOTES');
const { setDetail } = useNoteDetail();
const onClickCreate = () => {
setDetail({ title: '', content: '' });
history.push('/notes/detail');
};
return (
<NotesThemeProvider>
<AppWrapper id='notes-app'>
<AppTitle app={notesApp} />
<Route path='/notes/detail' component={NoteModal} />
<AppContent>
<Route path='/notes' component={NoteList} />
<Fab
className={classes.absolute}
onClick={onClickCreate}
color='primary'
>
<AddIcon />
</Fab>
</AppContent>
</AppWrapper>
</NotesThemeProvider>
);
};
InjectDebugData([ InjectDebugData([
{ {
@@ -34,37 +62,3 @@ InjectDebugData([
], ],
}, },
]); ]);
export const NotesApp = () => {
const { setNoteModal } = useNoteModal();
const { detail, setDetail } = useNoteDetail();
const { notes } = useNotes();
const notesApp = useApp('NOTES');
const classes = useStyles();
const handleModal = () => {
setNoteModal(true);
setDetail(null);
};
return (
<AppWrapper id='notes-app'>
<AppTitle app={notesApp} />
<NoteModal key={detail?.id} />
<AppContent>
<NoteList notes={notes} />
</AppContent>
<Fab
className={classes.absolute}
onClick={handleModal}
style={{
background: '#f9a825',
color: '#fff',
}}
>
<AddIcon />
</Fab>
</AppWrapper>
);
};
+18 -6
View File
@@ -1,18 +1,30 @@
import React from 'react'; import React from 'react';
import { yellow } from '@material-ui/core/colors'; import { makeStyles, Paper } from '@material-ui/core';
import useStyles from './notes.styles';
import { Paper } from '@material-ui/core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faStickyNote } from '@fortawesome/free-solid-svg-icons'; import { faStickyNote } from '@fortawesome/free-solid-svg-icons';
const useStyles = makeStyles((theme) => ({
header: {
width: '100%',
display: 'flex',
flexFlow: 'row nowrap',
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center',
height: '60px',
},
icon: {
color: theme.palette.primary.main,
fontSize: 40,
},
}));
const NotesTitle = () => { const NotesTitle = () => {
const classes = useStyles(); const classes = useStyles();
return ( return (
<Paper elevation={24} square variant='outlined' className={classes.header}> <Paper elevation={24} square variant='outlined' className={classes.header}>
<FontAwesomeIcon icon={faStickyNote} color={yellow[800]} size='lg' /> <FontAwesomeIcon icon={faStickyNote} className={classes.icon} size='lg' />
</Paper> </Paper>
); );
}; };
@@ -1,12 +0,0 @@
import { useRecoilState } from 'recoil';
import { noteStates } from './state';
interface NoteModalProps {
noteModal: boolean;
setNoteModal: (show: boolean) => void;
}
export const useNoteModal = (): NoteModalProps => {
const [noteModal, setNoteModal] = useRecoilState(noteStates.noteModal);
return { noteModal, setNoteModal };
};
+7 -6
View File
@@ -1,18 +1,19 @@
import { List, ListItem, ListItemText } from '@material-ui/core';
import React from 'react'; import React from 'react';
import { List, ListItem, ListItemText } from '@material-ui/core';
import { useNoteModal } from '../hooks/useNoteModal';
import { useNoteDetail } from '../hooks/useNoteDetail'; import { useNoteDetail } from '../hooks/useNoteDetail';
import { useNotes } from '../hooks/useNotes';
import { useHistory } from 'react-router-dom';
// add search bar later // add search bar later
// TODO: Add interface for note // TODO: Add interface for note
const NoteList = ({ notes }) => { const NoteList = () => {
const { setNoteModal } = useNoteModal(); const history = useHistory();
const { notes } = useNotes();
const { setDetail } = useNoteDetail(); const { setDetail } = useNoteDetail();
const handleNoteModal = (note) => { const handleNoteModal = (note) => {
setNoteModal(true);
setDetail(note); setDetail(note);
history.push('/notes/detail');
}; };
return ( return (
+107 -89
View File
@@ -1,41 +1,38 @@
import { Button, TextField, Slide } from '@material-ui/core'; import {
import React, { useState } from 'react'; Button,
TextField,
Slide,
Paper,
Typography,
Container,
CircularProgress,
Box,
} from '@material-ui/core';
import React from 'react';
import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import ArrowBackIcon from '@material-ui/icons/ArrowBack';
import { useNoteModal } from '../hooks/useNoteModal';
import { useNoteDetail } from '../hooks/useNoteDetail'; import { useNoteDetail } from '../hooks/useNoteDetail';
import useStyles from './modal.styles'; import useStyles from './modal.styles';
import '../NotesApp.css';
import Nui from '../../../os/nui-events/utils/Nui'; import Nui from '../../../os/nui-events/utils/Nui';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
// TODO: Fix input focus color
export const NoteModal = () => { export const NoteModal = () => {
const { noteModal, setNoteModal } = useNoteModal(); const classes = useStyles();
const history = useHistory();
const { t } = useTranslation();
const { detail, setDetail } = useNoteDetail(); const { detail, setDetail } = useNoteDetail();
const [title, setTitle] = useState(detail ? detail.title : '');
const [content, setContent] = useState(detail ? detail.content : '');
const classes = useStyles() const onClose = () => history.goBack();
const _handleClose = () => { const _handleClose = () => {
setDetail(null); setDetail(null);
setNoteModal(false); onClose();
}; };
const handleNoteSave = () => { const handleNoteSave = () => {
Nui.send('phone:addNote', { Nui.send('phone:addNote', detail);
title,
content,
});
setDetail(null); setDetail(null);
setNoteModal(false); onClose();
setTitle('')
setContent('')
}; };
const handleDeleteNote = () => { const handleDeleteNote = () => {
@@ -44,78 +41,99 @@ export const NoteModal = () => {
id, id,
}); });
setDetail(null); setDetail(null);
setNoteModal(false); onClose();
}; };
const handleUpdateNote = () => { const handleUpdateNote = () => {
Nui.send('phone:updateNote', { Nui.send('phone:updateNote', detail);
id: detail.id,
title,
content,
});
setDetail(null); setDetail(null);
setNoteModal(false); onClose();
}; };
return ( return (
<div className={noteModal ? classes.modalRoot : classes.modalHide}> <Slide direction='left' in={!!detail}>
<Slide direction='left' in={noteModal} mountOnEnter unmountOnExit> <Paper className={classes.modalRoot}>
<div> {!detail ? (
<Button className={classes.closeButton} onClick={_handleClose}> <CircularProgress />
<ArrowBackIcon fontSize='large' /> ) : (
</Button> <Container>
<div id='notes-modal' className={classes.noteContainer}> <Box>
<TextField <Box py={2}>
className={classes.input} <Button
rowsMax={1} color='primary'
placeholder='Title' size='large'
inputProps={{ startIcon={<ArrowBackIcon fontSize='large' />}
className: classes.inputPropsTitle, onClick={_handleClose}
maxLength: 25 >
}} {t('APPS_NOTES')}
fullWidth </Button>
value={title} </Box>
onChange={(e) => setTitle(e.target.value)} <TextField
/> className={classes.input}
<TextField rowsMax={1}
className={classes.input} label={t('GENERIC_TITLE')}
inputProps={{ inputProps={{
className: classes.inputPropsContent, className: classes.inputPropsTitle,
maxLength: 250, maxLength: 25,
}} }}
placeholder='Content' fullWidth
multiline value={detail.title}
fullWidth onChange={(e) =>
rows={19} setDetail((d) => ({ ...d, title: e.target.value }))
variant='outlined' }
value={content} />
onChange={(e) => setContent(e.target.value)} <TextField
/> className={classes.input}
<p style={{ color: "#fff" }}>{content.length}/250</p> inputProps={{
{!detail &&( className: classes.inputPropsContent,
<Button disabled={title.length > 0 ? false : true} className={classes.saveButton} onClick={handleNoteSave}> maxLength: 250,
Save }}
</Button> label={t('GENERIC_CONTENT')}
)} multiline
{detail && ( fullWidth
<Button rows={16}
className={classes.updateButton} variant='outlined'
onClick={handleUpdateNote} value={detail.content}
> onChange={(e) =>
Update setDetail((d) => ({ ...d, content: e.target.value }))
</Button> }
)} />
{detail && ( <Typography paragraph>{detail.content.length}/250</Typography>
<Button {!detail.id && (
className={classes.deleteButton} <Button
onClick={handleDeleteNote} color='primary'
> variant='contained'
Delete disabled={detail.title.length > 0 ? false : true}
</Button> className={classes.saveButton}
)} onClick={handleNoteSave}
</div> >
</div> {t('GENERIC_SAVE')}
</Slide> </Button>
</div> )}
{!!detail.id && (
<>
<Button
color='primary'
variant='contained'
className={classes.updateButton}
onClick={handleUpdateNote}
>
{t('GENERIC_UPDATE')}
</Button>
<Button
color='secondary'
variant='contained'
className={classes.deleteButton}
onClick={handleDeleteNote}
>
{t('GENERIC_DELETE')}
</Button>
</>
)}
</Box>
</Container>
)}
</Paper>
</Slide>
); );
}; };
+2 -18
View File
@@ -6,21 +6,7 @@ const useStyles = makeStyles((theme) => ({
position: 'absolute', position: 'absolute',
height: '100%', height: '100%',
width: '100%', width: '100%',
background: '#232323', background: theme.palette.background.default,
},
modalHide: {
display: 'none',
},
closeButton: {
width: '10%',
position: 'absolute',
top: 10,
left: 0,
},
noteContainer: {
width: '90%',
marginTop: 80,
margin: '0 auto',
}, },
input: { input: {
marginBottom: 20, marginBottom: 20,
@@ -30,18 +16,16 @@ const useStyles = makeStyles((theme) => ({
}, },
inputPropsContent: { inputPropsContent: {
fontSize: 20, fontSize: 20,
lineHeight: 1.2
}, },
saveButton: { saveButton: {
background: '#f9a825',
padding: '10px 30px', padding: '10px 30px',
}, },
updateButton: { updateButton: {
background: '#f9a825',
padding: '10px 30px', padding: '10px 30px',
marginRight: '8px', marginRight: '8px',
}, },
deleteButton: { deleteButton: {
background: '#c62828',
padding: '10px 30px', padding: '10px 30px',
}, },
})); }));
-9
View File
@@ -1,15 +1,6 @@
import { makeStyles } from '@material-ui/core'; import { makeStyles } from '@material-ui/core';
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
header: {
width: '100%',
display: 'flex',
flexFlow: 'row nowrap',
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center',
height: '60px',
},
backgroundModal: { backgroundModal: {
background: 'black', background: 'black',
opacity: '0.6', opacity: '0.6',
+17
View File
@@ -0,0 +1,17 @@
import { common, yellow } from "@material-ui/core/colors";
export const NOTES_APP_PRIMARY_COLOR = yellow[800];
export const NOTES_APP_TEXT_COLOR = common.black;
const theme = {
palette: {
primary: {
main: NOTES_APP_PRIMARY_COLOR,
dark: yellow[900],
light: yellow[500],
contrastText: NOTES_APP_TEXT_COLOR
}
}
}
export default theme;
@@ -0,0 +1,4 @@
import { createAppThemeProvider } from "../../../os/apps/utils/createAppThemeProvider";
import notesTheme from '../notes.theme';
export const NotesThemeProvider = createAppThemeProvider(notesTheme);
+8 -5
View File
@@ -1,12 +1,15 @@
import { common } from "@material-ui/core/colors"; import { common, red } from "@material-ui/core/colors";
export const SELLOUT_APP_PRIMARY_COLOR = red[500];
export const SELLOUT_APP_TEXT_COLOR = common.black;
const theme = { const theme = {
palette: { palette: {
primary: { primary: {
main: '#f44336', main: SELLOUT_APP_PRIMARY_COLOR,
dark: '#b3251b', dark: red[700],
light: 'f87f76', light: red[200],
contrastText: common.black contrastText: SELLOUT_APP_TEXT_COLOR
} }
} }
} }
+3 -1
View File
@@ -106,6 +106,8 @@
"GENERIC_SAVE": "Save", "GENERIC_SAVE": "Save",
"GENERIC_UPDATE": "Update", "GENERIC_UPDATE": "Update",
"GENERIC_DELETE": "Delete", "GENERIC_DELETE": "Delete",
"GENERIC_CLOSE": "Close" "GENERIC_CLOSE": "Close",
"GENERIC_TITLE": "Title",
"GENERIC_CONTENT": "Content"
} }
} }
+6 -6
View File
@@ -5,8 +5,6 @@ import {
grey, grey,
green, green,
purple, purple,
yellow,
red,
} from '@material-ui/core/colors'; } from '@material-ui/core/colors';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { import {
@@ -43,6 +41,8 @@ import {
CONTACTS_APP_PRIMARY_COLOR, CONTACTS_APP_PRIMARY_COLOR,
CONTACTS_APP_TEXT_COLOR, CONTACTS_APP_TEXT_COLOR,
} from '../../../apps/contacts/contacts.theme'; } from '../../../apps/contacts/contacts.theme';
import { SELLOUT_APP_PRIMARY_COLOR, SELLOUT_APP_TEXT_COLOR } from '../../../apps/sellout/sellout.theme';
import { NOTES_APP_PRIMARY_COLOR, NOTES_APP_TEXT_COLOR } from '../../../apps/notes/notes.theme';
export interface IAppConfig { export interface IAppConfig {
id: string; id: string;
@@ -141,8 +141,8 @@ export const APPS: IAppConfig[] = [
nameLocale: 'APPS_SELLOUT', nameLocale: 'APPS_SELLOUT',
icon: <FontAwesomeIcon icon={faAd} fixedWidth />, icon: <FontAwesomeIcon icon={faAd} fixedWidth />,
notificationIcon: <FontAwesomeIcon icon={faAd} fixedWidth size='xs' />, notificationIcon: <FontAwesomeIcon icon={faAd} fixedWidth size='xs' />,
backgroundColor: red[500], backgroundColor: SELLOUT_APP_PRIMARY_COLOR,
color: common.white, color: SELLOUT_APP_TEXT_COLOR,
path: '/sellout', path: '/sellout',
Route: () => ( Route: () => (
<AppRoute id='SELLOUT' path='/sellout' component={SelloutApp} /> <AppRoute id='SELLOUT' path='/sellout' component={SelloutApp} />
@@ -155,8 +155,8 @@ export const APPS: IAppConfig[] = [
notificationIcon: ( notificationIcon: (
<FontAwesomeIcon icon={faStickyNote} fixedWidth size='xs' /> <FontAwesomeIcon icon={faStickyNote} fixedWidth size='xs' />
), ),
backgroundColor: yellow[800], backgroundColor: NOTES_APP_PRIMARY_COLOR,
color: common.white, color: NOTES_APP_TEXT_COLOR,
path: '/notes', path: '/notes',
Route: () => <AppRoute id='NOTES' path='/notes' component={NotesApp} />, Route: () => <AppRoute id='NOTES' path='/notes' component={NotesApp} />,
}, },