-
Notifications
You must be signed in to change notification settings - Fork 227
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bookmark notes #647
Bookmark notes #647
Changes from 4 commits
1743df5
9264e4d
adee88c
afbb99c
494f6ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
import { Small } from '~/components/Typography' | ||
import { GET_BOOKMARKS } from '~/graphql/queries' | ||
import Input from '~/components/Input' | ||
import Textarea from '~/components/Textarea' | ||
import Grid from '~/components/Grid' | ||
|
||
interface Props { | ||
|
@@ -20,16 +21,23 @@ export default function EditingBookmarkListItem(props: Props) { | |
const initialState = { | ||
error: '', | ||
title: bookmark.title, | ||
notes: bookmark.notes || '', | ||
} | ||
|
||
function reducer(state, action) { | ||
switch (action.type) { | ||
case 'edit': { | ||
case 'edit-title': { | ||
return { | ||
error: '', | ||
title: action.value, | ||
} | ||
} | ||
case 'edit-notes': { | ||
return { | ||
...state, | ||
notes: action.value, | ||
} | ||
} | ||
case 'error': { | ||
return { | ||
...state, | ||
|
@@ -43,14 +51,15 @@ export default function EditingBookmarkListItem(props: Props) { | |
|
||
const [state, dispatch] = React.useReducer(reducer, initialState) | ||
|
||
const [saveBookmark] = useEditBookmarkMutation({ | ||
variables: { title: state.title, id: bookmark.id }, | ||
const [editBookmark] = useEditBookmarkMutation({ | ||
variables: { title: state.title, id: bookmark.id, notes: state.notes }, | ||
optimisticResponse: { | ||
__typename: 'Mutation', | ||
editBookmark: { | ||
__typename: 'Bookmark', | ||
...bookmark, | ||
title: state.title, | ||
notes: state.notes, | ||
}, | ||
}, | ||
onError({ message }) { | ||
|
@@ -75,8 +84,12 @@ export default function EditingBookmarkListItem(props: Props) { | |
}, | ||
}) | ||
|
||
function onChange(e) { | ||
dispatch({ type: 'edit', value: e.target.value }) | ||
function onTitleChange(e) { | ||
dispatch({ type: 'edit-title', value: e.target.value }) | ||
} | ||
|
||
function onNotesChange(e) { | ||
dispatch({ type: 'edit-notes', value: e.target.value }) | ||
} | ||
|
||
function handleSave(e) { | ||
|
@@ -86,14 +99,23 @@ export default function EditingBookmarkListItem(props: Props) { | |
return dispatch({ type: 'error', value: 'Bookmark must have a title' }) | ||
} | ||
|
||
saveBookmark() | ||
editBookmark() | ||
return onDone() | ||
} | ||
|
||
return ( | ||
<Grid gap={12} as={'form'} onSubmit={handleSave}> | ||
<Input value={state.title} onChange={onChange} /> | ||
|
||
<Input | ||
autoFocus | ||
placeholder="Title" | ||
value={state.title} | ||
onChange={onTitleChange} | ||
/> | ||
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. Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input. |
||
<Textarea | ||
placeholder="Notes..." | ||
value={state.notes} | ||
onChange={onNotesChange} | ||
/> | ||
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. Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input. |
||
{state.error && ( | ||
<Small style={{ color: 'var(--accent-red)' }}>{state.error}</Small> | ||
)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import styled from 'styled-components' | ||
import theme from '~/components/Theme' | ||
|
||
export default styled.textarea` | ||
padding: ${theme.space[3]}; | ||
border: 1px solid var(--border-primary); | ||
color: var(--text-primary); | ||
border-radius: ${theme.space[2]}; | ||
font-size: 16px; | ||
background: var(--bg-primary); | ||
resize: vertical; | ||
width: 100%; | ||
line-height: ${theme.lineHeights.body}; | ||
|
||
&:focus { | ||
border: 1px solid var(--accent-blue); | ||
background: var(--bg-secondary); | ||
} | ||
` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ export const BookmarkInfoFragment = gql` | |
url | ||
host | ||
reactions | ||
notes | ||
} | ||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.