From db0903336757eb35bf5be72347c793249b6d15bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Curcio?= Date: Thu, 26 Jul 2018 11:13:39 -0300 Subject: [PATCH 1/2] Creating assetURL in localState --- .../stream/components/Permalink/Permalink.tsx | 9 +++------ .../stream/containers/PermalinkContainer.tsx | 11 ++--------- src/core/client/stream/local/initLocalState.ts | 14 ++++++++------ src/core/client/stream/local/local.graphql | 3 +-- src/core/client/stream/queries/AppQuery.tsx | 2 +- 5 files changed, 15 insertions(+), 24 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/containers/PermalinkContainer.tsx b/src/core/client/stream/containers/PermalinkContainer.tsx index a203dedcc..ea4630391 100644 --- a/src/core/client/stream/containers/PermalinkContainer.tsx +++ b/src/core/client/stream/containers/PermalinkContainer.tsx @@ -11,20 +11,13 @@ interface InnerProps { } export const PermalinkContainer: StatelessComponent = props => { - return ( - - ); + return ; }; 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); From f51f989021a3f2d17b3ce83429ca4889536111f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Curcio?= Date: Thu, 26 Jul 2018 11:21:12 -0300 Subject: [PATCH 2/2] S --- .../components/Permalink/PermalinkView.tsx | 25 +++++++++++-------- .../stream/containers/PermalinkContainer.tsx | 9 +++++-- 2 files changed, 22 insertions(+), 12 deletions(-) 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 ea4630391..1176426c5 100644 --- a/src/core/client/stream/containers/PermalinkContainer.tsx +++ b/src/core/client/stream/containers/PermalinkContainer.tsx @@ -10,8 +10,13 @@ interface InnerProps { commentID: string; } -export const PermalinkContainer: StatelessComponent = props => { - return ; +export const PermalinkContainer: StatelessComponent = ({ + local, + commentID, +}) => { + return local.assetURL ? ( + + ) : null; }; const enhanced = withLocalStateContainer(