Skip to content

Commit

Permalink
feat: update paste code rel links
Browse files Browse the repository at this point in the history
dreamerblue committed Sep 24, 2024
1 parent 758c7db commit c9e7a56
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions .umirc.js
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ export default {
hash: true,
define: {
'process.env.COMPETITION_SIDE': process.env.COMPETITION_SIDE === '1' ? '1' : '',
'process.env.BASE': usingBuildConfig.base || '/',
'process.env.CDN_URL': process.env.CDN_URL || '',
'process.env.MEDIA_URL': process.env.MEDIA_URL || '',
'process.env.CDN_RAW_URL_BEFORE_PROXY': process.env.CDN_RAW_URL_BEFORE_PROXY || '',
15 changes: 13 additions & 2 deletions src/components/SolutionDetailPage.tsx
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ import tracker from '@/utils/tracker';
import Explanation from '@/components/Explanation';
import { addPiece } from '@/utils/pasteThenAC';
import ExtLink from './ExtLink';
import { urlf } from '@/utils/format';
import pages from '@/configs/pages';

export interface Props extends ReduxProps {
loading: boolean;
@@ -134,11 +136,18 @@ class SolutionDetailPage extends React.Component<Props, State> {
pasteCodeStatus: 'submitting',
pasteCodeUrl: '',
});
const problemId = this.props.data.problem?.problemId;
addPiece({
code: this.props.data.code,
lang: langsMap4Hljs[this.props.data.language],
ttl: 2592000, // 1 month
rel: window.location.href,
relLinks: [
window.location.href,
problemId &&
`${window.location.origin}${process.env.BASE}${urlf(pages.problems.detail, {
param: { id: problemId },
}).substring(1)}`,
].filter(Boolean),
})
.then((res) => {
if (!this._mounted) {
@@ -221,7 +230,9 @@ class SolutionDetailPage extends React.Component<Props, State> {
return (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<div>Share code link!</div>
<ExtLink href={this.state.pasteCodeUrl}>{this.state.pasteCodeUrl}</ExtLink>
<ExtLink href={this.state.pasteCodeUrl}>
<code>{this.state.pasteCodeUrl}</code>
</ExtLink>
<CopyToClipboardButton text={this.state.pasteCodeUrl} addNewLine={false}>
<Button type="primary" size="small" className="mt-md">
Copy URL
2 changes: 1 addition & 1 deletion src/utils/pasteThenAC.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ function formatAPIResponse(res: any) {


export function addPiece(
data: { code: string; lang: string; ttl: number, rel?: string },
data: { code: string; lang: string; ttl: number, relLinks?: string[] },
options: RequestInit = {},
): Promise<{ key: string; url: string }> {
return fetch(`${PASTE_THEN_AC_API_BASE_URL}/addPiece`, {

0 comments on commit c9e7a56

Please sign in to comment.