diff --git a/apps/kampus/app/pano/__generated__/SinglePostContainerQuery.graphql.ts b/apps/kampus/app/pano/__generated__/SinglePostContainerQuery.graphql.ts index c2b34211..b8bba9ad 100644 --- a/apps/kampus/app/pano/__generated__/SinglePostContainerQuery.graphql.ts +++ b/apps/kampus/app/pano/__generated__/SinglePostContainerQuery.graphql.ts @@ -1,5 +1,5 @@ /** - * @generated SignedSource<<5f5308eecb94664d8c4d7e40499a646c>> + * @generated SignedSource<> * @lightSyntaxTransform * @nogrep */ @@ -291,6 +291,18 @@ return { (v7/*: any*/), (v8/*: any*/), (v9/*: any*/), + { + "alias": null, + "args": null, + "concreteType": "PanoPost", + "kind": "LinkedField", + "name": "post", + "plural": false, + "selections": [ + (v4/*: any*/) + ], + "storageKey": null + }, (v12/*: any*/), (v2/*: any*/) ], @@ -367,12 +379,12 @@ return { ] }, "params": { - "cacheID": "04e79370b9682cdf863f4365c8f65dfc", + "cacheID": "bce44ac06b004a5aa2ba6ae686442e66", "id": null, "metadata": {}, "name": "SinglePostContainerQuery", "operationKind": "query", - "text": "query SinglePostContainerQuery(\n $id: ID!\n) {\n viewer {\n ...SinglePostFeed_viewer\n }\n pano {\n post(id: $id) {\n ...SinglePostFeed_post\n id\n }\n }\n}\n\nfragment CommentItem_comment on PanoComment {\n id\n content\n createdAt\n owner {\n displayName\n id\n }\n commentCount\n ...CommentUpvoteButton_comment\n ...CommentMoreOptions_comment\n}\n\nfragment CommentItem_viewer on Viewer {\n actor {\n __typename\n displayName\n id\n }\n ...CommentMoreOptions_viewer\n ...UpdateCommentForm_viewer\n}\n\nfragment CommentMoreOptions_comment on PanoComment {\n id\n owner {\n displayName\n id\n }\n}\n\nfragment CommentMoreOptions_viewer on Viewer {\n actor {\n __typename\n displayName\n id\n }\n}\n\nfragment CommentUpvoteButton_comment on PanoComment {\n id\n isUpvotedByViewer\n upvoteCount\n}\n\nfragment CreatePostCommentForm_viewer on Viewer {\n actor {\n __typename\n displayName\n id\n }\n}\n\nfragment MoreOptions_post on PanoPost {\n id\n owner {\n displayName\n id\n }\n}\n\nfragment MoreOptions_viewer on Viewer {\n actor {\n __typename\n displayName\n id\n }\n}\n\nfragment PostItem_post on PanoPost {\n id\n title\n content\n url\n createdAt\n site\n commentCount\n ...PostUpvoteButton_post\n owner {\n displayName\n id\n }\n ...MoreOptions_post\n}\n\nfragment PostItem_viewer on Viewer {\n ...MoreOptions_viewer\n actor {\n __typename\n displayName\n id\n }\n}\n\nfragment PostUpvoteButton_post on PanoPost {\n id\n isUpvotedByViewer\n upvoteCount\n}\n\nfragment SinglePostFeed_post on PanoPost {\n ...PostItem_post\n commentCount\n comments(first: 10) {\n edges {\n node {\n id\n content\n createdAt\n owner {\n displayName\n id\n }\n ...CommentItem_comment\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n\nfragment SinglePostFeed_viewer on Viewer {\n ...PostItem_viewer\n ...CommentItem_viewer\n ...CreatePostCommentForm_viewer\n}\n\nfragment UpdateCommentForm_viewer on Viewer {\n actor {\n __typename\n displayName\n id\n }\n}\n" + "text": "query SinglePostContainerQuery(\n $id: ID!\n) {\n viewer {\n ...SinglePostFeed_viewer\n }\n pano {\n post(id: $id) {\n ...SinglePostFeed_post\n id\n }\n }\n}\n\nfragment CommentItem_comment on PanoComment {\n id\n content\n createdAt\n owner {\n displayName\n id\n }\n commentCount\n ...CommentUpvoteButton_comment\n ...CommentMoreOptions_comment\n}\n\nfragment CommentItem_viewer on Viewer {\n actor {\n __typename\n displayName\n id\n }\n ...CommentMoreOptions_viewer\n ...UpdateCommentForm_viewer\n}\n\nfragment CommentMoreOptions_comment on PanoComment {\n id\n post {\n id\n }\n owner {\n displayName\n id\n }\n}\n\nfragment CommentMoreOptions_viewer on Viewer {\n actor {\n __typename\n displayName\n id\n }\n}\n\nfragment CommentUpvoteButton_comment on PanoComment {\n id\n isUpvotedByViewer\n upvoteCount\n}\n\nfragment CreatePostCommentForm_viewer on Viewer {\n actor {\n __typename\n displayName\n id\n }\n}\n\nfragment MoreOptions_post on PanoPost {\n id\n owner {\n displayName\n id\n }\n}\n\nfragment MoreOptions_viewer on Viewer {\n actor {\n __typename\n displayName\n id\n }\n}\n\nfragment PostItem_post on PanoPost {\n id\n title\n content\n url\n createdAt\n site\n commentCount\n ...PostUpvoteButton_post\n owner {\n displayName\n id\n }\n ...MoreOptions_post\n}\n\nfragment PostItem_viewer on Viewer {\n ...MoreOptions_viewer\n actor {\n __typename\n displayName\n id\n }\n}\n\nfragment PostUpvoteButton_post on PanoPost {\n id\n isUpvotedByViewer\n upvoteCount\n}\n\nfragment SinglePostFeed_post on PanoPost {\n ...PostItem_post\n commentCount\n comments(first: 10) {\n edges {\n node {\n id\n content\n createdAt\n owner {\n displayName\n id\n }\n ...CommentItem_comment\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n\nfragment SinglePostFeed_viewer on Viewer {\n ...PostItem_viewer\n ...CommentItem_viewer\n ...CreatePostCommentForm_viewer\n}\n\nfragment UpdateCommentForm_viewer on Viewer {\n actor {\n __typename\n displayName\n id\n }\n}\n" } }; })(); diff --git a/apps/kampus/app/pano/__generated__/SinglePostFeedPaginationQuery.graphql.ts b/apps/kampus/app/pano/__generated__/SinglePostFeedPaginationQuery.graphql.ts index 6cebc033..767d0f61 100644 --- a/apps/kampus/app/pano/__generated__/SinglePostFeedPaginationQuery.graphql.ts +++ b/apps/kampus/app/pano/__generated__/SinglePostFeedPaginationQuery.graphql.ts @@ -1,5 +1,5 @@ /** - * @generated SignedSource<<80327a5b31c47e8f64937f103e9cecf8>> + * @generated SignedSource<<6b510cb6581f4f6f0b387ac509439a3e>> * @lightSyntaxTransform * @nogrep */ @@ -278,6 +278,18 @@ return { (v11/*: any*/), (v12/*: any*/), (v13/*: any*/), + { + "alias": null, + "args": null, + "concreteType": "PanoPost", + "kind": "LinkedField", + "name": "post", + "plural": false, + "selections": [ + (v8/*: any*/) + ], + "storageKey": null + }, (v15/*: any*/), (v7/*: any*/) ], @@ -355,12 +367,12 @@ return { ] }, "params": { - "cacheID": "a09d3f2d5a409974450c2baa06c85391", + "cacheID": "8296a6f08ec06ed693c0d25236076dca", "id": null, "metadata": {}, "name": "SinglePostFeedPaginationQuery", "operationKind": "query", - "text": "query SinglePostFeedPaginationQuery(\n $after: String\n $before: String\n $first: Int = 10\n $last: Int\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...SinglePostFeed_post_pbnwq\n id\n }\n}\n\nfragment CommentItem_comment on PanoComment {\n id\n content\n createdAt\n owner {\n displayName\n id\n }\n commentCount\n ...CommentUpvoteButton_comment\n ...CommentMoreOptions_comment\n}\n\nfragment CommentMoreOptions_comment on PanoComment {\n id\n owner {\n displayName\n id\n }\n}\n\nfragment CommentUpvoteButton_comment on PanoComment {\n id\n isUpvotedByViewer\n upvoteCount\n}\n\nfragment MoreOptions_post on PanoPost {\n id\n owner {\n displayName\n id\n }\n}\n\nfragment PostItem_post on PanoPost {\n id\n title\n content\n url\n createdAt\n site\n commentCount\n ...PostUpvoteButton_post\n owner {\n displayName\n id\n }\n ...MoreOptions_post\n}\n\nfragment PostUpvoteButton_post on PanoPost {\n id\n isUpvotedByViewer\n upvoteCount\n}\n\nfragment SinglePostFeed_post_pbnwq on PanoPost {\n ...PostItem_post\n commentCount\n comments(first: $first, after: $after, last: $last, before: $before) {\n edges {\n node {\n id\n content\n createdAt\n owner {\n displayName\n id\n }\n ...CommentItem_comment\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n" + "text": "query SinglePostFeedPaginationQuery(\n $after: String\n $before: String\n $first: Int = 10\n $last: Int\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...SinglePostFeed_post_pbnwq\n id\n }\n}\n\nfragment CommentItem_comment on PanoComment {\n id\n content\n createdAt\n owner {\n displayName\n id\n }\n commentCount\n ...CommentUpvoteButton_comment\n ...CommentMoreOptions_comment\n}\n\nfragment CommentMoreOptions_comment on PanoComment {\n id\n post {\n id\n }\n owner {\n displayName\n id\n }\n}\n\nfragment CommentUpvoteButton_comment on PanoComment {\n id\n isUpvotedByViewer\n upvoteCount\n}\n\nfragment MoreOptions_post on PanoPost {\n id\n owner {\n displayName\n id\n }\n}\n\nfragment PostItem_post on PanoPost {\n id\n title\n content\n url\n createdAt\n site\n commentCount\n ...PostUpvoteButton_post\n owner {\n displayName\n id\n }\n ...MoreOptions_post\n}\n\nfragment PostUpvoteButton_post on PanoPost {\n id\n isUpvotedByViewer\n upvoteCount\n}\n\nfragment SinglePostFeed_post_pbnwq on PanoPost {\n ...PostItem_post\n commentCount\n comments(first: $first, after: $after, last: $last, before: $before) {\n edges {\n node {\n id\n content\n createdAt\n owner {\n displayName\n id\n }\n ...CommentItem_comment\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n" } }; })(); diff --git a/apps/kampus/app/pano/features/comment-list/CommentMoreOptions.tsx b/apps/kampus/app/pano/features/comment-list/CommentMoreOptions.tsx index 05d00b32..977189f0 100644 --- a/apps/kampus/app/pano/features/comment-list/CommentMoreOptions.tsx +++ b/apps/kampus/app/pano/features/comment-list/CommentMoreOptions.tsx @@ -22,21 +22,25 @@ import { useToast, } from "@kampus/ui"; +import { getCommentURL } from "~/features/kampus-url/pano"; import { type CommentMoreOptions_comment$key } from "./__generated__/CommentMoreOptions_comment.graphql"; import { type CommentMoreOptions_viewer$key } from "./__generated__/CommentMoreOptions_viewer.graphql"; interface Props { - comment: CommentMoreOptions_comment$key | null; - viewerRef: CommentMoreOptions_viewer$key | null; + comment: CommentMoreOptions_comment$key; + viewerRef: CommentMoreOptions_viewer$key; commentConnectionID?: string; setEditOpen: React.Dispatch>; } -const useMoreOptionsCommentFragment = (key: CommentMoreOptions_comment$key | null) => +const useMoreOptionsCommentFragment = (key: CommentMoreOptions_comment$key) => useFragment( graphql` fragment CommentMoreOptions_comment on PanoComment { id + post @required(action: LOG) { + id + } owner { displayName } @@ -45,7 +49,7 @@ const useMoreOptionsCommentFragment = (key: CommentMoreOptions_comment$key | nul key ); -const useMoreOptionsViewerFragment = (key: CommentMoreOptions_viewer$key | null) => +const useMoreOptionsViewerFragment = (key: CommentMoreOptions_viewer$key) => useFragment( graphql` fragment CommentMoreOptions_viewer on Viewer { @@ -89,6 +93,9 @@ export const CommentMoreOptions = (props: Props) => { const { toast } = useToast(); const [removeComment, isRemoving] = useMutation(removeCommentMutation); + if (!comment) return null; + const shareUrl = getCommentURL({ postID: comment.post.id, commentID: comment.id }); + const onClick = () => { if (!comment) { return; @@ -125,8 +132,10 @@ export const CommentMoreOptions = (props: Props) => { )} { - toast({ - description: "Link kopyalandı", + void navigator.clipboard?.writeText(shareUrl).then(() => { + toast({ + description: "Link kopyalandı", + }); }); }} > diff --git a/apps/kampus/app/pano/features/comment-list/__generated__/CommentMoreOptions_comment.graphql.ts b/apps/kampus/app/pano/features/comment-list/__generated__/CommentMoreOptions_comment.graphql.ts index ddc0cd8e..4defbf7c 100644 --- a/apps/kampus/app/pano/features/comment-list/__generated__/CommentMoreOptions_comment.graphql.ts +++ b/apps/kampus/app/pano/features/comment-list/__generated__/CommentMoreOptions_comment.graphql.ts @@ -1,5 +1,5 @@ /** - * @generated SignedSource<> + * @generated SignedSource<<3c81d39b138324a82b5e40ad209ba5f5>> * @lightSyntaxTransform * @nogrep */ @@ -15,25 +15,47 @@ export type CommentMoreOptions_comment$data = { readonly owner: { readonly displayName: string | null; } | null; + readonly post: { + readonly id: string; + }; readonly " $fragmentType": "CommentMoreOptions_comment"; -}; +} | null; export type CommentMoreOptions_comment$key = { readonly " $data"?: CommentMoreOptions_comment$data; readonly " $fragmentSpreads": FragmentRefs<"CommentMoreOptions_comment">; }; -const node: ReaderFragment = { +const node: ReaderFragment = (function(){ +var v0 = { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "id", + "storageKey": null +}; +return { "argumentDefinitions": [], "kind": "Fragment", "metadata": null, "name": "CommentMoreOptions_comment", "selections": [ + (v0/*: any*/), { - "alias": null, - "args": null, - "kind": "ScalarField", - "name": "id", - "storageKey": null + "kind": "RequiredField", + "field": { + "alias": null, + "args": null, + "concreteType": "PanoPost", + "kind": "LinkedField", + "name": "post", + "plural": false, + "selections": [ + (v0/*: any*/) + ], + "storageKey": null + }, + "action": "LOG", + "path": "post" }, { "alias": null, @@ -57,7 +79,8 @@ const node: ReaderFragment = { "type": "PanoComment", "abstractKey": null }; +})(); -(node as any).hash = "8d099d051875d0adf45fc3e7191f22e8"; +(node as any).hash = "c4121b9e6ee30e11971e068a0e562e44"; export default node; diff --git a/apps/kampus/env.ts b/apps/kampus/env.ts index 24638916..9805c4c1 100644 --- a/apps/kampus/env.ts +++ b/apps/kampus/env.ts @@ -6,13 +6,13 @@ export const env = parseEnv( GQL_URL: process.env.NEXT_PUBLIC_GQL_URL, RESEND_API_KEY: process.env.RESEND_API_KEY, NEXTAUTH_URL: process.env.NEXTAUTH_URL, - KAMPUS_ENV: process.env.KAMPUS_ENV, + KAMPUS_ENV: process.env.KAMPUS_ENV ?? process.env.VERCEL_URL, }, { NODE_ENV: z.enum(["development", "test", "production"]), GQL_URL: z.string().url().default("http://localhost:4000/graphql"), RESEND_API_KEY: z.string().default("default-resend-key"), NEXTAUTH_URL: z.string().url().default("http://localhost:3001/auth"), - KAMPUS_ENV: z.enum(["development", "test", "production"]).default("development"), + KAMPUS_ENV: z.enum(["localhost", "preview", "development", "production"]).default("localhost"), } ); diff --git a/apps/kampus/features/kampus-url/get-kampus-url.ts b/apps/kampus/features/kampus-url/get-kampus-url.ts new file mode 100644 index 00000000..43cbca28 --- /dev/null +++ b/apps/kampus/features/kampus-url/get-kampus-url.ts @@ -0,0 +1,19 @@ +import { assertNever } from "@kampus/std"; + +import { env } from "~/env"; + +type KampusProduct = "sozluk" | "pano" | "pasaport"; + +export const getKampusURL = (product: KampusProduct, path: string = "") => { + switch (env.KAMPUS_ENV) { + case "localhost": + return `http://${product}.localhost.kamp.us:3000${path}`; + case "preview": + case "development": + return `https://${product}.dev.kamp.us${path}`; + case "production": + return `https://${product}.kamp.us${path}`; + default: + return assertNever(env.KAMPUS_ENV); + } +}; diff --git a/apps/kampus/features/kampus-url/pano.ts b/apps/kampus/features/kampus-url/pano.ts new file mode 100644 index 00000000..cc6ef9b1 --- /dev/null +++ b/apps/kampus/features/kampus-url/pano.ts @@ -0,0 +1,24 @@ +import { getKampusURL } from "./get-kampus-url"; + +export function getPostURL({ postID }: { postID: string }) { + return getKampusURL("pano", getPostLink(postID)); +} + +export function getCommentURL({ postID, commentID }: { postID: string; commentID: string }) { + return getKampusURL("pano", getCommentLink(postID, commentID)); +} + +function getPostLink(postID: string) { + return `/post/${postID}`; +} + +function getCommentLink(postID: string, commentID: string) { + const post = getPostLink(postID); + const comment = `#c_${commentID}`; + + return `${post}${comment}`; +} + +function getSitePostsLink(post: { site: string }) { + return `/site/${post.site}`; +} diff --git a/turbo.json b/turbo.json index df1ab4a3..d87d75ce 100644 --- a/turbo.json +++ b/turbo.json @@ -46,7 +46,7 @@ "dependsOn": ["@kampus/prisma#prisma:generate", "@kampus/sozluk-content#build"] }, "@kampus-apps/kampus#*": { - "env": ["NODE_ENV", "NEXT_PUBLIC_GQL_URL", "RESEND_API_KEY", "NEXTAUTH_URL", "KAMPUS_ENV"] + "env": ["NODE_ENV", "NEXT_PUBLIC_GQL_URL", "RESEND_API_KEY", "NEXTAUTH_URL", "KAMPUS_ENV", "VERCEL_URL"] }, "@kampus-apps/pasaport#*": { "env": ["NODE_ENV", "NEXTAUTH_URL", "DATABASE_URL", "KAMPUS_ENV"]