From ea442275199d9d28dd7e85d2a794dca36999d284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Curcio?= Date: Thu, 26 Jul 2018 11:21:57 -0300 Subject: [PATCH] Creating assetURL in localState S --- .../stream/components/Permalink/Permalink.tsx | 9 +++---- .../components/Permalink/PermalinkView.tsx | 25 +++++++++++-------- .../stream/containers/PermalinkContainer.tsx | 18 ++++++------- .../client/stream/local/initLocalState.ts | 14 ++++++----- src/core/client/stream/local/local.graphql | 3 +-- src/core/client/stream/queries/AppQuery.tsx | 2 +- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/core/client/stream/components/Permalink/Permalink.tsx b/src/core/client/stream/components/Permalink/Permalink.tsx index eefd8859d..3acfc3d71 100644 --- a/src/core/client/stream/components/Permalink/Permalink.tsx +++ b/src/core/client/stream/components/Permalink/Permalink.tsx @@ -5,21 +5,18 @@ import PermalinkPopover from "./PermalinkPopover"; interface InnerProps { commentID: string; - origin: string | null; - assetID: string | null; + assetURL: string | null; } class Permalink extends React.Component { public render() { - const { commentID, origin, assetID } = this.props; + const { commentID, assetURL } = this.props; return ( ( diff --git a/src/core/client/stream/components/Permalink/PermalinkView.tsx b/src/core/client/stream/components/Permalink/PermalinkView.tsx index a5e6b76db..ad10de179 100644 --- a/src/core/client/stream/components/Permalink/PermalinkView.tsx +++ b/src/core/client/stream/components/Permalink/PermalinkView.tsx @@ -21,22 +21,27 @@ const PermalinkView: StatelessComponent = props => { if (props.comment) { // TODO (bc) temporary needed to pass the assetID to go back to the correct asset until the backend // returns the correct asset url - const assetURL = `${location.origin}/?assetID=${query.assetID}`; + let assetURL: string = ""; + if (query.assetID) { + assetURL = `${location.origin}/?assetID=${query.assetID}`; + } return (
- + {assetURL && ( + + )}
); diff --git a/src/core/client/stream/containers/PermalinkContainer.tsx b/src/core/client/stream/containers/PermalinkContainer.tsx index a203dedcc..1176426c5 100644 --- a/src/core/client/stream/containers/PermalinkContainer.tsx +++ b/src/core/client/stream/containers/PermalinkContainer.tsx @@ -10,21 +10,19 @@ interface InnerProps { commentID: string; } -export const PermalinkContainer: StatelessComponent = props => { - return ( - - ); +export const PermalinkContainer: StatelessComponent = ({ + local, + commentID, +}) => { + return local.assetURL ? ( + + ) : null; }; const enhanced = withLocalStateContainer( graphql` fragment PermalinkContainerLocal on Local { - assetID - origin + assetURL } ` )(PermalinkContainer); diff --git a/src/core/client/stream/local/initLocalState.ts b/src/core/client/stream/local/initLocalState.ts index f43b14406..434c60e32 100644 --- a/src/core/client/stream/local/initLocalState.ts +++ b/src/core/client/stream/local/initLocalState.ts @@ -22,16 +22,18 @@ export default async function initLocalState(environment: Environment) { // Parse query params const query = qs.parse(location.search); - // Saving location host for permalink until we get the asset url - the url now points to the tenant - if (location) { - localRecord.setValue(location.host, "host"); - localRecord.setValue(location.origin, "origin"); - } - if (query.assetID) { localRecord.setValue(query.assetID, "assetID"); } + // Saving location host for permalink until we get the asset url - the url now points to the tenant + if (location && query.assetID) { + localRecord.setValue( + `${location.origin}/?assetID=${query.assetID}`, + "assetURL" + ); + } + if (query.commentID) { localRecord.setValue(query.commentID, "commentID"); } diff --git a/src/core/client/stream/local/local.graphql b/src/core/client/stream/local/local.graphql index f7152b2ce..9a2991607 100644 --- a/src/core/client/stream/local/local.graphql +++ b/src/core/client/stream/local/local.graphql @@ -7,8 +7,7 @@ type Local { network: Network! assetID: String commentID: String - host: String - origin: String + assetURL: String } extend type Query { diff --git a/src/core/client/stream/queries/AppQuery.tsx b/src/core/client/stream/queries/AppQuery.tsx index 64a005795..48ac6e5c5 100644 --- a/src/core/client/stream/queries/AppQuery.tsx +++ b/src/core/client/stream/queries/AppQuery.tsx @@ -78,7 +78,7 @@ const enhanced = withLocalStateContainer( fragment AppQueryLocal on Local { assetID commentID - origin + assetURL } ` )(AppQuery);