From e5195031295827a451b55e776c8a1488f8d8fd67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Curcio?= Date: Wed, 25 Jul 2018 14:06:25 -0300 Subject: [PATCH] Progress: --- .../stream/components/PermalinkView.tsx | 26 ++++++ src/core/client/stream/components/Stream.tsx | 93 +++++++++++-------- .../client/stream/containers/AppContainer.tsx | 1 + .../containers/PermalinkViewContainer.tsx | 37 ++++++++ .../client/stream/local/initLocalState.ts | 5 + src/core/client/stream/local/local.graphql | 1 + src/core/client/stream/queries/AppQuery.tsx | 6 ++ .../stream/queries/PermalinkViewQuery.tsx | 57 ++++++++++++ .../server/graph/tenant/resolvers/query.ts | 2 +- 9 files changed, 189 insertions(+), 39 deletions(-) create mode 100644 src/core/client/stream/components/PermalinkView.tsx create mode 100644 src/core/client/stream/containers/PermalinkViewContainer.tsx create mode 100644 src/core/client/stream/queries/PermalinkViewQuery.tsx diff --git a/src/core/client/stream/components/PermalinkView.tsx b/src/core/client/stream/components/PermalinkView.tsx new file mode 100644 index 000000000..f0e884fc8 --- /dev/null +++ b/src/core/client/stream/components/PermalinkView.tsx @@ -0,0 +1,26 @@ +import * as React from "react"; +import { StatelessComponent } from "react"; + +import { CommentProps } from "talk-stream/components/Comment"; +import { Flex } from "talk-ui/components"; +import CommentContainer from "../containers/CommentContainer"; + +export interface AppProps { + comment: CommentProps | null; +} + +const PermalinkView: StatelessComponent = props => { + if (props.comment) { + return ( + + + + + + ); + } + + return
Error
; +}; + +export default PermalinkView; diff --git a/src/core/client/stream/components/Stream.tsx b/src/core/client/stream/components/Stream.tsx index 9dbb21c5b..fd70e3630 100644 --- a/src/core/client/stream/components/Stream.tsx +++ b/src/core/client/stream/components/Stream.tsx @@ -10,50 +10,67 @@ import ReplyListContainer from "../containers/ReplyListContainer"; import Logo from "./Logo"; import * as styles from "./Stream.css"; +import { Comment, CommentProps } from "talk-stream/components/Comment"; + export interface StreamProps { assetID: string; - isClosed: boolean; - comments: ReadonlyArray<{ id: string }>; - onLoadMore: () => void; - hasMore: boolean; - disableLoadMore: boolean; + comment?: CommentProps; + isClosed?: boolean; + comments?: ReadonlyArray<{ id: string }>; + onLoadMore?: () => void; + hasMore?: boolean; + disableLoadMore?: boolean; } const Stream: StatelessComponent = props => { - return ( -
- - - - {props.comments.map(comment => ( - - - - - ))} - {props.hasMore && ( - - - - )} + if (props.comment) { + return ( + + + + -
- ); + ); + } + + if (props.comments) { + return ( +
+ + + + {props.comments.map(comment => ( + + + + + ))} + {props.hasMore && ( + + + + )} + +
+ ); + } + + return
Error
; }; export default Stream; diff --git a/src/core/client/stream/containers/AppContainer.tsx b/src/core/client/stream/containers/AppContainer.tsx index 90eb1e1c6..f090ba128 100644 --- a/src/core/client/stream/containers/AppContainer.tsx +++ b/src/core/client/stream/containers/AppContainer.tsx @@ -12,6 +12,7 @@ interface InnerProps { } export const AppContainer: StatelessComponent = props => { + console.log("App query render", props); return ; }; diff --git a/src/core/client/stream/containers/PermalinkViewContainer.tsx b/src/core/client/stream/containers/PermalinkViewContainer.tsx new file mode 100644 index 000000000..8cd464b81 --- /dev/null +++ b/src/core/client/stream/containers/PermalinkViewContainer.tsx @@ -0,0 +1,37 @@ +import React, { StatelessComponent } from "react"; +import { graphql } from "react-relay"; + +import { withFragmentContainer } from "talk-framework/lib/relay"; +import { PropTypesOf } from "talk-framework/types"; + +import PermalinkView from "../components/PermalinkView"; + +import { PermalinkViewContainer as Data } from "talk-stream/__generated__/PermalinkViewContainer.graphql"; + +interface InnerProps { + data: Data; +} + +export const PermalinkViewContainer: StatelessComponent = props => { + console.log("App query render", props); + return ; +}; + +const enhanced = withFragmentContainer<{ data: Data }>({ + data: graphql` + fragment PermalinkViewContainer on Query + @argumentDefinitions(commentID: { type: "ID!" }) { + comment(id: $commentID) { + id + body + author { + username + } + createdAt + } + } + `, +})(PermalinkViewContainer); + +export type PermalinkViewContainerProps = PropTypesOf; +export default enhanced; diff --git a/src/core/client/stream/local/initLocalState.ts b/src/core/client/stream/local/initLocalState.ts index d65ea6331..2786b3ef2 100644 --- a/src/core/client/stream/local/initLocalState.ts +++ b/src/core/client/stream/local/initLocalState.ts @@ -21,10 +21,15 @@ export default async function initLocalState(environment: Environment) { // Parse query params const query = qs.parse(location.search); + if (query.assetID) { localRecord.setValue(query.assetID, "assetID"); } + if (query.commentID) { + localRecord.setValue(query.commentID, "commentID"); + } + // Create network Record const networkRecord = createAndRetain( environment, diff --git a/src/core/client/stream/local/local.graphql b/src/core/client/stream/local/local.graphql index 3359458d0..59c829490 100644 --- a/src/core/client/stream/local/local.graphql +++ b/src/core/client/stream/local/local.graphql @@ -6,6 +6,7 @@ type Network { type Local { network: Network! assetID: String + commentID: String } extend type Query { diff --git a/src/core/client/stream/queries/AppQuery.tsx b/src/core/client/stream/queries/AppQuery.tsx index 3fe95b6d9..3e6072c27 100644 --- a/src/core/client/stream/queries/AppQuery.tsx +++ b/src/core/client/stream/queries/AppQuery.tsx @@ -14,6 +14,7 @@ import { import { AppQueryLocal as Local } from "talk-stream/__generated__/AppQueryLocal.graphql"; import AppContainer from "../containers/AppContainer"; +import PermalinkViewQuery from "./PermalinkViewQuery"; export const render = ({ error, props }: ReadyState) => { if (error) { @@ -30,6 +31,10 @@ interface InnerProps { } const AppQuery: StatelessComponent = props => { + if (props.local.commentID) { + return ; + } + return ( query={graphql` @@ -49,6 +54,7 @@ const enhanced = withLocalStateContainer( graphql` fragment AppQueryLocal on Local { assetID + commentID } ` )(AppQuery); diff --git a/src/core/client/stream/queries/PermalinkViewQuery.tsx b/src/core/client/stream/queries/PermalinkViewQuery.tsx new file mode 100644 index 000000000..d48caf00f --- /dev/null +++ b/src/core/client/stream/queries/PermalinkViewQuery.tsx @@ -0,0 +1,57 @@ +import * as React from "react"; +import { StatelessComponent } from "react"; +import { ReadyState } from "react-relay"; + +import { graphql, QueryRenderer } from "talk-framework/lib/relay"; + +import { + PermalinkViewQueryResponse, + PermalinkViewQueryVariables, +} from "talk-stream/__generated__/PermalinkViewQuery.graphql"; +import { PermalinkViewContainer } from "talk-stream/containers/PermalinkViewContainer"; + +export interface CommentData { + id: string; + author: { + username: string; + } | null; + body: string | null; + createdAt: string; +} + +export const render = ({ + error, + props, +}: ReadyState<{ + comment: CommentData; +}>) => { + if (error) { + return
{error.message}
; + } + if (props) { + return ; + } + return
Loading
; +}; + +interface InnerProps { + commentID: string; +} + +const PermalinkViewQuery: StatelessComponent = props => { + return ( + + query={graphql` + query PermalinkViewQuery($commentID: ID!) { + ...PermalinkViewContainer @arguments(commentID: $commentID) + } + `} + variables={{ + commentID: props.commentID, + }} + render={render} + /> + ); +}; + +export default PermalinkViewQuery; diff --git a/src/core/server/graph/tenant/resolvers/query.ts b/src/core/server/graph/tenant/resolvers/query.ts index 01ebde5f5..91a31e7b8 100644 --- a/src/core/server/graph/tenant/resolvers/query.ts +++ b/src/core/server/graph/tenant/resolvers/query.ts @@ -10,6 +10,6 @@ export default { source: void, { id }: { id: string; url: string }, ctx: TenantContext - ) => ctx.loaders.Comments.comment.load(id), + ) => (id ? ctx.loaders.Comments.comment.load(id) : null), settings: async (parent: any, args: any, ctx: TenantContext) => ctx.tenant, };