-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Notes 100 - Comment Edit #1196
base: main
Are you sure you want to change the base?
Notes 100 - Comment Edit #1196
Changes from 9 commits
1769593
44fdb6c
1bda074
eb1423c
702c200
519bb1a
17bf426
40f5bec
cd8a607
ef58f80
7866294
3da473a
63f6fda
836dc42
a71be42
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import '@percy/cypress' | ||
import { | ||
homepageSetup, | ||
returningUserVisitsHomepageWaitForModel, | ||
auth0Login, | ||
} from '../../support/utils' | ||
|
||
/** {@link https://github.com/bldrs-ai/Share/issues/1186} */ | ||
describe('Notes 100: Comment edit', () => { | ||
beforeEach(homepageSetup) | ||
context('Returning user visits homepage', () => { | ||
beforeEach(returningUserVisitsHomepageWaitForModel) | ||
context('Open Notes > first note', () => { | ||
beforeEach(() => { | ||
cy.get('[data-testid="control-button-notes"]').click() | ||
cy.get('[data-testid="list-notes"] :nth-child(1) > [data-testid="note-body"]').first().click() | ||
}) | ||
it('Comment switches to edit mode', () => { | ||
auth0Login() | ||
cy.get(`[data-testid="list-notes"] > :nth-child(3) | ||
> [data-testid="note-card"] > .MuiCardActions-root > .MuiBox-root > [data-testid="editComment"]`).click() | ||
cy.get('[data-testid="Save"]') | ||
cy.percySnapshot() | ||
}) | ||
it('Comment displays updated body', () => { | ||
auth0Login() | ||
cy.get(`[data-testid="list-notes"] > :nth-child(3) | ||
> [data-testid="note-card"] > .MuiCardActions-root > .MuiBox-root > [data-testid="editComment"]`).click() | ||
cy.get('[placeholder="Note body"]').click().type(' updated body') | ||
cy.get('[data-testid="Save"]').click() | ||
cy.percySnapshot() | ||
}) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint-disable no-console */ | ||
import React, {ReactElement, useState, useEffect} from 'react' | ||
import Avatar from '@mui/material/Avatar' | ||
import Card from '@mui/material/Card' | ||
|
@@ -9,6 +10,7 @@ import { | |
updateIssue, | ||
// TODO(pablo): deleteComment as deleteCommentGitHub, | ||
} from '../../net/github/Issues' | ||
import {updateComment} from '../../net/github/Comments' | ||
import useStore from '../../store/useStore' | ||
import {assertDefined} from '../../utils/assert' | ||
import {getHashParamsFromHashStr, setHashParams} from '../../utils/location' | ||
|
@@ -71,7 +73,6 @@ export default function NoteCard({ | |
const setSnackMessage = useStore((state) => state.setSnackMessage) | ||
const [showCreateComment, setShowCreateComment] = useState(false) | ||
|
||
|
||
const [editMode, setEditMode] = useState(false) | ||
const [editBody, setEditBody] = useState(body) | ||
|
||
|
@@ -96,14 +97,12 @@ export default function NoteCard({ | |
setEditBody(body) | ||
}, [selectedNoteId, body]) | ||
|
||
|
||
useEffect(() => { | ||
if (selected && firstCamera) { | ||
setCameraFromParams(firstCamera, cameraControls) | ||
} | ||
}, [selected, firstCamera, cameraControls]) | ||
|
||
|
||
/** Selecting a card move the notes to the replies/comments thread. */ | ||
function selectCard() { | ||
let selectedNote = null | ||
|
@@ -119,7 +118,6 @@ export default function NoteCard({ | |
setHashParams(window.location, HASH_PREFIX_NOTES, {id: id}) | ||
} | ||
|
||
|
||
/** Moves the camera to the position specified in the url attached to the issue/comment */ | ||
function showCameraView() { | ||
setCameraFromParams(firstCamera, cameraControls) | ||
|
@@ -135,7 +133,6 @@ export default function NoteCard({ | |
setSnackMessage({text: 'The url path is copied to the clipboard', autoDismiss: true}) | ||
} | ||
|
||
|
||
/** | ||
* Closes the issue. TODO(pablo): this isn't a delete | ||
* | ||
|
@@ -150,7 +147,6 @@ export default function NoteCard({ | |
return res | ||
} | ||
|
||
|
||
/** | ||
* Delete comment from repo and remove from UI | ||
* | ||
|
@@ -169,16 +165,26 @@ export default function NoteCard({ | |
setComments(newComments) | ||
} */ | ||
|
||
|
||
/** Update issue on GH, set read-only */ | ||
async function submitUpdate() { | ||
async function updateIssueGithub() { | ||
const res = await updateIssue(repository, noteNumber, title, editBody, accessToken) | ||
const editedNote = notes.find((note) => note.id === id) | ||
editedNote.body = res.data.body | ||
setNotes(notes) | ||
setEditMode(false) | ||
} | ||
|
||
/** | ||
* Update comment in github | ||
* | ||
* @param {number} commentId | ||
*/ | ||
async function updateCommentGithub(commentId) { | ||
const updatedComment = await updateComment(repository, commentId, editBody, accessToken) | ||
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. Fix this? #1201 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. yes WIP 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. This is a bit more involved. |
||
console.log('updated comment', updatedComment) | ||
setEditMode(false) | ||
} | ||
|
||
|
||
return ( | ||
<Card elevation={1} data-testid='note-card'> | ||
|
@@ -203,7 +209,7 @@ export default function NoteCard({ | |
{isNote && !editMode && !selected && | ||
<NoteBody selectCard={selectCard} markdownContent={editBody}/>} | ||
{selected && !editMode && <NoteContent markdownContent={editBody}/>} | ||
{!isNote && <NoteContent markdownContent={editBody}/>} | ||
{!isNote && !editMode && <NoteContent markdownContent={editBody}/>} | ||
{editMode && | ||
<NoteBodyEdit | ||
handleTextUpdate={(event) => setEditBody(event.target.value)} | ||
|
@@ -226,8 +232,9 @@ export default function NoteCard({ | |
onClickShare={shareIssue} | ||
selectCard={selectCard} | ||
selected={selected} | ||
submitUpdate={submitUpdate} | ||
synched={synched} | ||
setEditMode={setEditMode} | ||
submitNoteUpdate={updateIssueGithub} | ||
submitCommentUpdate={updateCommentGithub} | ||
username={username} | ||
/> | ||
</Card> | ||
|
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.
Fix this? #1201
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.
this code is related to the issues, i will do it in a separate PR.
Will keep this PR on comments