Skip to content

Commit

Permalink
For picked posts and comments to them, fetch body source from the ori…
Browse files Browse the repository at this point in the history
…ginal node.
  • Loading branch information
smelamud committed Apr 1, 2021
1 parent 69bb600 commit 7239b21
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/state/detailedposting/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export function getCommentsState(state) {
return state.detailedPosting.comments;
}

export function getCommentsReceiverName(state) {
return getCommentsState(state).receiverName;
}

export function getCommentsReceiverPostingId(state) {
return getCommentsState(state).receiverPostingId;
}
Expand Down
4 changes: 2 additions & 2 deletions src/state/sourcedialog/actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const OPEN_SOURCE_DIALOG = "OPEN_SOURCE_DIALOG";
export const openSourceDialog = (postingId, commentId) => ({
export const openSourceDialog = (nodeName, postingId, commentId) => ({
type: OPEN_SOURCE_DIALOG,
payload: {postingId, commentId}
payload: {nodeName, postingId, commentId}
});

export const CLOSE_SOURCE_DIALOG = "CLOSE_SOURCE_DIALOG";
Expand Down
8 changes: 4 additions & 4 deletions src/state/sourcedialog/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ export default [
];

function* openSourceDialogSaga(action) {
const {postingId, commentId} = action.payload;
const {nodeName, postingId, commentId} = action.payload;

try {
let entry;
if (commentId == null) {
entry = yield call(Node.getPosting, "", postingId, true);
entry = yield call(Node.getPosting, nodeName, postingId, true);
} else {
entry = yield call(Node.getComment, "", postingId, commentId, true);
entry = yield call(Node.getComment, nodeName, postingId, commentId, true);
}
yield put(sourceDialogLoaded(entry.bodySrc.text));
yield put(sourceDialogLoaded(entry.bodySrc ? entry.bodySrc.text : ""));
} catch (e) {
yield put(sourceDialogLoadFailed());
yield put(errorThrown(e));
Expand Down
7 changes: 5 additions & 2 deletions src/ui/comment/CommentMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { commentCopyLink, commentDelete, openCommentDialog } from "state/detaile
import { openSourceDialog } from "state/sourcedialog/actions";
import { confirmBox } from "state/confirmbox/actions";
import { getNodeRootLocation } from "state/node/selectors";
import { getCommentsReceiverName, getCommentsReceiverPostingId } from "state/detailedposting/selectors";

class CommentMenu extends React.PureComponent {

Expand All @@ -29,9 +30,9 @@ class CommentMenu extends React.PureComponent {
};

onViewSource = () => {
const {postingId, comment, openSourceDialog} = this.props;
const {receiverName, receiverPostingId, comment, openSourceDialog} = this.props;

openSourceDialog(postingId, comment.id);
openSourceDialog(receiverName, receiverPostingId, comment.id);
};

render() {
Expand Down Expand Up @@ -75,6 +76,8 @@ class CommentMenu extends React.PureComponent {
export default connect(
state => ({
rootLocation: getNodeRootLocation(state),
receiverName: getCommentsReceiverName(state),
receiverPostingId: getCommentsReceiverPostingId(state)
}),
{ commentCopyLink, openCommentDialog, openSourceDialog, confirmBox }
)(CommentMenu);
6 changes: 5 additions & 1 deletion src/ui/posting/PostingMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ class PostingMenu extends React.PureComponent {
onViewSource = () => {
const {posting, openSourceDialog} = this.props;

openSourceDialog(posting.id);
if (posting.receiverName == null) {
openSourceDialog("", posting.id);
} else {
openSourceDialog(posting.receiverName, posting.receiverPostingId);
}
};

render() {
Expand Down

0 comments on commit 7239b21

Please sign in to comment.