- Notifications
You must be signed in to change notification settings - Fork928
feat: Add emoji picker to group settings#4685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import data from "@emoji-mart/data/sets/14/twitter.json" | ||
import Picker from "@emoji-mart/react" | ||
import Button from "@material-ui/core/Button" | ||
import InputAdornment from "@material-ui/core/InputAdornment" | ||
import Popover from "@material-ui/core/Popover" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import TextField from "@material-ui/core/TextField" | ||
import { Group } from "api/typesGenerated" | ||
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne" | ||
import { OpenDropdown } from "components/DropdownArrows/DropdownArrows" | ||
import { FormFooter } from "components/FormFooter/FormFooter" | ||
import { FullPageForm } from "components/FullPageForm/FullPageForm" | ||
import { FullScreenLoader } from "components/Loader/FullScreenLoader" | ||
import { Margins } from "components/Margins/Margins" | ||
import { useFormik } from "formik" | ||
import React, { useRef, useState } from "react" | ||
import { colors } from "theme/colors" | ||
import { getFormHelpers, nameValidator, onChangeTrimmed } from "util/formUtils" | ||
import * as Yup from "yup" | ||
@@ -26,6 +34,7 @@ const UpdateGroupForm: React.FC<{ | ||
onCancel: () => void | ||
isLoading: boolean | ||
}> = ({ group, errors, onSubmit, onCancel, isLoading }) => { | ||
const [isEmojiPickerOpen, setIsEmojiPickerOpen] = useState(false) | ||
const form = useFormik<FormData>({ | ||
initialValues: { | ||
name: group.name, | ||
@@ -35,6 +44,10 @@ const UpdateGroupForm: React.FC<{ | ||
onSubmit, | ||
}) | ||
const getFieldHelpers = getFormHelpers<FormData>(form, errors) | ||
const hasIcon = form.values.avatar_url && form.values.avatar_url !== "" | ||
const emojiButtonRef = useRef<HTMLButtonElement>(null) | ||
const styles = useStyles() | ||
const { t } = useTranslation("common") | ||
return ( | ||
<FullPageForm title="Group settings" onCancel={onCancel}> | ||
@@ -53,9 +66,60 @@ const UpdateGroupForm: React.FC<{ | ||
onChange={onChangeTrimmed(form)} | ||
autoFocus | ||
fullWidth | ||
label="Icon" | ||
variant="outlined" | ||
InputProps={{ | ||
endAdornment: hasIcon ? ( | ||
<InputAdornment position="end"> | ||
<img | ||
alt="" | ||
src={form.values.avatar_url} | ||
className={styles.adornment} | ||
// This prevent browser to display the ugly error icon if the | ||
// image path is wrong or user didn't finish typing the url | ||
onError={(e) => (e.currentTarget.style.display = "none")} | ||
onLoad={(e) => (e.currentTarget.style.display = "inline")} | ||
/> | ||
</InputAdornment> | ||
) : undefined, | ||
}} | ||
/> | ||
<Button | ||
fullWidth | ||
ref={emojiButtonRef} | ||
variant="outlined" | ||
size="small" | ||
endIcon={<OpenDropdown />} | ||
onClick={() => { | ||
setIsEmojiPickerOpen((v) => !v) | ||
}} | ||
> | ||
{t("emojiPicker.select")} | ||
</Button> | ||
<Popover | ||
id="emoji" | ||
open={isEmojiPickerOpen} | ||
anchorEl={emojiButtonRef.current} | ||
onClose={() => { | ||
setIsEmojiPickerOpen(false) | ||
}} | ||
> | ||
<Picker | ||
theme="dark" | ||
data={data} | ||
onEmojiSelect={(emojiData) => { | ||
form | ||
.setFieldValue("avatar_url", `/emojis/${emojiData.unified}.png`) | ||
.catch((ex) => { | ||
console.error(ex) | ||
}) | ||
setIsEmojiPickerOpen(false) | ||
}} | ||
/> | ||
</Popover> | ||
<FormFooter onCancel={onCancel} isLoading={isLoading} /> | ||
</form> | ||
</FullPageForm> | ||
@@ -100,4 +164,21 @@ export const SettingsGroupPageView: React.FC<SettingsGroupPageViewProps> = ({ | ||
) | ||
} | ||
const useStyles = makeStyles((theme) => ({ | ||
"@global": { | ||
"em-emoji-picker": { | ||
"--rgb-background": theme.palette.background.paper, | ||
"--rgb-input": colors.gray[17], | ||
"--rgb-color": colors.gray[4], | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Do we want to add this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I just copied this from the template settings one, but I assume we'll abstract this (maybe once it's used once more?). Member
| ||
}, | ||
adornment: { | ||
width: theme.spacing(3), | ||
height: theme.spacing(3), | ||
}, | ||
iconField: { | ||
paddingBottom: theme.spacing(0.5), | ||
}, | ||
})) | ||
export default SettingsGroupPageView |