Skip to content

Commit

Permalink
feat: comment whispers
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Jul 20, 2022
1 parent 84b0589 commit 7c717e0
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/components/widgets/Comment/box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const USER_DRAFT = 'mx-space-comment-draft'

const initialState = {
syncToRecently: false,
isWhispers: false,
}

const CommentSendingContext = createContext({
Expand All @@ -48,7 +49,7 @@ const CommentSendingContext = createContext({
})

export const CommentBox: FC<{
onSubmit: ({ text, author, mail, url }) => any
onSubmit: ({ text, author, mail, url, isWhispers }) => any
onCancel?: () => any
autoFocus?: boolean

Expand Down Expand Up @@ -159,6 +160,7 @@ export const CommentBox: FC<{
text,
mail,
url: url || undefined,
isWhispers: config.isWhispers,
}
localStorage.setItem(USER_PREFIX, JSON.stringify(omit(model, ['text'])))
onSubmit(model).then(() => {
Expand Down Expand Up @@ -326,7 +328,9 @@ const CommentBoxOption = observer<{ commentId?: string; refId: string }>(
(props) => {
const { userStore } = useStore()
const { isLogged } = userStore
const { syncToRecently, setConfig } = useContext(CommentSendingContext)
const { syncToRecently, isWhispers, setConfig } = useContext(
CommentSendingContext,
)
return (
<>
{isLogged && !props.commentId && (
Expand All @@ -344,6 +348,21 @@ const CommentBoxOption = observer<{ commentId?: string; refId: string }>(
</label>
</fieldset>
)}
{!isLogged && (
<fieldset className="inline-flex items-center children:cursor-pointer">
<input
type="checkbox"
id="comment-box-whispers"
checked={isWhispers}
onChange={(e) => {
setConfig({ isWhispers: e.target.checked })
}}
/>
<label htmlFor="comment-box-whispers" className="text-shizuku">
悄悄话
</label>
</fieldset>
)}
</>
)
},
Expand Down

0 comments on commit 7c717e0

Please sign in to comment.