[next] Bugfixes (#2272)

* feat: suspending, banning, now propogation

* feat: new mutation api with hooks support

* [CORL-343] Center Spinner in Stream

* [CORL-344] Fix moderation card styling

* [CORL-338] Fix permalink reply bug

* [CORL-337] Fix community guidelines box width

* [CORL-341] Toggle reply form view when clicking on reply

* test: add tests

* [CORL-333] Fix bug: removing message box icon; [CORL-336] Fix bug: allow resetting custom css
This commit is contained in:
Kiwi
2019-04-23 22:29:58 +02:00
committed by Wyatt Johnson
parent 5150cdf60e
commit a92dcd6224
29 changed files with 745 additions and 439 deletions
@@ -1,8 +0,0 @@
import { Environment } from "relay-runtime";
export default function getStory(environment: Environment, id: string) {
return environment
.getStore()
.getSource()
.get(id);
}
@@ -1,15 +0,0 @@
import { Environment } from "relay-runtime";
import getStory from "./getStory";
export default function getStorySettings(environment: Environment, id: string) {
const story = getStory(environment, id);
if (!story) {
return null;
}
const storySettingsRef = story.settings.__ref;
return environment
.getStore()
.getSource()
.get(storySettingsRef);
}
@@ -1,12 +1,13 @@
import { Environment } from "relay-runtime";
import { lookup } from "talk-framework/lib/relay";
import { GQLUser } from "talk-framework/schema";
import getViewerSourceID from "./getViewerSourceID";
export default function getViewer(environment: Environment) {
const source = environment.getStore().getSource();
const viewerID = getViewerSourceID(environment);
if (!viewerID) {
return null;
}
return source.get(viewerID)!;
return lookup<GQLUser>(environment, viewerID)!;
}
@@ -7,5 +7,3 @@ export { default as redirectOAuth2 } from "./redirectOAuth2";
export {
default as getParamsFromHashAndClearIt,
} from "./getParamsFromHashAndClearIt";
export { default as getStory } from "./getStory";
export { default as getStorySettings } from "./getStorySettings";
@@ -6,7 +6,7 @@ import { Environment, RelayInMemoryRecordSource } from "relay-runtime";
*/
type RecordSourceProxy<T> = T extends object
? {
readonly [P in keyof T]?: T[P] extends Array<infer U>
readonly [P in keyof T]: T[P] extends Array<infer U>
? ReadonlyArray<RecordSourceProxy<U>>
: T[P] extends ReadonlyArray<infer V>
? ReadonlyArray<RecordSourceProxy<V>>
@@ -1,33 +1,48 @@
export function denormalizeComment(comment: any, parents: any[] = []) {
const replyNodes =
import { GQLComment, GQLCommentEdge, GQLStory } from "talk-framework/schema";
import createFixture, { Fixture } from "./createFixture";
export function denormalizeComment(
comment: Fixture<GQLComment>,
parents: Array<Fixture<GQLCommentEdge>> = []
): GQLComment {
const replyEdges =
(comment.replies &&
comment.replies.edges.map((edge: any) =>
denormalizeComment(edge, [...parents, comment])
)) ||
comment.replies.edges &&
comment.replies.edges.map(edge => ({
...edge,
node:
edge.node &&
denormalizeComment(edge.node, [
...parents,
{ node: comment, cursor: comment.createdAt },
]),
}))) ||
[];
const repliesPageInfo = (comment.replies && comment.replies.pageInfo) || {
endCursor: null,
hasNextPage: false,
};
return {
return createFixture<GQLComment>({
...comment,
replies: { edges: replyNodes, pageInfo: repliesPageInfo },
replyCount: replyNodes.length,
replies: { edges: replyEdges, pageInfo: repliesPageInfo },
replyCount: replyEdges.length,
parentCount: parents.length,
parents: {
edges: parents,
pageInfo: { startCursor: null, hasPreviousPage: false },
},
};
});
}
export function denormalizeComments(commentList: any[]) {
export function denormalizeComments(commentList: Array<Fixture<GQLComment>>) {
return commentList.map(c => denormalizeComment(c));
}
export function denormalizeStory(story: any) {
export function denormalizeStory(story: Fixture<GQLStory>) {
const commentNodes =
(story.comments &&
story.comments.edges &&
story.comments.edges.map((edge: any) => ({
...edge,
node: denormalizeComment(edge.node),
@@ -46,6 +61,6 @@ export function denormalizeStory(story: any) {
};
}
export function denormalizeStories(storyList: any[]) {
export function denormalizeStories(storyList: Array<Fixture<GQLStory>>) {
return storyList.map(a => denormalizeStory(a));
}