Skip to content

Commit b352524

Browse files
committed
migrate copybutton to tailwind
1 parent a8525cd commit b352524

File tree

6 files changed

+60
-93
lines changed

6 files changed

+60
-93
lines changed

.eslintrc.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ module.exports = {
1818
ecmaVersion: 12,
1919
sourceType: 'module',
2020
},
21-
plugins: ['react', '@typescript-eslint', 'jest', '@emotion'],
21+
plugins: ['react', '@typescript-eslint', 'jest'],
2222
rules: {
2323
'no-prototype-builtins': 'off',
2424
'react/no-unescaped-entities': 'off',
2525
'no-useless-escape': 'warn',
2626
'@typescript-eslint/no-empty-function': 'off',
2727
curly: ['error', 'multi-line'],
28-
'react/no-unknown-property': ['error', { ignore: ['css'] }],
2928
// some of these are just too hard to fix at the moment :(
3029
'react/prop-types': 'off',
3130
},

package.json

+35-37
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,57 @@
1212
"@dnd-kit/core": "^3.1.1",
1313
"@dnd-kit/sortable": "^4.0.0",
1414
"@emotion/core": "^11.0.0",
15-
"@emotion/react": "^11.11.3",
15+
"@emotion/eslint-plugin": "^11.11.0",
1616
"@headlessui/react": "^1.6.4",
1717
"@heroicons/react": "^1.0.6",
18+
"@mdx-js/loader": "^1.6.22",
1819
"@monaco-editor/react": "^4.4.5",
19-
"@primer/primitives": "^2.0.0",
2020
"@sentry/gatsby": "^7.2.0",
21+
"@storybook/addon-a11y": "^6.5.16",
22+
"@storybook/addon-actions": "^6.5.16",
23+
"@storybook/addon-essentials": "^6.5.16",
24+
"@storybook/addon-links": "^6.5.16",
25+
"@storybook/addon-postcss": "^2.0.0",
2126
"@storybook/builder-webpack5": "^6.5.16",
2227
"@storybook/manager-webpack5": "^6.5.16",
28+
"@storybook/react": "^6.5.16",
2329
"@tailwindcss/aspect-ratio": "^0.4.0",
2430
"@tailwindcss/forms": "^0.5.2",
2531
"@tailwindcss/typography": "^0.5.2",
2632
"@tailwindcss/ui": "^0.7.2",
33+
"@testing-library/jest-dom": "^5.14.1",
34+
"@testing-library/react": "^12.1.0",
2735
"@tippyjs/react": "^4.2.5",
36+
"@types/bad-words": "^3.0.1",
2837
"@types/reach__router": "^1.3.10",
38+
"@types/react": "^17.0.37",
2939
"@types/react-calendar-heatmap": "^1.6.6",
3040
"@types/seedrandom": "^3.0.8",
3141
"@types/styled-components": "^5.1.34",
42+
"@typescript-eslint/eslint-plugin": "^5.28.0",
43+
"@typescript-eslint/parser": "^5.28.0",
3244
"algoliasearch": "^4.10.5",
45+
"babel-jest": "^28.1.1",
46+
"babel-loader": "^8.2.5",
3347
"babel-plugin-remove-graphql-queries": "^4.16.0",
3448
"babel-plugin-styled-components": "^2.0.7",
49+
"babel-preset-gatsby": "^2.16.0",
50+
"babel-preset-react-app": "^10.0.1",
3551
"bad-words": "^3.0.4",
52+
"blob-polyfill": "^5.0.20210201",
3653
"broken-link-checker": "^0.7.8",
3754
"buffer": "^6.0.3",
55+
"bundlewatch": "^0.3.2",
56+
"chromatic": "^5.9.2",
3857
"classnames": "^2.3.1",
3958
"cssnano": "^5.0.8",
4059
"dayjs": "^1.11.3",
4160
"diff-match-patch": "^1.0.5",
4261
"dotenv": "^16.3.1",
62+
"eslint-plugin-jest": "^24.4.0",
4363
"firebase": "9.8.3",
64+
"firebase-admin": "^9.11.1",
65+
"firestore-export-import": "^0.17.0",
4466
"gatsby": "^4.25.7",
4567
"gatsby-image": "^3.11.0",
4668
"gatsby-plugin-algolia": "^0.24.0",
@@ -58,22 +80,29 @@
5880
"gatsby-plugin-sharp": "^4.16.1",
5981
"gatsby-plugin-sitemap": "^5.16.0",
6082
"gatsby-plugin-styled-components": "^5.16.0",
83+
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.32",
6184
"gatsby-remark-autolink-headers": "^5.16.0",
6285
"gatsby-source-filesystem": "^4.16.0",
6386
"gatsby-transformer-sharp": "^4.16.0",
6487
"github-slugger": "^1.4.0",
6588
"gray-matter": "^4.0.3",
6689
"hast-util-to-string": "1.0.4",
6790
"hast-util-to-text": "2.0.0",
91+
"identity-obj-proxy": "^3.0.0",
6892
"import-fresh": "^3.3.0",
93+
"jest": "^27.1.1",
6994
"jotai": "^2.6.1",
7095
"katex": "^0.16.0",
96+
"lint-staged": "^11.1.2",
7197
"loader-utils": "^2.0.4",
7298
"loadjs": "^4.2.0",
7399
"octokit": "^3.1.2",
74100
"postcss": "^8.4.31",
101+
"postcss-cli": "^8.3.1",
75102
"postcss-import": "^14.1.0",
76103
"postcss-nested": "^5.0.6",
104+
"prettier": "^2.7.1",
105+
"prettier-plugin-organize-imports": "^3.0.0",
77106
"prism-react-renderer": "^2.3.1",
78107
"prismjs": "^1.28.0",
79108
"process": "^0.11.10",
@@ -94,6 +123,7 @@
94123
"react-share": "^4.4.0",
95124
"react-simplemde-editor": "4.1.3",
96125
"react-split": "^2.0.14",
126+
"react-test-renderer": "^17.0.2",
97127
"react-youtube": "^7.13.1",
98128
"readline": "^1.3.0",
99129
"recharts": "^2.1.2",
@@ -110,7 +140,9 @@
110140
"remark-mdx-frontmatter": "1.1.1",
111141
"remark-slug": "6.0.0",
112142
"seedrandom": "^3.0.5",
143+
"serve": "^12.0.1",
113144
"storybook-addon-gatsby": "^0.0.5",
145+
"storybook-dark-mode": "^2.0.5",
114146
"styled-components": "^5.3.5",
115147
"tailwindcss": "^3.1.3",
116148
"tippy.js": "^6.3.1",
@@ -121,41 +153,7 @@
121153
"uuid": "^8.3.2",
122154
"webpack-filter-warnings-plugin": "^1.2.1",
123155
"worker-loader": "^3.0.8",
124-
"xdm": "1.12.2",
125-
"@emotion/eslint-plugin": "^11.11.0",
126-
"@mdx-js/loader": "^1.6.22",
127-
"@storybook/addon-a11y": "^6.5.16",
128-
"@storybook/addon-actions": "^6.5.16",
129-
"@storybook/addon-essentials": "^6.5.16",
130-
"@storybook/addon-links": "^6.5.16",
131-
"@storybook/addon-postcss": "^2.0.0",
132-
"@storybook/react": "^6.5.16",
133-
"@testing-library/jest-dom": "^5.14.1",
134-
"@testing-library/react": "^12.1.0",
135-
"@types/bad-words": "^3.0.1",
136-
"@types/react": "^17.0.37",
137-
"@typescript-eslint/eslint-plugin": "^5.28.0",
138-
"@typescript-eslint/parser": "^5.28.0",
139-
"babel-jest": "^28.1.1",
140-
"babel-loader": "^8.2.5",
141-
"babel-preset-gatsby": "^2.16.0",
142-
"babel-preset-react-app": "^10.0.1",
143-
"blob-polyfill": "^5.0.20210201",
144-
"bundlewatch": "^0.3.2",
145-
"chromatic": "^5.9.2",
146-
"eslint-plugin-jest": "^24.4.0",
147-
"firebase-admin": "^9.11.1",
148-
"firestore-export-import": "^0.17.0",
149-
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.32",
150-
"identity-obj-proxy": "^3.0.0",
151-
"jest": "^27.1.1",
152-
"lint-staged": "^11.1.2",
153-
"postcss-cli": "^8.3.1",
154-
"prettier": "^2.7.1",
155-
"prettier-plugin-organize-imports": "^3.0.0",
156-
"react-test-renderer": "^17.0.2",
157-
"serve": "^12.0.1",
158-
"storybook-dark-mode": "^2.0.5"
156+
"xdm": "1.12.2"
159157
},
160158
"resolutions": {
161159
"@types/react": "^17.0.37"

src/components/Editor/AddProblemModal.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import prettier from 'prettier';
33
import babelParser from 'prettier/parser-babel';
44
import React, { useRef, useState } from 'react';
55
import CopyButton from './CopyButton';
6-
import parse from './parsers/parse';
6+
import parse, { parsers } from './parsers/parse';
77
async function getHtml(url: string): Promise<string> {
88
const res = await fetch('/api/fetch-html', {
99
method: 'POST',
@@ -42,7 +42,13 @@ async function addProblem(
4242
);
4343
setStatus('Get Metadata');
4444
} catch (e) {
45-
alert(e);
45+
setMetadata(
46+
`No parser found for this url.
47+
Available parsers:
48+
${Object.keys(parsers)
49+
.map(key => ` - ${key}`)
50+
.join('\n')}`
51+
);
4652
setStatus('Get Metadata');
4753
}
4854
}

src/components/Editor/CopyButton.tsx

+6-39
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
// source: https://codesandbox.io/p/sandbox/copy-to-clipboard-animation-qt8pf
2-
// organize-imports-ignore
3-
/** @jsxRuntime classic */
4-
/** @jsx jsx */
5-
import { colors } from '@primer/primitives';
6-
import { jsx } from '@emotion/react';
72
import React from 'react';
83

94
export default function CopyButton({ className, onClick }) {
@@ -23,44 +18,18 @@ export default function CopyButton({ className, onClick }) {
2318
setCopied(true);
2419
onClick();
2520
}}
26-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
27-
// @ts-ignore
28-
css={{
29-
appearance: 'none',
30-
padding: 8,
31-
border: 0,
32-
outline: 0,
33-
cursor: 'pointer',
34-
}}
35-
className={className}
21+
className={`appearance-none p-2 border-0 outline-none cursor-pointer ${className}`}
3622
>
37-
<div
38-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
39-
// @ts-ignore
40-
css={{
41-
position: 'relative',
42-
height: 16,
43-
width: 16,
44-
}}
45-
>
23+
<div className="relative h-4 w-4">
4624
<Clippy
47-
css={{
48-
color: colors.gray[4],
49-
position: 'absolute',
50-
top: 0,
51-
left: 0,
25+
style={{
5226
strokeDasharray: 50,
5327
strokeDashoffset: copied ? -50 : 0,
5428
transition: 'all 300ms ease-in-out',
5529
}}
5630
/>
5731
<Check
58-
isVisible={copied}
59-
css={{
60-
color: colors.green[5],
61-
position: 'absolute',
62-
top: 0,
63-
left: 0,
32+
style={{
6433
strokeDasharray: 50,
6534
strokeDashoffset: copied ? 0 : -50,
6635
transition: 'all 300ms ease-in-out',
@@ -78,10 +47,9 @@ function Clippy(props) {
7847
height="16"
7948
viewBox="0 0 16 16"
8049
fill="none"
81-
stroke="currentColor"
82-
strokeWidth="1.5"
8350
strokeLinecap="round"
8451
strokeLinejoin="round"
52+
className="stroke-gray-400 stroke-[1.5] absolute top-0 left-0"
8553
{...props}
8654
>
8755
<path d="M5.75 4.75H10.25V1.75H5.75V4.75Z" />
@@ -97,11 +65,10 @@ function Check(props) {
9765
height="16"
9866
viewBox="0 0 16 16"
9967
fill="none"
100-
stroke="currentColor"
101-
strokeWidth="1.5"
10268
strokeLinecap="round"
10369
strokeLinejoin="round"
10470
{...props}
71+
className="stroke-green-500 stroke-[1.5] absolute top-0 left-0"
10572
>
10673
<path d="M13.25 4.75L6 12L2.75 8.75" />
10774
</svg>
+9-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import parseCf from './cf';
22
import parseUsaco from './usaco';
3-
3+
export const parsers = {
4+
'codeforces.com': parseCf,
5+
'usaco.org': parseUsaco,
6+
};
47
export default function parse(url: string, html: string) {
5-
if (url.includes('codeforces.com')) {
6-
return parseCf(url, html);
7-
} else if (url.includes('usaco.org')) {
8-
return parseUsaco(url, html);
9-
} else {
10-
throw new Error(`Problem source not supported yet :(`);
8+
for (const [domain, parser] of Object.entries(parsers)) {
9+
if (url.includes(domain)) {
10+
return parser(url, html);
11+
}
1112
}
13+
throw new Error('No parser found for this URL');
1214
}

yarn.lock

+1-6
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@
20102010
resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.8.1.tgz#c1ddb040429c6d21d38cc945fe75c818cfb68e17"
20112011
integrity sha512-W2P2c/VRW1/1tLox0mVUalvnWXxavmv/Oum2aPsRcoDJuob75FC3Y8FbpfLwUegRcxINtGUMPq0tFCvYNTBXNA==
20122012

2013-
"@emotion/react@^11.1.1", "@emotion/react@^11.11.3":
2013+
"@emotion/react@^11.1.1":
20142014
version "11.11.3"
20152015
resolved "https://registry.yarnpkg.com/@emotion/react/-/react-11.11.3.tgz#96b855dc40a2a55f52a72f518a41db4f69c31a25"
20162016
integrity sha512-Cnn0kuq4DoONOMcnoVsTOR8E+AdnKFf//6kUWc4LCdnxj31pZWn7rIULd6Y7/Js1PiPHzn7SKCM9vB/jBni8eA==
@@ -4393,11 +4393,6 @@
43934393
resolved "https://registry.npmjs.org/@popperjs/core/-/core-2.11.0.tgz"
43944394
integrity sha512-zrsUxjLOKAzdewIDRWy9nsV1GQsKBCWaGwsZQlCgr6/q+vjyZhFgqedLfFBuI9anTPEUT4APq9Mu0SZBTzIcGQ==
43954395

4396-
"@primer/primitives@^2.0.0":
4397-
version "2.0.1"
4398-
resolved "https://registry.yarnpkg.com/@primer/primitives/-/primitives-2.0.1.tgz#060b0882cdf75c3100db84100bb40538628bb63f"
4399-
integrity sha512-1zMGwqAfeTU3bOcsxzVgJlCPKTeDtDIP3h+Hm7qTvU0ez/87WZqjLKY6Jl7EBp9WH5VSm+LNwo56KfajInd3/w==
4400-
44014396
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2":
44024397
version "1.1.2"
44034398
resolved "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz"

0 commit comments

Comments
 (0)