fix: distinction ux
This commit is contained in:
parent
c341642473
commit
6153561643
|
@ -13,6 +13,7 @@ import useChannel from 'hooks/useChannel';
|
||||||
export default function Distinction(props) {
|
export default function Distinction(props) {
|
||||||
const {
|
const {
|
||||||
state: [distinction, setDistinction],
|
state: [distinction, setDistinction],
|
||||||
|
$textarea,
|
||||||
} = props;
|
} = props;
|
||||||
const channel = useChannel();
|
const channel = useChannel();
|
||||||
const isAnonymous = channelIsAnonymous(channel);
|
const isAnonymous = channelIsAnonymous(channel);
|
||||||
|
@ -30,6 +31,9 @@ export default function Distinction(props) {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
// eslint-disable-next-line no-bitwise
|
// eslint-disable-next-line no-bitwise
|
||||||
setDistinction(distinction & ADMIN ? distinction & ~ADMIN : distinction | ADMIN);
|
setDistinction(distinction & ADMIN ? distinction & ~ADMIN : distinction | ADMIN);
|
||||||
|
if ($textarea.current) {
|
||||||
|
$textarea.current.focus();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span>👑</span>
|
<span>👑</span>
|
||||||
|
@ -45,6 +49,9 @@ export default function Distinction(props) {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
// eslint-disable-next-line no-bitwise
|
// eslint-disable-next-line no-bitwise
|
||||||
setDistinction(distinction & MOD ? distinction & ~MOD : distinction | MOD);
|
setDistinction(distinction & MOD ? distinction & ~MOD : distinction | MOD);
|
||||||
|
if ($textarea.current) {
|
||||||
|
$textarea.current.focus();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span>🎩</span>
|
<span>🎩</span>
|
||||||
|
@ -59,4 +66,15 @@ Distinction.propTypes = {
|
||||||
PropTypes.number,
|
PropTypes.number,
|
||||||
PropTypes.func,
|
PropTypes.func,
|
||||||
])).isRequired,
|
])).isRequired,
|
||||||
|
$textarea: PropTypes.oneOfType([
|
||||||
|
PropTypes.func,
|
||||||
|
PropTypes.shape({
|
||||||
|
current: (props, propName, componentName) => {
|
||||||
|
if (props[propName] !== null && !(props[propName] instanceof window.Node)) {
|
||||||
|
throw new Error(`Invalid current prop for $textarea on ${componentName}.`);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]).isRequired,
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,7 @@ export default function ChatSubmitMessage() {
|
||||||
const channel = useChannel();
|
const channel = useChannel();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const $form = useRef(null);
|
const $form = useRef(null);
|
||||||
|
const $textarea = useRef(null);
|
||||||
const [distinction, setDistinction] = useState(0);
|
const [distinction, setDistinction] = useState(0);
|
||||||
const redditUsername = useSelector(redditUsernameSelector);
|
const redditUsername = useSelector(redditUsernameSelector);
|
||||||
const user = useSelector(userSelector);
|
const user = useSelector(userSelector);
|
||||||
|
@ -81,6 +82,7 @@ export default function ChatSubmitMessage() {
|
||||||
<textarea
|
<textarea
|
||||||
className="chat--messagesTextarea"
|
className="chat--messagesTextarea"
|
||||||
name="message"
|
name="message"
|
||||||
|
ref={$textarea}
|
||||||
type="textarea"
|
type="textarea"
|
||||||
onChange={(event) => setText(event.target.value || '')}
|
onChange={(event) => setText(event.target.value || '')}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
|
@ -99,7 +101,10 @@ export default function ChatSubmitMessage() {
|
||||||
}}
|
}}
|
||||||
value={text || ''}
|
value={text || ''}
|
||||||
/>
|
/>
|
||||||
<Distinction state={[distinction, setDistinction]} />
|
<Distinction
|
||||||
|
state={[distinction, setDistinction]}
|
||||||
|
$textarea={$textarea}
|
||||||
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user