mirror of
https://github.com/wassname/talk.git
synced 2026-07-03 13:11:57 +08:00
91 lines
2.2 KiB
TypeScript
91 lines
2.2 KiB
TypeScript
import { Localized } from "fluent-react/compat";
|
|
import * as React from "react";
|
|
import { StatelessComponent } from "react";
|
|
import { ReadyState } from "react-relay";
|
|
|
|
import {
|
|
graphql,
|
|
QueryRenderer,
|
|
withLocalStateContainer,
|
|
} from "talk-framework/lib/relay";
|
|
import { PermalinkViewQuery as QueryTypes } from "talk-stream/__generated__/PermalinkViewQuery.graphql";
|
|
import { PermalinkViewQueryLocal as Local } from "talk-stream/__generated__/PermalinkViewQueryLocal.graphql";
|
|
|
|
import { Spinner } from "talk-ui/components";
|
|
import PermalinkViewContainer from "../containers/PermalinkViewContainer";
|
|
|
|
interface InnerProps {
|
|
local: Local;
|
|
}
|
|
|
|
export const render = ({
|
|
error,
|
|
props,
|
|
}: ReadyState<QueryTypes["response"]>) => {
|
|
if (error) {
|
|
return <div>{error.message}</div>;
|
|
}
|
|
if (props) {
|
|
if (!props.asset) {
|
|
return (
|
|
<Localized id="comments-permalinkViewQuery-assetNotFound">
|
|
<div>Asset not found</div>
|
|
</Localized>
|
|
);
|
|
}
|
|
return (
|
|
<PermalinkViewContainer
|
|
me={props.me}
|
|
comment={props.comment}
|
|
asset={props.asset}
|
|
/>
|
|
);
|
|
}
|
|
return <Spinner />;
|
|
};
|
|
|
|
const PermalinkViewQuery: StatelessComponent<InnerProps> = ({
|
|
local: { commentID, assetID, authRevision },
|
|
}) => (
|
|
<QueryRenderer<QueryTypes>
|
|
query={graphql`
|
|
query PermalinkViewQuery(
|
|
$commentID: ID!
|
|
$assetID: ID!
|
|
$authRevision: Int!
|
|
) {
|
|
# authRevision is increment every time auth state has changed.
|
|
# This is basically a cache invalidation and causes relay
|
|
# to automatically update this query.
|
|
me(clientAuthRevision: $authRevision) {
|
|
...PermalinkViewContainer_me
|
|
}
|
|
asset(id: $assetID) {
|
|
...PermalinkViewContainer_asset
|
|
}
|
|
comment(id: $commentID) {
|
|
...PermalinkViewContainer_comment
|
|
}
|
|
}
|
|
`}
|
|
variables={{
|
|
assetID: assetID!,
|
|
commentID: commentID!,
|
|
authRevision,
|
|
}}
|
|
render={render}
|
|
/>
|
|
);
|
|
|
|
const enhanced = withLocalStateContainer(
|
|
graphql`
|
|
fragment PermalinkViewQueryLocal on Local {
|
|
assetID
|
|
authRevision
|
|
commentID
|
|
}
|
|
`
|
|
)(PermalinkViewQuery);
|
|
|
|
export default enhanced;
|