-
Notifications
You must be signed in to change notification settings - Fork 15
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
PR 226 added editable descriptions #232
Open
4xdk
wants to merge
10
commits into
PursuanceProject:develop
Choose a base branch
from
4xdk:PR-226-Added-editable-descriptions
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c5ec319
Added editable descriptions
b8469ac
Merge pull request #1 from PursuanceProject/develop
b1f4dc7
Added confetti via local component state
a6a01c7
Revert "Added confetti via local component state"
d91d0af
Merged in Jhovahn:develop
c59cb23
Revert and do a manual selective merge
a63abb0
Wysiwyg draft.js with markdown - WIP, saves but doesnt reload
e1a54ae
Editor with markdown support and autolists
ce7c179
Cleanup
cf8fd58
Cleanup v2
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,7 +109,7 @@ | |
|
||
.subtasks-list { | ||
list-style: none; | ||
padding-left: 0 | ||
padding-left: 0; | ||
} | ||
|
||
.subtask-item { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/components/Content/RightPanel/TaskDetails/Wysiwyg/Wysiwyg.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.wysiwyg { | ||
box-sizing: border-box; | ||
border: 1px solid #ccc; | ||
cursor: text; | ||
padding: 16px; | ||
border-radius: 5px; | ||
margin: 20px 0; | ||
box-shadow: inset 0px 1px 8px 3px #ABABAB; | ||
background: #fefefe; | ||
color: black; | ||
} | ||
|
||
.wysiwyg :global(.public-DraftEditor-content) { | ||
min-height: 140px; | ||
} | ||
|
||
.wysiwyg-save, | ||
.wysiwyg-edit { | ||
border-radius: 5px; | ||
background-color: #000; | ||
} |
103 changes: 103 additions & 0 deletions
103
src/components/Content/RightPanel/TaskDetails/Wysiwyg/Wysiwyg.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, {Component} from 'react'; | ||
import {connect} from 'react-redux'; | ||
import {EditorState, convertToRaw, convertFromRaw} from 'draft-js'; | ||
import Editor from 'draft-js-plugins-editor'; | ||
import createAutoListPlugin from 'draft-js-autolist-plugin' | ||
import createMarkdownPlugin from 'draft-js-markdown-plugin'; | ||
import {markdownToDraft, draftToMarkdown} from 'markdown-draft-js'; | ||
import ReactMarkdown from 'react-markdown'; | ||
import './Wysiwyg.css'; | ||
|
||
const autoListPlugin = createAutoListPlugin(); | ||
|
||
const plugins = [ | ||
autoListPlugin, | ||
createMarkdownPlugin() | ||
]; | ||
|
||
class Wysiwyg extends Component { | ||
componentWillMount() { | ||
const {tasks: { taskMap }, taskGid, attributeName} = this.props, | ||
attributeValue = taskMap[taskGid][attributeName], | ||
content = attributeValue ? markdownToDraft(attributeValue, { | ||
remarkableOptions: { | ||
html: false, | ||
preserveNewlines: true | ||
} | ||
}) : markdownToDraft(''); | ||
|
||
this.state = { | ||
editMode: false, | ||
editorState: EditorState.createWithContent(convertFromRaw(content)) | ||
}; | ||
} | ||
|
||
editModeEnable = () => { | ||
this.setState({ | ||
editMode: true | ||
}); | ||
}; | ||
|
||
onChange = (editorState) => { | ||
this.setState({ | ||
editorState | ||
}); | ||
}; | ||
|
||
save = () => { | ||
const {patchTask} = this.props, | ||
markdown = draftToMarkdown(convertToRaw(this.state.editorState.getCurrentContent())), | ||
payload = {gid: this.props.taskGid}; | ||
|
||
payload[this.props.attributeName] = markdown; | ||
|
||
patchTask(payload); | ||
|
||
this.setState({ | ||
editMode: false | ||
}); | ||
} | ||
|
||
render() { | ||
const {tasks: {taskMap}} = this.props, | ||
attributeValue = taskMap[this.props.taskGid][this.props.attributeName]; | ||
|
||
return ( | ||
<div> | ||
{ | ||
this.state.editMode && ( | ||
<div> | ||
<div className='wysiwyg'> | ||
<Editor | ||
editorState={this.state.editorState} | ||
onChange={this.onChange} | ||
plugins={plugins} | ||
/> | ||
</div> | ||
<button className='wysiwyg-save' | ||
onClick={this.save}>Save</button> | ||
</div> | ||
) | ||
} | ||
{ | ||
!this.state.editMode && ( | ||
<div> | ||
<ReactMarkdown | ||
source={attributeValue} | ||
render={{Link: props => { | ||
if (props.href.startsWith('/')) { | ||
return <a href={props.href}>{props.children}</a>; | ||
} | ||
// If link to external site, open in new tab | ||
return <a href={props.href} target="_blank">{props.children}</a>; | ||
}}} /> | ||
<button className='wysiwyg-edit' onClick={this.editModeEnable}>Edit</button> | ||
</div> | ||
) | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default connect(({tasks}) => ({tasks}), null)(Wysiwyg); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@4xdk Got a more description variable name than
attributeValue
?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.
Well, this variable can hold any attribute value - depending on props passed to Wysiwyg element. I think generic variable name fits in this case.