-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…rs on rehydration in the browser. and improved translation component code generally to be DRY (all possible locales are indicated in the graphql type system only now)
- Loading branch information
Showing
9 changed files
with
341 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Translate from '..' | ||
import DialogTitle from '@mui/material/DialogTitle' | ||
import DialogContent from '@mui/material/DialogContent' | ||
import DialogContentText from '@mui/material/DialogContentText' | ||
import DialogActions from '@mui/material/DialogActions' | ||
import Button from '@mui/material/Button' | ||
|
||
export default ({ from }) => { | ||
return ( | ||
<> | ||
<DialogTitle> | ||
<Translate contentId="Language translation" /> | ||
</DialogTitle> | ||
<DialogContent dividers> | ||
<DialogContentText gutterBottom> | ||
<Translate contentId="suggest-translation" />: | ||
</DialogContentText> | ||
<DialogContentText gutterBottom>From: {from}</DialogContentText> | ||
<DialogContentText gutterBottom>To: (TODO - this should be a text field)</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button size="small" variant="contained"> | ||
TODO | ||
</Button> | ||
</DialogActions> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,15 @@ | ||
import Translate from '..' | ||
import { lazy, Suspense } from 'react' | ||
import { Linear as Loading } from '../../../../components/loading' | ||
import Dialog from '@mui/material/Dialog' | ||
import DialogTitle from '@mui/material/DialogTitle' | ||
import DialogContent from '@mui/material/DialogContent' | ||
import DialogContentText from '@mui/material/DialogContentText' | ||
import DialogActions from '@mui/material/DialogActions' | ||
import Button from '@mui/material/Button' | ||
|
||
const Form = lazy(() => import('./_lazy')) | ||
|
||
export default ({ open, setOpen, from }) => { | ||
return ( | ||
<Dialog onClose={() => setOpen(false)} open={open}> | ||
<DialogTitle> | ||
<Translate contentId="Language translation" /> | ||
</DialogTitle> | ||
<DialogContent dividers> | ||
<DialogContentText gutterBottom> | ||
<Translate contentId="suggest-translation" />: | ||
</DialogContentText> | ||
<DialogContentText gutterBottom>From: {from}</DialogContentText> | ||
<DialogContentText gutterBottom>To: (TODO - this should be a text field)</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button size="small" variant="contained"> | ||
TODO | ||
</Button> | ||
</DialogActions> | ||
<Suspense fallback={<Loading />}> | ||
<Form from={from} /> | ||
</Suspense> | ||
</Dialog> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,47 @@ | ||
import { useContext, useState } from 'react' | ||
import { useContext, useState, useEffect, lazy, Suspense } from 'react' | ||
import { ctx as i18nContext } from '../index' | ||
import Box from '@mui/material/Box' | ||
import { Translate } from '../../../components/icons' | ||
import Form from './form' | ||
import Icon from '@mui/material/Icon' | ||
import Tooltip from '@mui/material/Tooltip' | ||
|
||
const Form = lazy(() => import('./form')) | ||
|
||
export default ({ contentId }) => { | ||
const [open, setOpen] = useState(false) | ||
const [isClient, setIsClient] = useState(false) | ||
const { t, language } = useContext(i18nContext) | ||
const { text, missing } = t(contentId, language) | ||
|
||
if (missing) { | ||
return ( | ||
<> | ||
<Tooltip placement="top-end" title="Click to translate!"> | ||
<Box | ||
onClick={() => setOpen(!open)} | ||
sx={{ | ||
position: 'relative', | ||
outline: theme => `thin dotted ${theme.palette.success.main}`, | ||
cursor: 'pointer', | ||
transition: theme => theme.transitions.create(['background-color']), | ||
'&:hover': { | ||
backgroundColor: theme => theme.palette.grey[100], | ||
}, | ||
}} | ||
> | ||
<Icon | ||
component={Translate} | ||
sx={{ | ||
width: '0.65em', | ||
height: '0.65em', | ||
position: 'absolute', | ||
right: 0, | ||
top: 0, | ||
}} | ||
/> | ||
{text} | ||
</Box> | ||
</Tooltip> | ||
<Form from={text} open={open} setOpen={setOpen} /> | ||
</> | ||
) | ||
} | ||
useEffect(() => { | ||
setIsClient(true) | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<Box | ||
component={'span'} | ||
onClick={missing && isClient ? () => setOpen(!open) : () => null} | ||
sx={ | ||
missing && isClient | ||
? { | ||
position: 'relative', | ||
outline: theme => `thin dotted ${theme.palette.success.main}`, | ||
cursor: 'pointer', | ||
transition: theme => theme.transitions.create(['background-color']), | ||
'&:hover': { | ||
backgroundColor: theme => theme.palette.grey[100], | ||
}, | ||
} | ||
: {} | ||
} | ||
> | ||
{text} | ||
</Box> | ||
|
||
return text | ||
{/* CONTENT TRANSLATION */} | ||
{missing && isClient && ( | ||
<Suspense fallback={null}> | ||
<Form from={text} open={open} setOpen={setOpen} /> | ||
</Suspense> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.