Skip to content
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

Refactor the EditableText component to reduce code duplication. #194

Open
raphaelweis opened this issue Jun 5, 2024 · 2 comments
Open
Assignees

Comments

@raphaelweis
Copy link
Contributor

In editable text, the functions handleImageUrl and handleBlur are almost identical, with the main difference being the source of the text to update. These can be combined into a single function allowing it's users to update the text for a passage margin, regardless of the input method.

@benel
Copy link
Member

benel commented Jun 12, 2024

Thank you for this suggestion.

Please note that a similar refactoring has recently been done to reuse code between handleClick and useEffect:

let updateEditedDocument = () => backend.getDocument(id)
.then((x) => {
x = x.error
? {_id: uuid(), text: `{${rubric}}`, isPartOf, links}
: x;
setEditedDocument(x);
return x;
});

@raphaelweis raphaelweis moved this from À faire to En cours in Analyse du système d'information 2024 Jun 12, 2024
@raphaelweis raphaelweis moved this from En cours to À faire in Analyse du système d'information 2024 Jun 19, 2024
@benel
Copy link
Member

benel commented Oct 24, 2024

let parsedText = parsePassage(editedDocument.text) + imageTag;
let text = (rubric)
? editedDocument.text.replace(PASSAGE, `{${rubric}} ${parsedText}`)
: parsedText;
backend.putDocument({ ...editedDocument, text })
.then(x => setLastUpdate(x.rev))

let parsedText = parseFirstPassage(editedText);
let text = (rubric)
? editedDocument.text.replace(PASSAGE, `{${rubric}} ${parsedText}`)
: editedText;
backend.putDocument({ ...editedDocument, text })
.then(x => setLastUpdate(x.rev))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

2 participants