Skip to content

Commit

Permalink
Merge pull request #183 from 1Hive/quests-117
Browse files Browse the repository at this point in the history
add a preview button for MarkDown when edit mode + add markdown in ch…
  • Loading branch information
alexchan0394 committed Mar 25, 2022
2 parents fe8b3a8 + 6676deb commit 948862d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
66 changes: 43 additions & 23 deletions packages/react-app/src/components/field-input/text-field-input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextInput, Markdown } from '@1hive/1hive-ui';
import { TextInput, Markdown, Button } from '@1hive/1hive-ui';
import { noop } from 'lodash-es';
import React, { ReactNode } from 'react';
import React, { ReactNode, useEffect, useState } from 'react';
import { CollapsableBlock } from 'src/collapsable-block';
import { GUpx } from 'src/utils/style.util';
import styled from 'styled-components';
Expand All @@ -21,6 +21,10 @@ const MaxLineStyled = styled.div`
}
`;

const BlockStyled = styled.div`
${({ wide }: any) => wide && 'width: 100%;'}
`;

// #endregion

type Props = {
Expand Down Expand Up @@ -63,6 +67,16 @@ export default function TextFieldInput({
tooltipDetail,
tooltip,
}: Props) {
const [isEditState, setIsEdit] = useState(isEdit);

useEffect(() => {
setIsEdit(isEdit);
}, [isEdit]);

const handlePreview = () => {
setIsEdit(!isEditState);
};

const readOnlyContent = (
<>
{isMarkDown ? (
Expand Down Expand Up @@ -114,28 +128,34 @@ export default function TextFieldInput({
)}
</>
);
const loadableContent = isEdit ? (
<TextInput
id={id}
value={value ?? ''}
wide={wide}
onChange={onChange}
placeHolder={placeHolder}
multiline={multiline}
style={css}
rows={rows}
/>
const loadableContent = isEditState ? (
<BlockStyled wide={wide}>
<TextInput
id={id}
value={value ?? ''}
wide={wide}
onChange={onChange}
placeHolder={placeHolder}
multiline={multiline}
style={css}
rows={rows}
/>
{isMarkDown && isEdit && <Button size="mini" label="Preview" onClick={handlePreview} />}
</BlockStyled>
) : (
<div style={{ ...css, fontSize }}>
{maxLine ? (
<div>
<MaxLineStyled maxLine={maxLine}>{readOnlyContent}</MaxLineStyled>
{ellipsis}
</div>
) : (
readOnlyContent
)}
</div>
<BlockStyled>
<div style={{ ...css, fontSize }}>
{maxLine ? (
<div>
<MaxLineStyled maxLine={maxLine}>{readOnlyContent}</MaxLineStyled>
{ellipsis}
</div>
) : (
readOnlyContent
)}
</div>
{isMarkDown && isEdit && <Button size="mini" label="Edit" onClick={handlePreview} />}
</BlockStyled>
);
return (
<FieldInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export default function ChallengeModal({ claim, challengeDeposit, onClose = noop
onChange={handleChange}
multiline
wide
isMarkDown
/>
</Outset>
</FormStyled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export default function ScheduleClaimModal({
wide
rows={5}
compact
isMarkDown
/>
<LineStyled>
<Outset horizontal>
Expand Down

1 comment on commit 948862d

@vercel
Copy link

@vercel vercel bot commented on 948862d Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

Please sign in to comment.