Fix according to peer review

This commit is contained in:
Charles Bochet
2023-07-15 19:15:21 -07:00
parent 91c8068db1
commit a2fcc3082f
3 changed files with 43 additions and 31 deletions

View File

@ -6,7 +6,7 @@ import { BoardPipelineStageColumn } from '@/ui/board/components/Board';
import { boardState } from './boardState'; import { boardState } from './boardState';
export const boardColumnTotalsFamilySelector = selectorFamily({ export const boardColumnTotalsFamilySelector = selectorFamily({
key: 'BoardColumnTotalsFamily', key: 'boardColumnTotalsFamilySelector',
get: get:
(pipelineStageId: string) => (pipelineStageId: string) =>
({ get }) => { ({ get }) => {

View File

@ -14,6 +14,7 @@ export const StyledColumn = styled.div`
`; `;
const StyledHeader = styled.div` const StyledHeader = styled.div`
cursor: pointer;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
@ -21,13 +22,17 @@ const StyledHeader = styled.div`
`; `;
export const StyledColumnTitle = styled.h3` export const StyledColumnTitle = styled.h3`
align-items: center;
color: ${({ color }) => color}; color: ${({ color }) => color};
display: flex;
flex-direction: row;
font-size: ${({ theme }) => theme.font.size.md}; font-size: ${({ theme }) => theme.font.size.md};
font-style: normal; font-style: normal;
font-weight: ${({ theme }) => theme.font.weight.medium}; font-weight: ${({ theme }) => theme.font.weight.medium};
line-height: ${({ theme }) => theme.text.lineHeight}; gap: ${({ theme }) => theme.spacing(2)};
height: 24px;
margin: 0; margin: 0;
margin-bottom: ${({ theme }) => theme.spacing(2)}; margin-bottom: ${({ theme }) => theme.spacing(1)};
`; `;
const StyledAmount = styled.div` const StyledAmount = styled.div`
@ -53,10 +58,6 @@ export function BoardColumn({
const [isEditing, setIsEditing] = React.useState(false); const [isEditing, setIsEditing] = React.useState(false);
const [internalValue, setInternalValue] = React.useState(title); const [internalValue, setInternalValue] = React.useState(title);
function toggleEditMode() {
setIsEditing(!isEditing);
}
const debouncedOnUpdate = debounce(onTitleEdit, 200); const debouncedOnUpdate = debounce(onTitleEdit, 200);
const handleChange = (event: ChangeEvent<HTMLInputElement>) => { const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
setInternalValue(event.target.value); setInternalValue(event.target.value);
@ -65,17 +66,20 @@ export function BoardColumn({
return ( return (
<StyledColumn> <StyledColumn>
<StyledHeader onClick={toggleEditMode}> <StyledHeader onClick={() => setIsEditing(true)}>
{isEditing ? ( <StyledColumnTitle color={colorCode}>
<EditColumnTitleInput
color={colorCode} {isEditing ? (
toggleEditMode={toggleEditMode} <EditColumnTitleInput
value={internalValue} color={colorCode}
onChange={handleChange} onFocusLeave={() => setIsEditing(false)}
/> value={internalValue}
) : ( onChange={handleChange}
<StyledColumnTitle color={colorCode}> {title}</StyledColumnTitle> />
)} ) : (
<div>{title}</div>
)}
</StyledColumnTitle>
{!!totalAmount && <StyledAmount>${totalAmount}</StyledAmount>} {!!totalAmount && <StyledAmount>${totalAmount}</StyledAmount>}
</StyledHeader> </StyledHeader>
{children} {children}

View File

@ -1,48 +1,56 @@
import React from 'react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { useScopedHotkeys } from '@/lib/hotkeys/hooks/useScopedHotkeys'; import { useScopedHotkeys } from '@/lib/hotkeys/hooks/useScopedHotkeys';
import { useSetHotkeyScope } from '@/lib/hotkeys/hooks/useSetHotkeyScope'; import { useSetHotkeyScope } from '@/lib/hotkeys/hooks/useSetHotkeyScope';
import { useListenClickOutsideArrayOfRef } from '@/ui/hooks/useListenClickOutsideArrayOfRef';
import { ColumnHotkeyScope } from './ColumnHotkeyScope'; import { ColumnHotkeyScope } from './ColumnHotkeyScope';
const StyledEditTitleInput = styled.input` const StyledEditTitleInput = styled.input`
background-color: transparent; background-color: transparent;
border: none; border: none;
&::placeholder, color: ${({ color }) => color};
&::-webkit-input-placeholder { font-family: ${({ theme }) => theme.font.family};
font-size: ${({ theme }) => theme.font.size.md};
font-weight: ${({ theme }) => theme.font.weight.medium};
&::placeholder {
color: ${({ theme }) => theme.font.color.light}; color: ${({ theme }) => theme.font.color.light};
font-family: ${({ theme }) => theme.font.family}; font-family: ${({ theme }) => theme.font.family};
font-weight: ${({ theme }) => theme.font.weight.medium}; font-weight: ${({ theme }) => theme.font.weight.medium};
} }
color: ${({ color }) => color}; font-weight: ${({ theme }) => theme.font.weight.medium};
&:focus {
color: ${({ color }) => color};
font-weight: ${({ theme }) => theme.font.weight.medium};
line-height: ${({ theme }) => theme.text.lineHeight};
}
margin: 0; margin: 0;
margin-bottom: ${({ theme }) => theme.spacing(2)};
outline: none; outline: none;
padding: 0;
`; `;
export function EditColumnTitleInput({ export function EditColumnTitleInput({
color, color,
value, value,
onChange, onChange,
toggleEditMode, onFocusLeave,
}: { }: {
color?: string; color?: string;
value: string; value: string;
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void; onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
toggleEditMode: () => void; onFocusLeave: () => void;
}) { }) {
const inputRef = React.useRef<HTMLInputElement>(null);
useListenClickOutsideArrayOfRef([inputRef], () => {
onFocusLeave();
});
const setHotkeyScope = useSetHotkeyScope(); const setHotkeyScope = useSetHotkeyScope();
setHotkeyScope(ColumnHotkeyScope.EditColumnName, { goto: false }); setHotkeyScope(ColumnHotkeyScope.EditColumnName, { goto: false });
useScopedHotkeys('enter', toggleEditMode, ColumnHotkeyScope.EditColumnName); useScopedHotkeys('enter', onFocusLeave, ColumnHotkeyScope.EditColumnName);
useScopedHotkeys('esc', toggleEditMode, ColumnHotkeyScope.EditColumnName); useScopedHotkeys('esc', onFocusLeave, ColumnHotkeyScope.EditColumnName);
return ( return (
<StyledEditTitleInput <StyledEditTitleInput
ref={inputRef}
placeholder={'Enter column name'} placeholder={'Enter column name'}
color={color} color={color}
autoFocus autoFocus