Files
talk/src/core/client/stream/mutations/SetCommentIDMutation.ts
T
Kiwi cf2be96a13 [next] Permalink View (#1987)
* feat: Implement converation thread

* Update unit tests

* test: adapt integration tests

* test: refactor denormalization helpers

* test: Include multiple parents in permalink View

* test: add integration test for loading previous parent comments

* feat: use dashed & solid time line

* feat: use new conversation thread design

* feat: add header from new design

* test: update snapshots

* fix: better scrolling behavior

* feat: add user box

* fix: add translations

* fix: typo

* fix: plural translation

* fix: paddings

* feat: better styling for level 0 comments

* fix: gutter size

* fix: update iframe url with new comment id

* test: add unit tests
2018-10-12 16:41:58 +00:00

44 lines
1.2 KiB
TypeScript

import { commitLocalUpdate, Environment } from "relay-runtime";
import { getURLWithCommentID } from "talk-framework/helpers";
import { TalkContext } from "talk-framework/lib/bootstrap";
import { createMutationContainer } from "talk-framework/lib/relay";
import { LOCAL_ID } from "talk-framework/lib/relay/withLocalStateContainer";
export interface SetCommentIDInput {
id: string | null;
}
export type SetCommentIDMutation = (input: SetCommentIDInput) => Promise<void>;
export async function commit(
environment: Environment,
input: SetCommentIDInput,
{ pym }: TalkContext
) {
return commitLocalUpdate(environment, store => {
const record = store.get(LOCAL_ID)!;
record.setValue(input.id, "commentID");
record.setValue("COMMENTS", "activeTab");
// Change iframe url, this is important
// because it is used to cleanly initialized
// a user session.
window.history.replaceState(
window.history.state,
document.title,
getURLWithCommentID(location.href, input.id || undefined)
);
if (pym) {
// This sets the comment id on the parent url.
pym.sendMessage("setCommentID", input.id || "");
}
});
}
export const withSetCommentIDMutation = createMutationContainer(
"setCommentID",
commit
);