Compare commits

..

2 Commits

Author SHA1 Message Date
Ivan Li
183564aed8 feat: Article 模块 2021-05-01 15:13:38 +08:00
Ivan
0b5fa5b643 feat: route-react -> curi. 2021-04-28 13:41:09 +08:00
14 changed files with 658 additions and 352 deletions

14
.vscode/launch.json vendored
View File

@ -5,19 +5,13 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch blog.localhost",
"type": "firefox",
"name": "chrome",
"type": "chrome",
"request": "launch",
"reAttach": true,
"url": "http://blog.localhost/",
"webRoot": "${workspaceFolder}"
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against blog.localhost",
"url": "http://blog.localhost/",
"webRoot": "${workspaceFolder}"
"webRoot": "${workspaceFolder}",
"userDataDir": "/Users/ivan/Projects/.chrome"
}
]
}

View File

@ -2,7 +2,7 @@ module.exports = {
client: {
service: {
name: 'blog-be',
url: 'http://localhost:7132/graphql'
url: 'http://api.blog.localhost/graphql'
}
}
};

532
package-lock.json generated
View File

@ -8,9 +8,13 @@
"version": "0.1.0",
"dependencies": {
"@apollo/client": "^3.3.15",
"@curi/react-dom": "^2.0.4",
"@curi/router": "^2.1.2",
"@date-io/date-fns": "^1.3.13",
"@hickory/browser": "^2.1.0",
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "*",
"@material-ui/pickers": "^3.3.10",
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
@ -25,9 +29,9 @@
"formik-material-ui": "^3.0.1",
"formik-material-ui-pickers": "^0.0.12",
"graphql": "^15.5.0",
"ramda": "^0.27.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"typescript": "^4.2.4",
"vditor": "^3.8.4",
@ -42,7 +46,7 @@
"@graphql-codegen/typescript-react-apollo": "2.2.3",
"@types/date-fns": "^2.6.0",
"@types/graphql": "^14.5.0",
"@types/react-router-dom": "^5.1.7",
"@types/ramda": "^0.27.40",
"@types/sass": "^1.16.0",
"@types/yup": "^0.29.11",
"sass": "^1.32.11"
@ -1270,6 +1274,92 @@
"resolved": "https://registry.npmjs.org/@csstools/normalize.css/-/normalize.css-10.1.0.tgz",
"integrity": "sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg=="
},
"node_modules/@curi/interactions": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@curi/interactions/-/interactions-2.0.3.tgz",
"integrity": "sha512-/d58jYFnWhqO4cMoFehxS/RWx3I22yCPnm6uAAE/1KEQG29k4uSkDKtxdIOMGcy6DnqFsOXXEFrh+ZLPIDQMBw==",
"dependencies": {
"@curi/types": "^2.0.2",
"@hickory/root": "^2.1.0"
}
},
"node_modules/@curi/react-dom": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@curi/react-dom/-/react-dom-2.0.4.tgz",
"integrity": "sha512-awgkkj/aQln0x4H7fB/2bZEAGRB6OjgQ4w1pQH2yz+zVK1xde2M+syL34rUCHxbAxh3dWHmsBxKnpHs0goRxwQ==",
"dependencies": {
"@curi/react-universal": "^2.0.3",
"@curi/types": "^2.0.2",
"@types/react": "^16.7.18"
},
"peerDependencies": {
"react": ">=16.8.0"
}
},
"node_modules/@curi/react-dom/node_modules/@types/react": {
"version": "16.14.5",
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.5.tgz",
"integrity": "sha512-YRRv9DNZhaVTVRh9Wmmit7Y0UFhEVqXqCSw3uazRWMxa2x85hWQZ5BN24i7GXZbaclaLXEcodEeIHsjBA8eAMw==",
"dependencies": {
"@types/prop-types": "*",
"@types/scheduler": "*",
"csstype": "^3.0.2"
}
},
"node_modules/@curi/react-universal": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@curi/react-universal/-/react-universal-2.0.3.tgz",
"integrity": "sha512-uBSq5iKUCaQg9BOKgkc6jQOR+uToxn4pHHVpVVPjJUstqlu9u1Sg2BrWvCdKLTYgMlH+XwgYmcVDh8+LdBdRXQ==",
"dependencies": {
"@curi/interactions": "^2.0.3",
"@curi/types": "^2.0.2",
"@hickory/root": "^2.1.0",
"@types/react": "^16.7.18"
},
"peerDependencies": {
"react": ">=16.8.0"
}
},
"node_modules/@curi/react-universal/node_modules/@types/react": {
"version": "16.14.5",
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.5.tgz",
"integrity": "sha512-YRRv9DNZhaVTVRh9Wmmit7Y0UFhEVqXqCSw3uazRWMxa2x85hWQZ5BN24i7GXZbaclaLXEcodEeIHsjBA8eAMw==",
"dependencies": {
"@types/prop-types": "*",
"@types/scheduler": "*",
"csstype": "^3.0.2"
}
},
"node_modules/@curi/router": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@curi/router/-/router-2.1.2.tgz",
"integrity": "sha512-XqESNXnlxlpiYl8VRyAsAkWjs3O4RFjH/crIodPE8gU314t/QRoD/G72GDq6xPRd90I4XekNA2y2uvMS1RAhKA==",
"dependencies": {
"@curi/interactions": "^2.0.3",
"@curi/types": "^2.0.2",
"@hickory/root": "^2.1.0",
"path-to-regexp": "^2.1.0"
}
},
"node_modules/@curi/router/node_modules/path-to-regexp": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-2.4.0.tgz",
"integrity": "sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w=="
},
"node_modules/@curi/types": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@curi/types/-/types-2.0.2.tgz",
"integrity": "sha512-e8VCWOCrmGvfakQTAapldCodAX2aMT9cgj41gboH064O5XJ69wQsZspqHNYxb/iKfdNhe0Wg83T5SW/3TTNcVg==",
"dependencies": {
"@hickory/root": "^2.1.0",
"path-to-regexp": "^2.1.0"
}
},
"node_modules/@curi/types/node_modules/path-to-regexp": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-2.4.0.tgz",
"integrity": "sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w=="
},
"node_modules/@date-io/core": {
"version": "1.3.13",
"resolved": "https://registry.npmjs.org/@date-io/core/-/core-1.3.13.tgz",
@ -2319,6 +2409,33 @@
"@hapi/hoek": "^8.3.0"
}
},
"node_modules/@hickory/browser": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@hickory/browser/-/browser-2.1.0.tgz",
"integrity": "sha512-bFTL4L/NKDBKA8PG1w3RBfsHdCZUieaFEYX42+YP+RFccEkUdCSz1EeIpL4lQuPOH4iW74p/4aijmhUGrDVjbw==",
"dependencies": {
"@hickory/dom-utils": "^2.1.0",
"@hickory/root": "^2.1.0"
}
},
"node_modules/@hickory/dom-utils": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@hickory/dom-utils/-/dom-utils-2.1.0.tgz",
"integrity": "sha512-fBzR0yWLFDLHcl6at+PaaXfC0c114DCYw+dwLzbvLLsGbEwWzQJaE4PGn1osR8teyWoqH6P2RYWVd95ua7lUuQ=="
},
"node_modules/@hickory/location-utils": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@hickory/location-utils/-/location-utils-2.1.0.tgz",
"integrity": "sha512-+PKHZ9fEbNAnnUzwk6RynvoQcW3/v8aw6jz1MHnSrdGM0lngiWrDQf1G78YFCIvcEm/FqAphmg7Nl8Cz7vaV6w=="
},
"node_modules/@hickory/root": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@hickory/root/-/root-2.1.0.tgz",
"integrity": "sha512-vRy4yadZp7mP47K8hpFpNKg3Ocxsmv+ezO9l4F7+GcscpD1JJiNLCnUNVuw+XIqUjuNvcyBoH8ToiEJCxWvvdA==",
"dependencies": {
"@hickory/location-utils": "^2.1.0"
}
},
"node_modules/@iarna/toml": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz",
@ -3033,6 +3150,32 @@
"node": ">=8.0.0"
}
},
"node_modules/@material-ui/lab": {
"version": "4.0.0-alpha.58",
"resolved": "https://registry.npmjs.org/@material-ui/lab/-/lab-4.0.0-alpha.58.tgz",
"integrity": "sha512-GKHlJqLxUeHH3L3dGQ48ZavYrqGOTXkFkiEiuYMAnAvXAZP4rhMIqeHOPXSUQan4Bd8QnafDcpovOSLnadDmKw==",
"dependencies": {
"@babel/runtime": "^7.4.4",
"@material-ui/utils": "^4.11.2",
"clsx": "^1.0.4",
"prop-types": "^15.7.2",
"react-is": "^16.8.0 || ^17.0.0"
},
"engines": {
"node": ">=8.0.0"
},
"peerDependencies": {
"@material-ui/core": "^4.9.10",
"@types/react": "^16.8.6 || ^17.0.0",
"react": "^16.8.0 || ^17.0.0",
"react-dom": "^16.8.0 || ^17.0.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@material-ui/pickers": {
"version": "3.3.10",
"resolved": "https://registry.npmjs.org/@material-ui/pickers/-/pickers-3.3.10.tgz",
@ -3762,12 +3905,6 @@
"graphql": "*"
}
},
"node_modules/@types/history": {
"version": "4.7.8",
"resolved": "https://registry.npmjs.org/@types/history/-/history-4.7.8.tgz",
"integrity": "sha512-S78QIYirQcUoo6UJZx9CSP0O2ix9IaeAXwQi26Rhr/+mg7qqPy8TzaxHSUut7eGjL8WmLccT7/MXf304WjqHcA==",
"dev": true
},
"node_modules/@types/html-minifier-terser": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/@types/html-minifier-terser/-/html-minifier-terser-5.1.1.tgz",
@ -3883,6 +4020,15 @@
"resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.4.tgz",
"integrity": "sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug=="
},
"node_modules/@types/ramda": {
"version": "0.27.40",
"resolved": "https://registry.npmjs.org/@types/ramda/-/ramda-0.27.40.tgz",
"integrity": "sha512-V99ZfTH2tqVYdLDAlgh2uT+N074HPgqnAsMjALKSBqogYd0HbuuGMqNukJ6fk9Ml/Htaus76fsc4Yh3p7q1VdQ==",
"dev": true,
"dependencies": {
"ts-toolbelt": "^6.15.1"
}
},
"node_modules/@types/react": {
"version": "17.0.3",
"resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.3.tgz",
@ -3901,27 +4047,6 @@
"@types/react": "*"
}
},
"node_modules/@types/react-router": {
"version": "5.1.13",
"resolved": "https://registry.npmjs.org/@types/react-router/-/react-router-5.1.13.tgz",
"integrity": "sha512-ZIuaO9Yrln54X6elg8q2Ivp6iK6p4syPsefEYAhRDAoqNh48C8VYUmB9RkXjKSQAJSJV0mbIFCX7I4vZDcHrjg==",
"dev": true,
"dependencies": {
"@types/history": "*",
"@types/react": "*"
}
},
"node_modules/@types/react-router-dom": {
"version": "5.1.7",
"resolved": "https://registry.npmjs.org/@types/react-router-dom/-/react-router-dom-5.1.7.tgz",
"integrity": "sha512-D5mHD6TbdV/DNHYsnwBTv+y73ei+mMjrkGrla86HthE4/PVvL1J94Bu3qABU+COXzpL23T1EZapVVpwHuBXiUg==",
"dev": true,
"dependencies": {
"@types/history": "*",
"@types/react": "*",
"@types/react-router": "*"
}
},
"node_modules/@types/react-transition-group": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.1.tgz",
@ -10559,19 +10684,6 @@
"resolved": "https://registry.npmjs.org/hex-color-regex/-/hex-color-regex-1.1.0.tgz",
"integrity": "sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ=="
},
"node_modules/history": {
"version": "4.10.1",
"resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz",
"integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==",
"dependencies": {
"@babel/runtime": "^7.1.2",
"loose-envify": "^1.2.0",
"resolve-pathname": "^3.0.0",
"tiny-invariant": "^1.0.2",
"tiny-warning": "^1.0.0",
"value-equal": "^1.0.1"
}
},
"node_modules/hmac-drbg": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz",
@ -15174,15 +15286,6 @@
"node": ">=4"
}
},
"node_modules/mini-create-react-context": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/mini-create-react-context/-/mini-create-react-context-0.4.1.tgz",
"integrity": "sha512-YWCYEmd5CQeHGSAKrYvXgmzzkrvssZcuuQDDeqkT+PziKGMgE+0MCCtcKbROzocGBG1meBLl2FotlRwf4gAzbQ==",
"dependencies": {
"@babel/runtime": "^7.12.1",
"tiny-warning": "^1.0.3"
}
},
"node_modules/mini-css-extract-plugin": {
"version": "0.11.3",
"resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-0.11.3.tgz",
@ -18055,6 +18158,11 @@
"performance-now": "^2.1.0"
}
},
"node_modules/ramda": {
"version": "0.27.1",
"resolved": "https://registry.npmjs.org/ramda/-/ramda-0.27.1.tgz",
"integrity": "sha512-PgIdVpn5y5Yns8vqb8FzBUEYn98V3xcPgawAkkgj0YJ0qDsnHCiNmZYfOGMgOvoB0eWFLpYbhxUR3mxfDIMvpw=="
},
"node_modules/randombytes": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
@ -18324,50 +18432,6 @@
"node": ">=0.10.0"
}
},
"node_modules/react-router": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-5.2.0.tgz",
"integrity": "sha512-smz1DUuFHRKdcJC0jobGo8cVbhO3x50tCL4icacOlcwDOEQPq4TMqwx3sY1TP+DvtTgz4nm3thuo7A+BK2U0Dw==",
"dependencies": {
"@babel/runtime": "^7.1.2",
"history": "^4.9.0",
"hoist-non-react-statics": "^3.1.0",
"loose-envify": "^1.3.1",
"mini-create-react-context": "^0.4.0",
"path-to-regexp": "^1.7.0",
"prop-types": "^15.6.2",
"react-is": "^16.6.0",
"tiny-invariant": "^1.0.2",
"tiny-warning": "^1.0.0"
}
},
"node_modules/react-router-dom": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.2.0.tgz",
"integrity": "sha512-gxAmfylo2QUjcwxI63RhQ5G85Qqt4voZpUXSEqCwykV0baaOTQDR1f0PmY8AELqIyVc0NEZUj0Gov5lNGcXgsA==",
"dependencies": {
"@babel/runtime": "^7.1.2",
"history": "^4.9.0",
"loose-envify": "^1.3.1",
"prop-types": "^15.6.2",
"react-router": "5.2.0",
"tiny-invariant": "^1.0.2",
"tiny-warning": "^1.0.0"
}
},
"node_modules/react-router/node_modules/isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"node_modules/react-router/node_modules/path-to-regexp": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz",
"integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==",
"dependencies": {
"isarray": "0.0.1"
}
},
"node_modules/react-scripts": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-4.0.3.tgz",
@ -19068,11 +19132,6 @@
"node": ">=4"
}
},
"node_modules/resolve-pathname": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-3.0.0.tgz",
"integrity": "sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng=="
},
"node_modules/resolve-url": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz",
@ -21210,11 +21269,6 @@
"resolved": "https://registry.npmjs.org/timsort/-/timsort-0.3.0.tgz",
"integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q="
},
"node_modules/tiny-invariant": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.1.0.tgz",
"integrity": "sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw=="
},
"node_modules/tiny-warning": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz",
@ -21424,6 +21478,12 @@
"node": ">=6"
}
},
"node_modules/ts-toolbelt": {
"version": "6.15.5",
"resolved": "https://registry.npmjs.org/ts-toolbelt/-/ts-toolbelt-6.15.5.tgz",
"integrity": "sha512-FZIXf1ksVyLcfr7M317jbB67XFJhOO1YqdTcuGaq9q5jLUoTikukZ+98TPjKiP2jC5CgmYdWWYs0s2nLSU0/1A==",
"dev": true
},
"node_modules/tsconfig-paths": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz",
@ -21987,11 +22047,6 @@
"spdx-expression-parse": "^3.0.0"
}
},
"node_modules/value-equal": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/value-equal/-/value-equal-1.0.1.tgz",
"integrity": "sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw=="
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
@ -25056,6 +25111,94 @@
"resolved": "https://registry.npmjs.org/@csstools/normalize.css/-/normalize.css-10.1.0.tgz",
"integrity": "sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg=="
},
"@curi/interactions": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@curi/interactions/-/interactions-2.0.3.tgz",
"integrity": "sha512-/d58jYFnWhqO4cMoFehxS/RWx3I22yCPnm6uAAE/1KEQG29k4uSkDKtxdIOMGcy6DnqFsOXXEFrh+ZLPIDQMBw==",
"requires": {
"@curi/types": "^2.0.2",
"@hickory/root": "^2.1.0"
}
},
"@curi/react-dom": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@curi/react-dom/-/react-dom-2.0.4.tgz",
"integrity": "sha512-awgkkj/aQln0x4H7fB/2bZEAGRB6OjgQ4w1pQH2yz+zVK1xde2M+syL34rUCHxbAxh3dWHmsBxKnpHs0goRxwQ==",
"requires": {
"@curi/react-universal": "^2.0.3",
"@curi/types": "^2.0.2",
"@types/react": "^16.7.18"
},
"dependencies": {
"@types/react": {
"version": "16.14.5",
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.5.tgz",
"integrity": "sha512-YRRv9DNZhaVTVRh9Wmmit7Y0UFhEVqXqCSw3uazRWMxa2x85hWQZ5BN24i7GXZbaclaLXEcodEeIHsjBA8eAMw==",
"requires": {
"@types/prop-types": "*",
"@types/scheduler": "*",
"csstype": "^3.0.2"
}
}
}
},
"@curi/react-universal": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@curi/react-universal/-/react-universal-2.0.3.tgz",
"integrity": "sha512-uBSq5iKUCaQg9BOKgkc6jQOR+uToxn4pHHVpVVPjJUstqlu9u1Sg2BrWvCdKLTYgMlH+XwgYmcVDh8+LdBdRXQ==",
"requires": {
"@curi/interactions": "^2.0.3",
"@curi/types": "^2.0.2",
"@hickory/root": "^2.1.0",
"@types/react": "^16.7.18"
},
"dependencies": {
"@types/react": {
"version": "16.14.5",
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.5.tgz",
"integrity": "sha512-YRRv9DNZhaVTVRh9Wmmit7Y0UFhEVqXqCSw3uazRWMxa2x85hWQZ5BN24i7GXZbaclaLXEcodEeIHsjBA8eAMw==",
"requires": {
"@types/prop-types": "*",
"@types/scheduler": "*",
"csstype": "^3.0.2"
}
}
}
},
"@curi/router": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@curi/router/-/router-2.1.2.tgz",
"integrity": "sha512-XqESNXnlxlpiYl8VRyAsAkWjs3O4RFjH/crIodPE8gU314t/QRoD/G72GDq6xPRd90I4XekNA2y2uvMS1RAhKA==",
"requires": {
"@curi/interactions": "^2.0.3",
"@curi/types": "^2.0.2",
"@hickory/root": "^2.1.0",
"path-to-regexp": "^2.1.0"
},
"dependencies": {
"path-to-regexp": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-2.4.0.tgz",
"integrity": "sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w=="
}
}
},
"@curi/types": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@curi/types/-/types-2.0.2.tgz",
"integrity": "sha512-e8VCWOCrmGvfakQTAapldCodAX2aMT9cgj41gboH064O5XJ69wQsZspqHNYxb/iKfdNhe0Wg83T5SW/3TTNcVg==",
"requires": {
"@hickory/root": "^2.1.0",
"path-to-regexp": "^2.1.0"
},
"dependencies": {
"path-to-regexp": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-2.4.0.tgz",
"integrity": "sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w=="
}
}
},
"@date-io/core": {
"version": "1.3.13",
"resolved": "https://registry.npmjs.org/@date-io/core/-/core-1.3.13.tgz",
@ -26067,6 +26210,33 @@
"@hapi/hoek": "^8.3.0"
}
},
"@hickory/browser": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@hickory/browser/-/browser-2.1.0.tgz",
"integrity": "sha512-bFTL4L/NKDBKA8PG1w3RBfsHdCZUieaFEYX42+YP+RFccEkUdCSz1EeIpL4lQuPOH4iW74p/4aijmhUGrDVjbw==",
"requires": {
"@hickory/dom-utils": "^2.1.0",
"@hickory/root": "^2.1.0"
}
},
"@hickory/dom-utils": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@hickory/dom-utils/-/dom-utils-2.1.0.tgz",
"integrity": "sha512-fBzR0yWLFDLHcl6at+PaaXfC0c114DCYw+dwLzbvLLsGbEwWzQJaE4PGn1osR8teyWoqH6P2RYWVd95ua7lUuQ=="
},
"@hickory/location-utils": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@hickory/location-utils/-/location-utils-2.1.0.tgz",
"integrity": "sha512-+PKHZ9fEbNAnnUzwk6RynvoQcW3/v8aw6jz1MHnSrdGM0lngiWrDQf1G78YFCIvcEm/FqAphmg7Nl8Cz7vaV6w=="
},
"@hickory/root": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@hickory/root/-/root-2.1.0.tgz",
"integrity": "sha512-vRy4yadZp7mP47K8hpFpNKg3Ocxsmv+ezO9l4F7+GcscpD1JJiNLCnUNVuw+XIqUjuNvcyBoH8ToiEJCxWvvdA==",
"requires": {
"@hickory/location-utils": "^2.1.0"
}
},
"@iarna/toml": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz",
@ -26638,6 +26808,18 @@
"@babel/runtime": "^7.4.4"
}
},
"@material-ui/lab": {
"version": "4.0.0-alpha.58",
"resolved": "https://registry.npmjs.org/@material-ui/lab/-/lab-4.0.0-alpha.58.tgz",
"integrity": "sha512-GKHlJqLxUeHH3L3dGQ48ZavYrqGOTXkFkiEiuYMAnAvXAZP4rhMIqeHOPXSUQan4Bd8QnafDcpovOSLnadDmKw==",
"requires": {
"@babel/runtime": "^7.4.4",
"@material-ui/utils": "^4.11.2",
"clsx": "^1.0.4",
"prop-types": "^15.7.2",
"react-is": "^16.8.0 || ^17.0.0"
}
},
"@material-ui/pickers": {
"version": "3.3.10",
"resolved": "https://registry.npmjs.org/@material-ui/pickers/-/pickers-3.3.10.tgz",
@ -27231,12 +27413,6 @@
"graphql": "*"
}
},
"@types/history": {
"version": "4.7.8",
"resolved": "https://registry.npmjs.org/@types/history/-/history-4.7.8.tgz",
"integrity": "sha512-S78QIYirQcUoo6UJZx9CSP0O2ix9IaeAXwQi26Rhr/+mg7qqPy8TzaxHSUut7eGjL8WmLccT7/MXf304WjqHcA==",
"dev": true
},
"@types/html-minifier-terser": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/@types/html-minifier-terser/-/html-minifier-terser-5.1.1.tgz",
@ -27352,6 +27528,15 @@
"resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.4.tgz",
"integrity": "sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug=="
},
"@types/ramda": {
"version": "0.27.40",
"resolved": "https://registry.npmjs.org/@types/ramda/-/ramda-0.27.40.tgz",
"integrity": "sha512-V99ZfTH2tqVYdLDAlgh2uT+N074HPgqnAsMjALKSBqogYd0HbuuGMqNukJ6fk9Ml/Htaus76fsc4Yh3p7q1VdQ==",
"dev": true,
"requires": {
"ts-toolbelt": "^6.15.1"
}
},
"@types/react": {
"version": "17.0.3",
"resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.3.tgz",
@ -27370,27 +27555,6 @@
"@types/react": "*"
}
},
"@types/react-router": {
"version": "5.1.13",
"resolved": "https://registry.npmjs.org/@types/react-router/-/react-router-5.1.13.tgz",
"integrity": "sha512-ZIuaO9Yrln54X6elg8q2Ivp6iK6p4syPsefEYAhRDAoqNh48C8VYUmB9RkXjKSQAJSJV0mbIFCX7I4vZDcHrjg==",
"dev": true,
"requires": {
"@types/history": "*",
"@types/react": "*"
}
},
"@types/react-router-dom": {
"version": "5.1.7",
"resolved": "https://registry.npmjs.org/@types/react-router-dom/-/react-router-dom-5.1.7.tgz",
"integrity": "sha512-D5mHD6TbdV/DNHYsnwBTv+y73ei+mMjrkGrla86HthE4/PVvL1J94Bu3qABU+COXzpL23T1EZapVVpwHuBXiUg==",
"dev": true,
"requires": {
"@types/history": "*",
"@types/react": "*",
"@types/react-router": "*"
}
},
"@types/react-transition-group": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.1.tgz",
@ -33039,19 +33203,6 @@
"resolved": "https://registry.npmjs.org/hex-color-regex/-/hex-color-regex-1.1.0.tgz",
"integrity": "sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ=="
},
"history": {
"version": "4.10.1",
"resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz",
"integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==",
"requires": {
"@babel/runtime": "^7.1.2",
"loose-envify": "^1.2.0",
"resolve-pathname": "^3.0.0",
"tiny-invariant": "^1.0.2",
"tiny-warning": "^1.0.0",
"value-equal": "^1.0.1"
}
},
"hmac-drbg": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz",
@ -36774,15 +36925,6 @@
"resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz",
"integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg=="
},
"mini-create-react-context": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/mini-create-react-context/-/mini-create-react-context-0.4.1.tgz",
"integrity": "sha512-YWCYEmd5CQeHGSAKrYvXgmzzkrvssZcuuQDDeqkT+PziKGMgE+0MCCtcKbROzocGBG1meBLl2FotlRwf4gAzbQ==",
"requires": {
"@babel/runtime": "^7.12.1",
"tiny-warning": "^1.0.3"
}
},
"mini-css-extract-plugin": {
"version": "0.11.3",
"resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-0.11.3.tgz",
@ -39169,6 +39311,11 @@
"performance-now": "^2.1.0"
}
},
"ramda": {
"version": "0.27.1",
"resolved": "https://registry.npmjs.org/ramda/-/ramda-0.27.1.tgz",
"integrity": "sha512-PgIdVpn5y5Yns8vqb8FzBUEYn98V3xcPgawAkkgj0YJ0qDsnHCiNmZYfOGMgOvoB0eWFLpYbhxUR3mxfDIMvpw=="
},
"randombytes": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
@ -39387,52 +39534,6 @@
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.8.3.tgz",
"integrity": "sha512-X8jZHc7nCMjaCqoU+V2I0cOhNW+QMBwSUkeXnTi8IPe6zaRWfn60ZzvFDZqWPfmSJfjub7dDW1SP0jaHWLu/hg=="
},
"react-router": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-5.2.0.tgz",
"integrity": "sha512-smz1DUuFHRKdcJC0jobGo8cVbhO3x50tCL4icacOlcwDOEQPq4TMqwx3sY1TP+DvtTgz4nm3thuo7A+BK2U0Dw==",
"requires": {
"@babel/runtime": "^7.1.2",
"history": "^4.9.0",
"hoist-non-react-statics": "^3.1.0",
"loose-envify": "^1.3.1",
"mini-create-react-context": "^0.4.0",
"path-to-regexp": "^1.7.0",
"prop-types": "^15.6.2",
"react-is": "^16.6.0",
"tiny-invariant": "^1.0.2",
"tiny-warning": "^1.0.0"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"path-to-regexp": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz",
"integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==",
"requires": {
"isarray": "0.0.1"
}
}
}
},
"react-router-dom": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.2.0.tgz",
"integrity": "sha512-gxAmfylo2QUjcwxI63RhQ5G85Qqt4voZpUXSEqCwykV0baaOTQDR1f0PmY8AELqIyVc0NEZUj0Gov5lNGcXgsA==",
"requires": {
"@babel/runtime": "^7.1.2",
"history": "^4.9.0",
"loose-envify": "^1.3.1",
"prop-types": "^15.6.2",
"react-router": "5.2.0",
"tiny-invariant": "^1.0.2",
"tiny-warning": "^1.0.0"
}
},
"react-scripts": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-4.0.3.tgz",
@ -40000,11 +40101,6 @@
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
"integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g=="
},
"resolve-pathname": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-3.0.0.tgz",
"integrity": "sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng=="
},
"resolve-url": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz",
@ -41843,11 +41939,6 @@
"resolved": "https://registry.npmjs.org/timsort/-/timsort-0.3.0.tgz",
"integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q="
},
"tiny-invariant": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.1.0.tgz",
"integrity": "sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw=="
},
"tiny-warning": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz",
@ -42017,6 +42108,12 @@
"resolved": "https://registry.npmjs.org/ts-pnp/-/ts-pnp-1.2.0.tgz",
"integrity": "sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw=="
},
"ts-toolbelt": {
"version": "6.15.5",
"resolved": "https://registry.npmjs.org/ts-toolbelt/-/ts-toolbelt-6.15.5.tgz",
"integrity": "sha512-FZIXf1ksVyLcfr7M317jbB67XFJhOO1YqdTcuGaq9q5jLUoTikukZ+98TPjKiP2jC5CgmYdWWYs0s2nLSU0/1A==",
"dev": true
},
"tsconfig-paths": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz",
@ -42492,11 +42589,6 @@
"spdx-expression-parse": "^3.0.0"
}
},
"value-equal": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/value-equal/-/value-equal-1.0.1.tgz",
"integrity": "sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw=="
},
"vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",

View File

@ -4,9 +4,13 @@
"private": true,
"dependencies": {
"@apollo/client": "^3.3.15",
"@curi/react-dom": "^2.0.4",
"@curi/router": "^2.1.2",
"@date-io/date-fns": "^1.3.13",
"@hickory/browser": "^2.1.0",
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "*",
"@material-ui/pickers": "^3.3.10",
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
@ -21,9 +25,9 @@
"formik-material-ui": "^3.0.1",
"formik-material-ui-pickers": "^0.0.12",
"graphql": "^15.5.0",
"ramda": "^0.27.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"typescript": "^4.2.4",
"vditor": "^3.8.4",
@ -31,8 +35,7 @@
"yup": "^0.32.9"
},
"scripts": {
"prestart": "npm run graphql",
"start": "PORT=7133 react-scripts start",
"start": "PORT=7133 BROWSER=none react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
@ -64,7 +67,7 @@
"@graphql-codegen/typescript-react-apollo": "2.2.3",
"@types/date-fns": "^2.6.0",
"@types/graphql": "^14.5.0",
"@types/react-router-dom": "^5.1.7",
"@types/ramda": "^0.27.40",
"@types/sass": "^1.16.0",
"@types/yup": "^0.29.11",
"sass": "^1.32.11"

View File

@ -1,9 +1,15 @@
import { useResponse } from '@curi/react-dom';
import './App.css';
import { DefaultLayout } from './layouts';
function App() {
const { response } = useResponse();
const { body: Body } = response;
return (
<DefaultLayout></DefaultLayout>
<DefaultLayout>
<Body response={response} />
</DefaultLayout>
);
}

View File

@ -9,20 +9,32 @@ import { Field, Form, Formik, FormikHelpers } from "formik";
import { FC } from "react";
import { Editor } from "../commons/editor/vditor";
import * as Yup from "yup";
import {
CreateArticleInput,
UpdateArticleInput,
} from "../generated/graphql";
import { DateTimePicker } from 'formik-material-ui-pickers';
import { gql, useMutation } from '@apollo/client';
import { Article, CreateArticleInput, UpdateArticleInput } from "../generated/graphql";
import { DateTimePicker } from "formik-material-ui-pickers";
import { gql, useMutation } from "@apollo/client";
import { useRouter } from "@curi/react-universal";
const CREATE_ARTICLE = gql`
mutation createArticle($input: CreateArticleInput!) {
createArticle(input: $input) {
id,
mutation createArticle($createArticleInput: CreateArticleInput!) {
createArticle(createArticleInput: $createArticleInput) {
id
title
content
publishedAt
}
}
}
`
`;
const UPDATE_ARTICLE = gql`
mutation updateArticle($updateArticleInput: UpdateArticleInput!) {
updateArticle(updateArticleInput: $updateArticleInput) {
id
title
content
publishedAt
}
}
`;
const useStyles = makeStyles((theme) =>
createStyles({
@ -47,32 +59,90 @@ export const ArticleEditor: FC<Props> = ({ article }) => {
content: Yup.string()
.max(65535, "文章内容不得超过 65535 个字符")
.required("文章内容不得为空"),
publishedAt: Yup.date()
publishedAt: Yup.date(),
});
const router = useRouter();
const [createArticle] = useMutation(CREATE_ARTICLE);
const [createArticle] = useMutation<{createArticle: Article} ,{
createArticleInput: CreateArticleInput;
}>(CREATE_ARTICLE, {
update(cache, { data }) {
cache.modify({
fields: {
articles(existingArticles = []) {
const newArticleRef = cache.writeFragment({
data: data!.createArticle,
fragment: gql`
fragment NewArticle on Article {
id
title
content
publishedAt
}
`,
});
return [newArticleRef, ...existingArticles];
},
},
});
},
});
const [updateArticle] = useMutation<{
updateArticleInput: UpdateArticleInput;
}>(UPDATE_ARTICLE);
const SubmitForm = (
values: Values,
{ setSubmitting }: FormikHelpers<Values>
) => {
if ('id' in article!) {
console.log('update', article)
} else {
const title = /# (.+)$/.exec(values.content ?? '')?.[1];
if ("id" in article!) {
const title = /# (.+)$/m.exec(values.content ?? "")?.[1];
if (!title) {
console.log('no title')
console.log("no title");
setSubmitting(false);
return;
}
updateArticle({
variables: {
updateArticleInput: {
...values,
title,
},
},
})
.then(() => {
router.navigate({
url: router.url({ name: "articles" }),
method: "replace",
});
})
.finally(() => {
setSubmitting(false);
});
} else {
const title = /# (.+)$/m.exec(values.content ?? "")?.[1];
if (!title) {
console.log("no title");
setSubmitting(false);
return;
}
createArticle({
variables: {
...values,
title,
createArticleInput: {
...values as CreateArticleInput,
title,
},
},
}).finally(() => {
setSubmitting(false);
});
})
.then(() => {
router.navigate({
url: router.url({ name: "articles" }),
method: "replace",
});
})
.finally(() => {
setSubmitting(false);
});
}
setSubmitting(false);
};

View File

@ -0,0 +1,82 @@
import { useMutation, useQuery } from "@apollo/client";
import {
IconButton,
Paper,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
} from "@material-ui/core";
import React, { FC } from "react";
import { Article } from "../generated/graphql";
import EditIcon from "@material-ui/icons/Edit";
import { useRouter } from "@curi/react-dom";
import { ARTICLES, REMOVE_ARTICLE } from './articles.constants';
import { Delete } from '@material-ui/icons';
export const ArticleIndex: FC = () => {
const { data } = useQuery<{
articles: Article[];
}>(ARTICLES, {});
const [removeArticle] = useMutation<any, { id: string }>(REMOVE_ARTICLE);
const router = useRouter();
return (
<section>
<TableContainer component={Paper}>
<Table aria-label="articles table">
<TableHead>
<TableRow>
<TableCell>Article Title</TableCell>
<TableCell>Published At</TableCell>
<TableCell>Views</TableCell>
<TableCell>Comments</TableCell>
<TableCell>Actions</TableCell>
</TableRow>
</TableHead>
<TableBody>
{data?.articles.map((article) => (
<TableRow key={article.id}>
<TableCell component="th" scope="row">
{article.title}
</TableCell>
<TableCell>{article.publishedAt}</TableCell>
<TableCell align="right"> -- </TableCell>
<TableCell align="right"> -- </TableCell>
<TableCell>
<IconButton
aria-label="edit"
onClick={() =>
router.navigate({
url: router.url({
name: "modify-article",
params: article,
}),
})
}
>
<EditIcon />
</IconButton>
<IconButton
aria-label="delete"
onClick={() =>
removeArticle({
variables: article,
})
}
>
<Delete />
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</section>
);
};

View File

@ -0,0 +1,26 @@
import { gql } from "@apollo/client";
export const ARTICLE = gql`
query Article($id: String!) {
article(id: $id) {
id
title
content
publishedAt
}
}
`;
export const ARTICLES = gql`
query Articles {
articles {
id
title
publishedAt
}
}
`;
export const REMOVE_ARTICLE = gql`
mutation RemoveArticle($id: String!) {
removeArticle(id: $id)
}
`;

3
src/articles/index.ts Normal file
View File

@ -0,0 +1,3 @@
export * from './article-editor';
export * from './articles-index';
export * from './articles.constants'

View File

@ -1,56 +0,0 @@
import { gql, useQuery } from "@apollo/client";
import {
Paper,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
} from "@material-ui/core";
import React, { FC } from "react";
import { Article } from '../generated/graphql';
const articles = gql`
query Articles {
articles {
id
title
publishedAt
}
}`;
export const ArticleIndex: FC = () => {
const { data } = useQuery<{
articles: Article[];
}>(articles, {});
return (
<section>
<TableContainer component={Paper}>
<Table aria-label="articles table">
<TableHead>
<TableRow>
<TableCell>Article Title</TableCell>
<TableCell>Published At</TableCell>
<TableCell>Views</TableCell>
<TableCell>Comments</TableCell>
</TableRow>
</TableHead>
<TableBody>
{data?.articles.map((article) => (
<TableRow key={article.id}>
<TableCell component="th" scope="row">
{article.title}
</TableCell>
<TableCell align="right">{article.publishedAt}</TableCell>
<TableCell align="right"> -- </TableCell>
<TableCell align="right"> -- </TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</section>
);
};

View File

@ -1,4 +1,4 @@
import { FormControl, FormHelperText, FormLabel } from '@material-ui/core';
import { createStyles, FormControl, FormHelperText, FormLabel, makeStyles } from '@material-ui/core';
import { FieldHookConfig, useField } from 'formik';
import React, { FC, useEffect, useRef, useState } from 'react';
import Vditor from 'vditor';
@ -9,6 +9,14 @@ type Props = (FieldHookConfig<string>) & {
className?: string;
};
const useStyles = makeStyles((theme) =>
createStyles({
formControl: {
width: '100%',
},
})
);
export const Editor: FC<Props> = ({ label, className, ...props }) => {
const [field, meta, helpers] = useField(props);
const editor = useRef<HTMLDivElement>(null);
@ -25,6 +33,7 @@ export const Editor: FC<Props> = ({ label, className, ...props }) => {
fullscreen: {
index: 1500,
},
value: meta.initialValue,
input: (val) => helpers.setValue(val),
blur: () => helpers.setTouched(true),
});
@ -33,8 +42,10 @@ export const Editor: FC<Props> = ({ label, className, ...props }) => {
instance?.destroy();
};
}, []);
const classes = useStyles();
return (
<FormControl>
<FormControl className={classes.formControl}>
<FormLabel>{label}</FormLabel>
<div className={className} ref={editor} key={containerKey}></div>
{meta.error && <FormHelperText error={true}>{meta.error}</FormHelperText>}

View File

@ -1,25 +1,43 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import "fontsource-roboto";
import App from './App';
import reportWebVitals from './reportWebVitals';
import { client } from './commons/graphql/client';
import { ApolloProvider } from '@apollo/client';
import { MuiPickersUtilsProvider } from '@material-ui/pickers';
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { client } from "./commons/graphql/client";
import { ApolloProvider } from "@apollo/client";
import { MuiPickersUtilsProvider } from "@material-ui/pickers";
import DateFnsUtils from "@date-io/date-fns";
import zhLocale from "date-fns/locale/zh-CN";
import { createRouterComponent } from "@curi/react-dom";
import { createRouter, announce } from "@curi/router";
import { browser } from "@hickory/browser";
import routes from "./routes";
ReactDOM.render(
<React.StrictMode>
<ApolloProvider client={client}>
<MuiPickersUtilsProvider utils={DateFnsUtils} locale={zhLocale}>
<App />
</MuiPickersUtilsProvider>
</ApolloProvider>
</React.StrictMode>,
document.getElementById("root")
);
const router = createRouter(browser, routes, {
sideEffects: [
announce(({ response }) => {
return `Navigated to ${response.location.pathname}`;
}),
],
external: { client }
});
const Router = createRouterComponent(router);
router.once(() => {
ReactDOM.render(
<React.StrictMode>
<ApolloProvider client={client}>
<MuiPickersUtilsProvider utils={DateFnsUtils} locale={zhLocale}>
<Router>
<App />
</Router>
</MuiPickersUtilsProvider>
</ApolloProvider>
</React.StrictMode>,
document.getElementById("root")
);
});
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))

View File

@ -20,10 +20,8 @@ import ChevronRightIcon from "@material-ui/icons/ChevronRight";
import ListItem from "@material-ui/core/ListItem";
import ListItemIcon from "@material-ui/core/ListItemIcon";
import ListItemText from "@material-ui/core/ListItemText";
import { Link, Route, BrowserRouter, Switch } from 'react-router-dom';
import { AddCircle, Description, LocalOffer } from '@material-ui/icons';
import { ArticleIndex } from '../articles';
import { ArticleEditor } from '../articles/article-editor';
import { Link } from '@curi/react-dom';
const drawerWidth = 240;
const useStyles = makeStyles((theme: Theme) =>
@ -105,7 +103,6 @@ export const DefaultLayout: FC = ({children}) => {
return (
<div className={classes.root}>
<BrowserRouter>
<CssBaseline />
<AppBar
position="fixed"
@ -154,7 +151,7 @@ export const DefaultLayout: FC = ({children}) => {
</div>
<Divider />
<List>
<Link to="/articles/create">
<Link name="create-article">
<ListItem button>
<ListItemIcon>
<AddCircle />
@ -162,7 +159,7 @@ export const DefaultLayout: FC = ({children}) => {
<ListItemText primary="New Article" />
</ListItem>
</Link>
<Link to="/articles">
<Link name="articles">
<ListItem button>
<ListItemIcon>
<Description />
@ -170,7 +167,7 @@ export const DefaultLayout: FC = ({children}) => {
<ListItemText primary="Articles" />
</ListItem>
</Link>
<Link to="/tags">
<Link name="tags">
<ListItem button>
<ListItemIcon>
<LocalOffer />
@ -183,17 +180,8 @@ export const DefaultLayout: FC = ({children}) => {
</Drawer>
<main className={classes.content}>
<div className={classes.toolbar} />
<Switch>
<Route path="/articles/create">
<ArticleEditor />
</Route>
<Route path="/articles">
<ArticleIndex />
</Route>
<Route path="/tags">Tags</Route>
</Switch>
{ children }
</main>
</BrowserRouter>
</div>
);
}

69
src/routes.tsx Normal file
View File

@ -0,0 +1,69 @@
import { ApolloClient } from "@apollo/client";
import { prepareRoutes } from "@curi/router";
import { omit } from 'ramda';
import { ARTICLE } from "./articles";
import { Article } from './generated/graphql';
export default prepareRoutes([
{
name: "dashboard",
path: "",
respond() {
return { body: () => <div>DashBoard</div> };
},
},
{
name: "create-article",
path: "articles/create",
resolve() {
const body = import(
/* webpackChunkName: "article-editor" */ "./articles"
).then((m) => m.ArticleEditor);
return body;
},
respond({ resolved }) {
return { body: resolved };
},
},
{
name: "modify-article",
path: "articles/:id",
async resolve(matched, { client }: { client: ApolloClient<any> }) {
const [ArticleEditor, result] = await Promise.all([
import(/* webpackChunkName: "article-editor" */ "./articles").then(
(m) => m.ArticleEditor
),
client.query<{article: Article}, { id: string }>({
query: ARTICLE,
variables: { id: matched!.params.id },
}),
]);
console.log(ArticleEditor, result);
return () => (
<ArticleEditor article={omit(["__typename"], result.data.article)} />
);
},
respond({ resolved }) {
return { body: resolved };
},
},
{
name: "articles",
path: "articles",
resolve() {
return import(/* webpackChunkName: "articles" */ "./articles").then(
(m) => m.ArticleIndex
);
},
respond({ resolved }) {
return { body: resolved };
},
},
{
name: "tags",
path: "tags",
respond() {
return { body: () => <div>Tags</div> };
},
},
]);