refactor: add checklist editor source (#1085)
* refactor: add checklist editor source * chore: merge develop
This commit is contained in:
14
.yarnrc.yml
14
.yarnrc.yml
@@ -5,3 +5,17 @@ plugins:
|
||||
spec: "@yarnpkg/plugin-workspace-tools"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.2.1.cjs
|
||||
|
||||
packageExtensions:
|
||||
"@types/react-redux@*":
|
||||
peerDependencies:
|
||||
"@types/react": "*"
|
||||
"@types/react-dom@*":
|
||||
peerDependencies:
|
||||
"@types/react": "*"
|
||||
"@types/react-beautiful-dnd@*":
|
||||
peerDependencies:
|
||||
"@types/react": "*"
|
||||
"@types/react-transition-group@*":
|
||||
peerDependencies:
|
||||
"@types/react": "*"
|
||||
9
packages/components/dist/Checksums.json
vendored
9
packages/components/dist/Checksums.json
vendored
@@ -1,7 +1,12 @@
|
||||
{
|
||||
"org.standardnotes.theme-autobiography": {
|
||||
"version": "1.0.4",
|
||||
"base64": "b1df118550bca4ef10b6f8eaeeeddb051cde8171212c5a73a577c834d331725f",
|
||||
"binary": "8cf9b21daea61b41bde70bfd6a7a4fcb1a8cf5539da52a7f7bcd48f2faa1c748"
|
||||
"base64": "64abd932647cc41a6780d7dc6ace34053c26eab79403b9f09c682221a72337f3",
|
||||
"binary": "12b90a338fb068615557dff1c11d5c08cebdf55868d448be20299fa0438a24f1"
|
||||
},
|
||||
"org.standardnotes.advanced-checklist": {
|
||||
"version": "0.0.1",
|
||||
"base64": "b7b9807b14554e933889ad18ba7e6891ed784b91c8cd14d58e575e0616631822",
|
||||
"binary": "bda0917402d5a671e4c53e9f66cfe643cfc773e3b93591eca1b1b08df059c064"
|
||||
}
|
||||
}
|
||||
13
packages/components/dist/org.standardnotes.advanced-checklist/build/asset-manifest.json
vendored
Normal file
13
packages/components/dist/org.standardnotes.advanced-checklist/build/asset-manifest.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"files": {
|
||||
"main.css": "./static/css/main.352e52d4.css",
|
||||
"main.js": "./static/js/main.c544f953.js",
|
||||
"index.html": "./index.html",
|
||||
"main.352e52d4.css.map": "./static/css/main.352e52d4.css.map",
|
||||
"main.c544f953.js.map": "./static/js/main.c544f953.js.map"
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/css/main.352e52d4.css",
|
||||
"static/js/main.c544f953.js"
|
||||
]
|
||||
}
|
||||
BIN
packages/components/dist/org.standardnotes.advanced-checklist/build/favicon.ico
vendored
Normal file
BIN
packages/components/dist/org.standardnotes.advanced-checklist/build/favicon.ico
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
1
packages/components/dist/org.standardnotes.advanced-checklist/build/index.html
vendored
Normal file
1
packages/components/dist/org.standardnotes.advanced-checklist/build/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="A great way to manage short-term and long-term to-do's. You can mark tasks as completed, change their order, and edit the text naturally in place."/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><title>Advanced Checklist</title><script defer="defer" src="./static/js/main.c544f953.js"></script><link href="./static/css/main.352e52d4.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div class="sn-component" id="root"></div></body></html>
|
||||
BIN
packages/components/dist/org.standardnotes.advanced-checklist/build/logo192.png
vendored
Normal file
BIN
packages/components/dist/org.standardnotes.advanced-checklist/build/logo192.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
BIN
packages/components/dist/org.standardnotes.advanced-checklist/build/logo512.png
vendored
Normal file
BIN
packages/components/dist/org.standardnotes.advanced-checklist/build/logo512.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
25
packages/components/dist/org.standardnotes.advanced-checklist/build/manifest.json
vendored
Normal file
25
packages/components/dist/org.standardnotes.advanced-checklist/build/manifest.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "Advanced Checklist",
|
||||
"name": "Advanced Checklist",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
21
packages/components/dist/org.standardnotes.advanced-checklist/build/package.json
vendored
Normal file
21
packages/components/dist/org.standardnotes.advanced-checklist/build/package.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@standardnotes/advanced-checklist",
|
||||
"version": "0.0.1",
|
||||
"description": "A task editor with grouping functionality.",
|
||||
"keywords": [
|
||||
"Standard Notes",
|
||||
"Standard Notes Extensions"
|
||||
],
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/standardnotes/advanced-checklist.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/standardnotes/advanced-checklist/issues"
|
||||
},
|
||||
"sn": {
|
||||
"main": "index.html"
|
||||
}
|
||||
}
|
||||
3
packages/components/dist/org.standardnotes.advanced-checklist/build/robots.txt
vendored
Normal file
3
packages/components/dist/org.standardnotes.advanced-checklist/build/robots.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
13
packages/components/dist/org.standardnotes.advanced-checklist/build/sample.ext.json
vendored
Normal file
13
packages/components/dist/org.standardnotes.advanced-checklist/build/sample.ext.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"identifier": "org.standardnotes.advanced-checklist-dev",
|
||||
"name": "Advanced Checklist - Dev",
|
||||
"content_type": "SN|Component",
|
||||
"area": "editor-editor",
|
||||
"version": "0.1.0",
|
||||
"description": "A task editor with grouping functionality.",
|
||||
"url": "http://localhost:3000/index.html",
|
||||
"download_url": "",
|
||||
"latest_url": "",
|
||||
"marketing_url": "https://github.com/standardnotes/advanced-checklist",
|
||||
"thumbnail_url": ""
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
object-assign
|
||||
(c) Sindre Sorhus
|
||||
@license MIT
|
||||
*/
|
||||
|
||||
/*! @license DOMPurify 2.3.8 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.3.8/LICENSE */
|
||||
|
||||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Lodash (Custom Build) lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE
|
||||
* Build: `lodash include="includes,merge,filter,map,remove,find,omit,pull,cloneDeep,pick,uniq,sortedIndexBy,mergeWith"`
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Lodash <https://lodash.com/>
|
||||
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
||||
* Released under MIT license <https://lodash.com/license>
|
||||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
||||
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||
*/
|
||||
|
||||
/** @license React v0.20.2
|
||||
* scheduler.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v16.13.1
|
||||
* react-is.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react-dom-server.browser.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react-dom.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react-is.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react-jsx-runtime.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v17.0.2
|
||||
* react.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
File diff suppressed because one or more lines are too long
144
packages/components/dist/org.standardnotes.advanced-checklist/package.json
vendored
Normal file
144
packages/components/dist/org.standardnotes.advanced-checklist/package.json
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
{
|
||||
"name": "@standardnotes/advanced-checklist",
|
||||
"version": "0.0.1",
|
||||
"description": "A task editor with grouping functionality.",
|
||||
"keywords": [
|
||||
"Standard Notes",
|
||||
"Standard Notes Extensions"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/standardnotes/advanced-checklist.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/standardnotes/advanced-checklist/issues"
|
||||
},
|
||||
"sn": {
|
||||
"main": "build/index.html"
|
||||
},
|
||||
"homepage": ".",
|
||||
"scripts": {
|
||||
"analyze": "source-map-explorer 'build/static/js/*.js'",
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"prepublishOnly": "npm run build",
|
||||
"clean-deploy-cache": "rm -rf node_modules/.cache/gh-pages",
|
||||
"predeploy": "yarn run pretty && yarn run build && yarn clean-deploy-cache",
|
||||
"deploy-build": "yarn run predeploy && gh-pages -b build -d build",
|
||||
"deploy-dev": "yarn run predeploy && gh-pages -b dev -d build",
|
||||
"deploy-stable": "yarn run predeploy && gh-pages -b gh-pages -d build",
|
||||
"test": "react-scripts test",
|
||||
"test:coverage": "npm run test -- --coverage --watchAll",
|
||||
"eject": "react-scripts eject",
|
||||
"serve": "serve -s -p 3000 build",
|
||||
"server-public": "http-server -p 3000 --cors",
|
||||
"server-root": "http-server ./ -p 3000 --cors",
|
||||
"server": "http-server ./build -p 3000 --cors",
|
||||
"pretty": "prettier --write 'src/**/*.{html,css,scss,js,jsx,ts,tsx,json}' README.md",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"lint-staged": {
|
||||
"README.md": [
|
||||
"prettier --write"
|
||||
],
|
||||
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
|
||||
"prettier --write"
|
||||
]
|
||||
},
|
||||
"jest": {
|
||||
"collectCoverageFrom": [
|
||||
"src/**/*.{js,jsx,ts,tsx}",
|
||||
"!<rootDir>/node_modules/"
|
||||
],
|
||||
"coveragePathIgnorePatterns": [
|
||||
"<rootDir>/src/mockData.ts",
|
||||
"<rootDir>/src/app/hooks.ts",
|
||||
"<rootDir>/src/app/store.ts",
|
||||
"<rootDir>/src/app/listenerMiddleware.ts"
|
||||
],
|
||||
"coverageReporters": [
|
||||
"text",
|
||||
"html"
|
||||
],
|
||||
"coverageThreshold": {
|
||||
"global": {
|
||||
"branches": 90,
|
||||
"functions": 100,
|
||||
"lines": 100,
|
||||
"statements": 100
|
||||
}
|
||||
},
|
||||
"transform": {
|
||||
"^.+\\.(ts|tsx)$": "ts-jest"
|
||||
},
|
||||
"transformIgnorePatterns": [
|
||||
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
|
||||
"^.+\\.module\\.(css|sass|scss)$"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@reach/alert-dialog": "0.16.2",
|
||||
"@reach/menu-button": "0.16.2",
|
||||
"@reach/visually-hidden": "0.16.0",
|
||||
"@reduxjs/toolkit": "1.8.0",
|
||||
"@standardnotes/editor-kit": "2.2.5",
|
||||
"@standardnotes/stylekit": "5.23.0",
|
||||
"@standardnotes/utils": "1.6.2",
|
||||
"@testing-library/dom": "8.11.3",
|
||||
"@testing-library/jest-dom": "5.16.2",
|
||||
"@testing-library/react": "12.1.4",
|
||||
"@testing-library/user-event": "13.5.0",
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/lodash": "4.14.179",
|
||||
"@types/node": "17.0.21",
|
||||
"@types/react": "17.0.40",
|
||||
"@types/react-beautiful-dnd": "13.1.2",
|
||||
"@types/react-dom": "17.0.13",
|
||||
"@types/react-redux": "7.1.23",
|
||||
"@types/react-transition-group": "4.4.4",
|
||||
"@types/redux-mock-store": "1.0.3",
|
||||
"@types/styled-components": "5.1.24",
|
||||
"@types/uuid": "8.3.4",
|
||||
"gh-pages": "3.2.3",
|
||||
"husky": "7.0.0",
|
||||
"lint-staged": "12.3.5",
|
||||
"node-sass": "*",
|
||||
"prettier": "2.5.1",
|
||||
"react": "17.0.2",
|
||||
"react-beautiful-dnd": "13.1.0",
|
||||
"react-dom": "17.0.2",
|
||||
"react-redux": "7.2.8",
|
||||
"react-scripts": "5.0.0",
|
||||
"react-transition-group": "4.4.2",
|
||||
"redux": "4.1.2",
|
||||
"redux-mock-store": "1.5.4",
|
||||
"source-map-explorer": "2.5.2",
|
||||
"styled-components": "5.3.5",
|
||||
"ts-jest": "27.1.4",
|
||||
"typescript": "4.6.2",
|
||||
"uuid": "8.3.2"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1 @@
|
||||
{
|
||||
"version": 3,
|
||||
"mappings": "AAAA,KAAM;EACJ,cAAc,CAAC,QAAQ;EACvB,cAAc,CAAC,QAAQ;EACvB,kBAAkB,CAAC,QAAQ;EAC3B,cAAc,CAAC,QAAQ;EACvB,iBAAiB,CAAC,QAAQ;EAC1B,oBAAoB,CAAC,QAAQ;EAE7B,wBAAwB,CAAC,QAAQ;EACjC,iCAAiC,CAAC,QAAQ;EAE1C,2BAA2B,CAAC,QAAQ;EACpC,oCAAoC,CAAC,QAAQ;EAE7C,2BAA2B,CAAC,QAAQ;EACpC,oCAAoC,CAAC,QAAQ;EAE7C,2BAA2B,CAAC,QAAQ;EACpC,oCAAoC,CAAC,QAAQ;EAE7C,0BAA0B,CAAC,QAAQ;EACnC,mCAAmC,CAAC,QAAQ;EAE5C,0BAA0B,CAAC,oBAAoB;EAE/C,8BAA8B,CAAC,oBAAoB;EACnD,8BAA8B,CAAC,wBAAwB;EACvD,0BAA0B,CAAC,oBAAoB;EAE/C,kCAAkC,CAAC,wBAAwB;EAE3D,uCAAuC,CAAC,oBAAoB;EAC5D,uCAAuC,CAAC,wBAAwB;EAChE,mCAAmC,CAAC,oBAAoB;EAExD,wCAAwC,CAAC,oBAAoB;EAC7D,wCAAwC,CAAC,wBAAwB;EACjE,oCAAoC,CAAC,oBAAoB;EAEzD,iDAAiD,CAAC,oBAAoB;EACtE,iDAAiD,CAAC,wBAAwB;EAC1E,6CAA6C,CAAC,oBAAoB;EAElE,qCAAqC,CAAC,oCAAoC;EAC1E,qCAAqC,CAAC,oCAAoC;EAE1E,0CAA0C,CAAC,oBAAoB;EAC/D,mCAAmC,CAAC,8BAA8B;EAElE,8BAA8B,CAAC,oBAAoB;EACnD,kCAAkC,CAAC,oBAAoB;EACvD,8BAA8B,CAAC,wBAAwB;EACvD,oCAAoC,CAAC,uBAAuB;EAE5D,6BAA6B,CAAC,QAAQ;EACtC,6BAA6B,CAAC,QAAQ;EACtC,6CAA6C,CAAC,UAAU;EACxD,6BAA6B,CAAC,QAAQ;;;AAGxC,mDAAoD;EAClD,gBAAgB,EAAE,OAAO;EACzB,KAAK,EAAE,4CAA4C",
|
||||
"sources": ["../src/main.scss"],
|
||||
"names": [],
|
||||
"file": "dist.css"
|
||||
}
|
||||
{"version":3,"sourceRoot":"","sources":["../src/main.scss"],"names":[],"mappings":"AAAA;EACE;EACA;EACA;EACA;EACA;EACA;EAEA;EACA;EAEA;EACA;EAEA;EACA;EAEA;EACA;EAEA;EACA;EAEA;EAEA;EACA;EACA;EAEA;EAEA;EACA;EACA;EAEA;EACA;EACA;EAEA;EACA;EACA;EAEA;EACA;EAEA;EACA;EAEA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;;;AAGF;EACE;EACA","file":"dist.css"}
|
||||
Binary file not shown.
@@ -2,25 +2,18 @@
|
||||
"name": "@standardnotes/autobiography-theme",
|
||||
"version": "1.0.4",
|
||||
"main": "dist/dist.css",
|
||||
"devDependencies": {
|
||||
"grunt": "^1.0.1",
|
||||
"grunt-contrib-sass": "^1.0.0",
|
||||
"grunt-contrib-watch": "^1.0.0",
|
||||
"grunt-newer": "^1.2.0"
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "grunt",
|
||||
"build": "yarn run grunt",
|
||||
"prepublishOnly": "yarn run build"
|
||||
},
|
||||
"sn": {
|
||||
"main": "dist/dist.css"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/standardnotes/autobiography-theme.git"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
"devDependencies": {
|
||||
"grunt": "^1.0.1",
|
||||
"grunt-contrib-sass": "^1.0.0",
|
||||
"grunt-contrib-watch": "^1.0.0",
|
||||
"grunt-newer": "^1.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,18 +9,18 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn workspaces foreach --parallel run build",
|
||||
"preversion": "yarn workspaces foreach --parallel run build",
|
||||
"preversion": "yarn build",
|
||||
"version": "node scripts/package-components.mjs"
|
||||
},
|
||||
"installConfig": {
|
||||
"hoistingLimits": "workspaces"
|
||||
},
|
||||
"dependencies": {
|
||||
"@standardnotes/autobiography-theme": "1.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@standardnotes/advanced-checklist": "0.0.1",
|
||||
"@standardnotes/autobiography-theme": "1.0.4",
|
||||
"@standardnotes/deterministic-zip": "^1.2.0",
|
||||
"@standardnotes/features": "^1.45.1",
|
||||
"node-sass": "7.0.1",
|
||||
"sass": "^1.52.3"
|
||||
}
|
||||
}
|
||||
|
||||
131
packages/components/src/org.standardnotes.advanced-checklist/.gitignore
vendored
Normal file
131
packages/components/src/org.standardnotes.advanced-checklist/.gitignore
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and *not* Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
#### Copied from Create React App ####
|
||||
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
/public/ext.json
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
yarn run lint-staged
|
||||
@@ -0,0 +1,4 @@
|
||||
.env
|
||||
coverage
|
||||
node_modules
|
||||
ext.json
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"semi": false,
|
||||
"trailingComma": "es5",
|
||||
"jsxSingleQuote": false
|
||||
}
|
||||
@@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
@@ -0,0 +1,80 @@
|
||||
# advanced-checklist
|
||||
|
||||
A great way to manage short-term and long-term to-do's. You can mark tasks as completed, change their order, and edit the text naturally in place.
|
||||
|
||||
## Development
|
||||
|
||||
**Prerequisites:** Install [Node.js](https://nodejs.org/en/), [Yarn](https://classic.yarnpkg.com/en/docs/install/), and [Git](https://github.com/git-guides/install-git) on your computer.
|
||||
|
||||
The general instructions setting up an environment to develop Standard Notes extensions can be found [here](https://docs.standardnotes.org/extensions/local-setup). You can also follow these instructions:
|
||||
|
||||
1. Fork the [repository](https://github.com/standardnotes/advanced-checklist) on GitHub.
|
||||
1. [Clone](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) your fork of the repository.
|
||||
1. Run `cd advanced-checklist` to enter the `advanced-checklist` directory.
|
||||
1. Run `yarn install` to install the dependencies on your machine as they are described in `yarn.lock`.
|
||||
|
||||
### Testing in the browser
|
||||
|
||||
1. To run the app in development mode, run `yarn start` and visit http://localhost:8001. Press `ctrl/cmd + C` to exit development mode.
|
||||
|
||||
### Testing in the Standard Notes app
|
||||
|
||||
1. Create an `ext.json` in the `public` directory. You have three options:
|
||||
1. Use `sample.ext.json`.
|
||||
1. Create `ext.json` as a copy of `sample.ext.json`.
|
||||
1. Follow the instructions [here](https://docs.standardnotes.org/extensions/local-setup) with `url: "http://localhost:3000/index.html"`.
|
||||
1. Install http-server using `sudo npm install -g http-server` then run `yarn server` to serve the `./build` directory at http://localhost:3000.
|
||||
1. To build the app, run `yarn build`.
|
||||
1. Install the editor into the [web](https://app.standardnotes.org) or [desktop](https://standardnotes.org/download) app with `http://localhost:3000/sample.ext.json` or with your custom `ext.json`. Press `ctrl/cmd + C` to shut down the server.
|
||||
|
||||
### Deployment
|
||||
|
||||
1. To make the source code prettier, run `yarn pretty`.
|
||||
1. To the deploy the build into the `gh-pages` branch of your repository on GitHub, run `yarn deploy-stable`.
|
||||
1. To deploy the build into to the `dev` branch for testing, run `yarn deploy-dev`.
|
||||
1. To deploy the built into the `build` branch for distributing, run `yarn deploy-build` for distributing builds.
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
### Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
#### `yarn start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:8001](http://localhost:8001) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
#### `yarn test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
#### `yarn build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
#### `yarn eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
### Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
@@ -0,0 +1,144 @@
|
||||
{
|
||||
"name": "@standardnotes/advanced-checklist",
|
||||
"version": "0.0.1",
|
||||
"description": "A task editor with grouping functionality.",
|
||||
"keywords": [
|
||||
"Standard Notes",
|
||||
"Standard Notes Extensions"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/standardnotes/advanced-checklist.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/standardnotes/advanced-checklist/issues"
|
||||
},
|
||||
"sn": {
|
||||
"main": "build/index.html"
|
||||
},
|
||||
"homepage": ".",
|
||||
"scripts": {
|
||||
"analyze": "source-map-explorer 'build/static/js/*.js'",
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"prepublishOnly": "npm run build",
|
||||
"clean-deploy-cache": "rm -rf node_modules/.cache/gh-pages",
|
||||
"predeploy": "yarn run pretty && yarn run build && yarn clean-deploy-cache",
|
||||
"deploy-build": "yarn run predeploy && gh-pages -b build -d build",
|
||||
"deploy-dev": "yarn run predeploy && gh-pages -b dev -d build",
|
||||
"deploy-stable": "yarn run predeploy && gh-pages -b gh-pages -d build",
|
||||
"test": "react-scripts test",
|
||||
"test:coverage": "npm run test -- --coverage --watchAll",
|
||||
"eject": "react-scripts eject",
|
||||
"serve": "serve -s -p 3000 build",
|
||||
"server-public": "http-server -p 3000 --cors",
|
||||
"server-root": "http-server ./ -p 3000 --cors",
|
||||
"server": "http-server ./build -p 3000 --cors",
|
||||
"pretty": "prettier --write 'src/**/*.{html,css,scss,js,jsx,ts,tsx,json}' README.md",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"lint-staged": {
|
||||
"README.md": [
|
||||
"prettier --write"
|
||||
],
|
||||
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
|
||||
"prettier --write"
|
||||
]
|
||||
},
|
||||
"jest": {
|
||||
"collectCoverageFrom": [
|
||||
"src/**/*.{js,jsx,ts,tsx}",
|
||||
"!<rootDir>/node_modules/"
|
||||
],
|
||||
"coveragePathIgnorePatterns": [
|
||||
"<rootDir>/src/mockData.ts",
|
||||
"<rootDir>/src/app/hooks.ts",
|
||||
"<rootDir>/src/app/store.ts",
|
||||
"<rootDir>/src/app/listenerMiddleware.ts"
|
||||
],
|
||||
"coverageReporters": [
|
||||
"text",
|
||||
"html"
|
||||
],
|
||||
"coverageThreshold": {
|
||||
"global": {
|
||||
"branches": 90,
|
||||
"functions": 100,
|
||||
"lines": 100,
|
||||
"statements": 100
|
||||
}
|
||||
},
|
||||
"transform": {
|
||||
"^.+\\.(ts|tsx)$": "ts-jest"
|
||||
},
|
||||
"transformIgnorePatterns": [
|
||||
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
|
||||
"^.+\\.module\\.(css|sass|scss)$"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@reach/alert-dialog": "0.16.2",
|
||||
"@reach/menu-button": "0.16.2",
|
||||
"@reach/visually-hidden": "0.16.0",
|
||||
"@reduxjs/toolkit": "1.8.0",
|
||||
"@standardnotes/editor-kit": "2.2.5",
|
||||
"@standardnotes/stylekit": "5.23.0",
|
||||
"@standardnotes/utils": "1.6.2",
|
||||
"@testing-library/dom": "8.11.3",
|
||||
"@testing-library/jest-dom": "5.16.2",
|
||||
"@testing-library/react": "12.1.4",
|
||||
"@testing-library/user-event": "13.5.0",
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/lodash": "4.14.179",
|
||||
"@types/node": "17.0.21",
|
||||
"@types/react": "17.0.40",
|
||||
"@types/react-beautiful-dnd": "13.1.2",
|
||||
"@types/react-dom": "17.0.13",
|
||||
"@types/react-redux": "7.1.23",
|
||||
"@types/react-transition-group": "4.4.4",
|
||||
"@types/redux-mock-store": "1.0.3",
|
||||
"@types/styled-components": "5.1.24",
|
||||
"@types/uuid": "8.3.4",
|
||||
"gh-pages": "3.2.3",
|
||||
"husky": "7.0.0",
|
||||
"lint-staged": "12.3.5",
|
||||
"node-sass": "*",
|
||||
"prettier": "2.5.1",
|
||||
"react": "17.0.2",
|
||||
"react-beautiful-dnd": "13.1.0",
|
||||
"react-dom": "17.0.2",
|
||||
"react-redux": "7.2.8",
|
||||
"react-scripts": "5.0.0",
|
||||
"react-transition-group": "4.4.2",
|
||||
"redux": "4.1.2",
|
||||
"redux-mock-store": "1.5.4",
|
||||
"source-map-explorer": "2.5.2",
|
||||
"styled-components": "5.3.5",
|
||||
"ts-jest": "27.1.4",
|
||||
"typescript": "4.6.2",
|
||||
"uuid": "8.3.2"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
@@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta name="description"
|
||||
content="A great way to manage short-term and long-term to-do's. You can mark tasks as completed, change their order, and edit the text naturally in place." />
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>Advanced Checklist</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div class="sn-component" id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "Advanced Checklist",
|
||||
"name": "Advanced Checklist",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@standardnotes/advanced-checklist",
|
||||
"version": "0.0.1",
|
||||
"description": "A task editor with grouping functionality.",
|
||||
"keywords": [
|
||||
"Standard Notes",
|
||||
"Standard Notes Extensions"
|
||||
],
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/standardnotes/advanced-checklist.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/standardnotes/advanced-checklist/issues"
|
||||
},
|
||||
"sn": {
|
||||
"main": "index.html"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"identifier": "org.standardnotes.advanced-checklist-dev",
|
||||
"name": "Advanced Checklist - Dev",
|
||||
"content_type": "SN|Component",
|
||||
"area": "editor-editor",
|
||||
"version": "0.1.0",
|
||||
"description": "A task editor with grouping functionality.",
|
||||
"url": "http://localhost:3000/index.html",
|
||||
"download_url": "",
|
||||
"latest_url": "",
|
||||
"marketing_url": "https://github.com/standardnotes/advanced-checklist",
|
||||
"thumbnail_url": ""
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
|
||||
import type { RootState, AppDispatch } from './store'
|
||||
|
||||
export const useAppDispatch = () => useDispatch<AppDispatch>()
|
||||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
|
||||
|
||||
export const useDidMount = (
|
||||
effect: React.EffectCallback,
|
||||
deps?: React.DependencyList
|
||||
) => {
|
||||
const [didMount, setDidMount] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (didMount) {
|
||||
effect()
|
||||
} else {
|
||||
setDidMount(true)
|
||||
}
|
||||
}, [deps, didMount, effect])
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { createListenerMiddleware, isAnyOf } from '@reduxjs/toolkit'
|
||||
import {
|
||||
deleteAllCompleted,
|
||||
openAllCompleted,
|
||||
taskAdded,
|
||||
taskDeleted,
|
||||
taskModified,
|
||||
tasksGroupAdded,
|
||||
tasksGroupCollapsed,
|
||||
tasksGroupDeleted,
|
||||
tasksGroupLastActive,
|
||||
tasksGroupMerged,
|
||||
tasksReordered,
|
||||
taskToggled,
|
||||
} from '../features/tasks/tasks-slice'
|
||||
|
||||
const listenerMiddleware = createListenerMiddleware()
|
||||
|
||||
/**
|
||||
* A list of actions that we want to listen to.
|
||||
* The groupName is obtained from the payload, and we use it to
|
||||
* dispatch the tasksGroupLastActive action.
|
||||
*/
|
||||
const actionsWithGroup = isAnyOf(
|
||||
taskAdded,
|
||||
taskModified,
|
||||
taskToggled,
|
||||
taskDeleted,
|
||||
openAllCompleted,
|
||||
deleteAllCompleted,
|
||||
tasksReordered,
|
||||
tasksGroupAdded,
|
||||
tasksGroupDeleted,
|
||||
tasksGroupMerged,
|
||||
tasksGroupCollapsed
|
||||
)
|
||||
|
||||
listenerMiddleware.startListening({
|
||||
matcher: actionsWithGroup,
|
||||
effect: ({ payload }, listenerApi) => {
|
||||
const { groupName } = payload
|
||||
listenerApi.dispatch(tasksGroupLastActive({ groupName }))
|
||||
},
|
||||
})
|
||||
|
||||
export default listenerMiddleware.middleware
|
||||
@@ -0,0 +1,17 @@
|
||||
import { configureStore } from '@reduxjs/toolkit'
|
||||
|
||||
import tasksReducer from '../features/tasks/tasks-slice'
|
||||
import settingsReducer from '../features/settings/settings-slice'
|
||||
import listenerMiddleware from './listenerMiddleware'
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
tasks: tasksReducer,
|
||||
settings: settingsReducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware().prepend(listenerMiddleware),
|
||||
})
|
||||
|
||||
export type AppDispatch = typeof store.dispatch
|
||||
export type RootState = ReturnType<typeof store.getState>
|
||||
@@ -0,0 +1,45 @@
|
||||
import React, { ChangeEvent, forwardRef } from 'react'
|
||||
|
||||
type CheckBoxInputProps = {
|
||||
checked?: boolean
|
||||
disabled?: boolean
|
||||
testId?: string
|
||||
onChange?: (event: ChangeEvent<HTMLInputElement>) => void
|
||||
}
|
||||
|
||||
export const CheckBoxInput = forwardRef<HTMLInputElement, CheckBoxInputProps>(
|
||||
({ checked, disabled, testId, onChange }, ref) => {
|
||||
function onCheckBoxButtonClick({
|
||||
currentTarget,
|
||||
}: React.MouseEvent<SVGElement>) {
|
||||
!checked
|
||||
? currentTarget.classList.add('explode')
|
||||
: currentTarget.classList.remove('explode')
|
||||
}
|
||||
|
||||
return (
|
||||
<label className="checkbox-container">
|
||||
<input
|
||||
className="checkbox-state"
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
data-testid={testId}
|
||||
disabled={disabled}
|
||||
onChange={onChange}
|
||||
ref={ref}
|
||||
/>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlnsXlink="http://www.w3.org/1999/xlink"
|
||||
viewBox="3 2 22 20"
|
||||
className="checkbox-button"
|
||||
onClick={onCheckBoxButtonClick}
|
||||
>
|
||||
<use xlinkHref="#checkbox-square" className="checkbox-square"></use>
|
||||
<use xlinkHref="#checkbox-mark" className="checkbox-mark"></use>
|
||||
<use xlinkHref="#checkbox-circle" className="checkbox-circle"></use>
|
||||
</svg>
|
||||
</label>
|
||||
)
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,61 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
const ProgressBarBackground = styled.circle`
|
||||
fill: none;
|
||||
stroke: var(--sn-stylekit-neutral-color);
|
||||
`
|
||||
|
||||
const ProgressBarStroke = styled.circle`
|
||||
fill: none;
|
||||
stroke: var(--sn-stylekit-info-color);
|
||||
transition: all 0.5s;
|
||||
`
|
||||
|
||||
type CircularProgressBarProps = {
|
||||
size: number
|
||||
percentage: number
|
||||
}
|
||||
|
||||
export const CircularProgressBar: React.FC<CircularProgressBarProps> = ({
|
||||
size,
|
||||
percentage,
|
||||
}) => {
|
||||
const [progress, setProgress] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
setProgress(percentage)
|
||||
}, [percentage])
|
||||
|
||||
const viewBox = `0 0 ${size} ${size}`
|
||||
const strokeWidth = size * (0.1 / 100) * 100 + 1
|
||||
const radius = (size - strokeWidth) / 2
|
||||
const circumference = radius * Math.PI * 2
|
||||
const dash = (progress * circumference) / 100
|
||||
|
||||
return (
|
||||
<svg
|
||||
height={size}
|
||||
viewBox={viewBox}
|
||||
width={size}
|
||||
data-testid="circular-progress-bar"
|
||||
>
|
||||
<ProgressBarBackground
|
||||
cx={size / 2}
|
||||
cy={size / 2}
|
||||
r={radius}
|
||||
strokeWidth={strokeWidth}
|
||||
/>
|
||||
<ProgressBarStroke
|
||||
cx={size / 2}
|
||||
cy={size / 2}
|
||||
r={radius}
|
||||
strokeWidth={strokeWidth}
|
||||
transform={`rotate(-90 ${size / 2} ${size / 2})`}
|
||||
strokeDasharray={`${dash} ${circumference - dash}`}
|
||||
strokeLinecap="round"
|
||||
style={{ transition: 'all 0.5s' }}
|
||||
/>
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import '@reach/dialog/styles.css'
|
||||
|
||||
import React, { useRef } from 'react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogLabel,
|
||||
AlertDialogDescription,
|
||||
} from '@reach/alert-dialog'
|
||||
|
||||
import { sanitizeHtmlString } from '@standardnotes/utils'
|
||||
|
||||
type ConfirmDialogProps = {
|
||||
testId?: string
|
||||
title?: string
|
||||
confirmButtonText?: string
|
||||
confirmButtonStyle?: 'danger' | 'info'
|
||||
confirmButtonCb: () => void
|
||||
cancelButtonText?: string
|
||||
cancelButtonCb: () => void
|
||||
}
|
||||
|
||||
export const ConfirmDialog: React.FC<ConfirmDialogProps> = ({
|
||||
testId,
|
||||
title = '',
|
||||
confirmButtonText = 'Confirm',
|
||||
confirmButtonStyle = 'info',
|
||||
confirmButtonCb,
|
||||
cancelButtonText = 'Cancel',
|
||||
cancelButtonCb,
|
||||
children,
|
||||
}) => {
|
||||
const cancelRef = useRef<HTMLButtonElement>(null)
|
||||
|
||||
return (
|
||||
<AlertDialog
|
||||
data-testid={testId}
|
||||
onDismiss={cancelButtonCb}
|
||||
leastDestructiveRef={cancelRef}
|
||||
>
|
||||
<div className="sk-modal-content">
|
||||
<div className="sn-component">
|
||||
<div className="sk-panel">
|
||||
<div className="sk-panel-content">
|
||||
<div className="sk-panel-section">
|
||||
<AlertDialogLabel
|
||||
className="sk-h3 sk-panel-section-title"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: sanitizeHtmlString(title),
|
||||
}}
|
||||
/>
|
||||
|
||||
<AlertDialogDescription className="sk-panel-row">
|
||||
<p className="color-foreground">{children}</p>
|
||||
</AlertDialogDescription>
|
||||
|
||||
<div className="flex my-1 mt-4">
|
||||
<button
|
||||
data-testid="cancel-dialog-button"
|
||||
className="sn-button small neutral"
|
||||
onClick={cancelButtonCb}
|
||||
ref={cancelRef}
|
||||
>
|
||||
{cancelButtonText}
|
||||
</button>
|
||||
<button
|
||||
data-testid="confirm-dialog-button"
|
||||
className={`sn-button small ml-2 ${confirmButtonStyle}`}
|
||||
onClick={confirmButtonCb}
|
||||
>
|
||||
{confirmButtonText}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AlertDialog>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import styled from 'styled-components'
|
||||
|
||||
export const GenericInlineText = styled.span`
|
||||
color: var(--sn-stylekit-paragraph-text-color);
|
||||
font-size: var(--sn-stylekit-font-size-p);
|
||||
margin: 0 10px;
|
||||
`
|
||||
@@ -0,0 +1,30 @@
|
||||
import styled from 'styled-components'
|
||||
|
||||
type Header1Props = {
|
||||
crossed: boolean
|
||||
}
|
||||
|
||||
const Header1 = styled.h1<Header1Props>`
|
||||
color: var(--sn-stylekit-editor-foreground-color);
|
||||
display: inline;
|
||||
font-size: 1.125rem !important;
|
||||
margin-right: 10px !important;
|
||||
text-decoration: ${({ crossed }) => (crossed ? 'line-through' : 'none')};
|
||||
`
|
||||
|
||||
type MainTitleProps = {
|
||||
highlight?: boolean
|
||||
crossed?: boolean
|
||||
}
|
||||
|
||||
export const MainTitle: React.FC<MainTitleProps> = ({
|
||||
children,
|
||||
highlight = false,
|
||||
crossed = false,
|
||||
}) => {
|
||||
return (
|
||||
<Header1 className={`sk-h1 ${highlight ? 'info' : ''}`} crossed={crossed}>
|
||||
{children}
|
||||
</Header1>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
type RoundButtonProps = {
|
||||
testId?: string
|
||||
onClick: () => void
|
||||
}
|
||||
|
||||
export const RoundButton: React.FC<RoundButtonProps> = ({
|
||||
testId,
|
||||
onClick,
|
||||
children,
|
||||
}) => {
|
||||
return (
|
||||
<button data-testid={testId} className="sn-icon-button" onClick={onClick}>
|
||||
{children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import styled from 'styled-components'
|
||||
|
||||
export const SubTitle = styled.h3`
|
||||
color: var(--sn-stylekit-foreground-color);
|
||||
font-size: var(--sn-stylekit-font-size-h3);
|
||||
font-weight: 500;
|
||||
margin: 10px 0px;
|
||||
opacity: 0.55;
|
||||
|
||||
&::first-letter {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
`
|
||||
@@ -0,0 +1,62 @@
|
||||
import { ChangeEvent, forwardRef, KeyboardEvent } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
const StyledTextArea = styled.textarea`
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
color: inherit;
|
||||
font-size: var(--sn-stylekit-font-size-h3);
|
||||
font-weight: 400;
|
||||
margin-left: 6px;
|
||||
outline: none;
|
||||
overflow: hidden;
|
||||
resize: none;
|
||||
width: 100%;
|
||||
`
|
||||
|
||||
type TextAreaInputProps = {
|
||||
value: string
|
||||
className?: string
|
||||
dir?: 'ltr' | 'rtl' | 'auto'
|
||||
disabled?: boolean
|
||||
spellCheck?: boolean
|
||||
testId?: string
|
||||
onChange?: (event: ChangeEvent<HTMLTextAreaElement>) => void
|
||||
onKeyPress?: (event: KeyboardEvent<HTMLTextAreaElement>) => void
|
||||
onKeyUp?: (event: KeyboardEvent<HTMLTextAreaElement>) => void
|
||||
}
|
||||
|
||||
export const TextAreaInput = forwardRef<
|
||||
HTMLTextAreaElement,
|
||||
TextAreaInputProps
|
||||
>(
|
||||
(
|
||||
{
|
||||
value,
|
||||
className,
|
||||
dir = 'auto',
|
||||
disabled,
|
||||
spellCheck,
|
||||
testId,
|
||||
onChange,
|
||||
onKeyPress,
|
||||
onKeyUp,
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
return (
|
||||
<StyledTextArea
|
||||
className={className}
|
||||
data-testid={testId}
|
||||
dir={dir}
|
||||
disabled={disabled}
|
||||
onChange={onChange}
|
||||
onKeyPress={onKeyPress}
|
||||
onKeyUp={onKeyUp}
|
||||
ref={ref}
|
||||
spellCheck={spellCheck}
|
||||
value={value}
|
||||
/>
|
||||
)
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,21 @@
|
||||
$transition-duration: 750ms;
|
||||
|
||||
@keyframes strike {
|
||||
from {
|
||||
text-decoration: line-through 1px solid transparent;
|
||||
}
|
||||
to {
|
||||
text-decoration: line-through 1px solid var(--sn-stylekit-info-color);
|
||||
}
|
||||
}
|
||||
|
||||
.cross-out {
|
||||
animation-duration: $transition-duration;
|
||||
animation-fill-mode: forwards;
|
||||
animation-name: strike;
|
||||
animation-timing-function: linear;
|
||||
}
|
||||
|
||||
.no-text-decoration {
|
||||
text-decoration: none !important;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import './TextInput.scss'
|
||||
|
||||
import { ChangeEvent, FocusEvent, forwardRef, KeyboardEvent } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
type StyledInputProps = {
|
||||
textSize: 'normal' | 'big'
|
||||
}
|
||||
|
||||
const StyledInput = styled.input<StyledInputProps>`
|
||||
background-color: unset;
|
||||
border: none;
|
||||
color: var(--sn-stylekit-foreground-color);
|
||||
font-size: ${({ textSize }) =>
|
||||
textSize === 'big' ? '1.125rem' : 'var(--sn-stylekit-font-size-h3)'};
|
||||
font-weight: ${({ textSize }) => (textSize === 'big' ? '500' : '400')};
|
||||
height: auto;
|
||||
margin: 6px 0 6px 0;
|
||||
outline: none;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
|
||||
/* Remove default shadow for iOS mobile */
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
appearance: none;
|
||||
|
||||
::placeholder {
|
||||
color: var(--sn-stylekit-input-placeholder-color);
|
||||
}
|
||||
`
|
||||
|
||||
type TextInputProps = {
|
||||
value: string
|
||||
autoFocus?: boolean
|
||||
dir?: 'ltr' | 'rtl' | 'auto'
|
||||
disabled?: boolean
|
||||
enterKeyHint?:
|
||||
| 'enter'
|
||||
| 'done'
|
||||
| 'go'
|
||||
| 'next'
|
||||
| 'previous'
|
||||
| 'search'
|
||||
| 'send'
|
||||
placeholder?: string
|
||||
spellCheck?: boolean
|
||||
testId?: string
|
||||
textSize?: 'normal' | 'big'
|
||||
onBlur?: (event: FocusEvent<HTMLInputElement>) => void
|
||||
onChange?: (event: ChangeEvent<HTMLInputElement>) => void
|
||||
onKeyPress?: (event: KeyboardEvent<HTMLInputElement>) => void
|
||||
}
|
||||
|
||||
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
|
||||
(
|
||||
{
|
||||
value,
|
||||
autoFocus,
|
||||
dir = 'auto',
|
||||
disabled,
|
||||
enterKeyHint,
|
||||
placeholder,
|
||||
spellCheck,
|
||||
testId,
|
||||
textSize = 'normal',
|
||||
onBlur,
|
||||
onChange,
|
||||
onKeyPress,
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
return (
|
||||
<StyledInput
|
||||
type="text"
|
||||
autoFocus={autoFocus}
|
||||
data-testid={testId}
|
||||
dir={dir}
|
||||
disabled={disabled}
|
||||
enterKeyHint={enterKeyHint}
|
||||
onBlur={onBlur}
|
||||
onChange={onChange}
|
||||
onKeyPress={onKeyPress}
|
||||
placeholder={placeholder}
|
||||
ref={ref}
|
||||
spellCheck={spellCheck}
|
||||
textSize={textSize}
|
||||
value={value}
|
||||
/>
|
||||
)
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
import styled from 'styled-components'
|
||||
|
||||
export const WideButton = styled.button`
|
||||
align-items: center;
|
||||
background-color: var(--sn-stylekit-background-color);
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--sn-stylekit-border-color);
|
||||
box-sizing: border-box;
|
||||
color: var(--sn-stylekit-paragraph-text-color);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
height: 36px;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
`
|
||||
@@ -0,0 +1,14 @@
|
||||
export const AddIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
className="sn-icon sm block"
|
||||
fill="none"
|
||||
height="14"
|
||||
viewBox="0 0 14 14"
|
||||
width="14"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path d="M14 7C14 7.55228 13.5523 8 13 8H8V13C8 13.5523 7.55228 14 7 14C6.44772 14 6 13.5523 6 13V8H1C0.447715 8 0 7.55228 0 7C0 6.44772 0.447715 6 1 6H6V1C6 0.447715 6.44772 0 7 0C7.55228 0 8 0.447715 8 1V6H13C13.5523 6 14 6.44772 14 7Z" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export const ChevronDownIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="sn-icon block"
|
||||
>
|
||||
<path d="M6.17622 7.15015L10.0012 10.9751L13.8262 7.15015L15.0012 8.33348L10.0012 13.3335L5.00122 8.33348L6.17622 7.15015Z" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export const ChevronUpIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="sn-icon block"
|
||||
>
|
||||
<path d="M13.826 13.3335L10.001 9.5085L6.17597 13.3335L5.00097 12.1502L10.001 7.15017L15.001 12.1502L13.826 13.3335Z" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
export const DottedCircleIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
className="sn-icon no-fill stroke-neutral-color block"
|
||||
fill="none"
|
||||
viewBox="0 0 20 20"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<rect
|
||||
x="0.5"
|
||||
y="0.5"
|
||||
width="19"
|
||||
height="19"
|
||||
rx="9.5"
|
||||
strokeDasharray="2 2"
|
||||
/>
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export const MergeIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="sn-icon block"
|
||||
>
|
||||
<path d="M8 17L12 13H15.2C15.6 14.2 16.7 15 18 15C19.7 15 21 13.7 21 12C21 10.3 19.7 9 18 9C16.7 9 15.6 9.8 15.2 11H12L8 7V3H3V8H6L10.2 12L6 16H3V21H8V17Z" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import styled from 'styled-components'
|
||||
|
||||
const Ellipsis = ({ ...props }) => (
|
||||
<span aria-hidden {...props}>
|
||||
…
|
||||
</span>
|
||||
)
|
||||
|
||||
/**
|
||||
* SVG icons don't work well with the MenuButton components.
|
||||
* So we create a text-based replacement for it.
|
||||
*/
|
||||
export const MoreIcon = styled(Ellipsis)`
|
||||
font-weight: 800;
|
||||
height: 18px;
|
||||
line-height: 10px;
|
||||
`
|
||||
@@ -0,0 +1,12 @@
|
||||
export const RenameIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="sn-icon block"
|
||||
>
|
||||
<path d="M11.7167 7.5L12.5 8.28333L4.93333 15.8333H4.16667V15.0667L11.7167 7.5ZM14.7167 2.5C14.5083 2.5 14.2917 2.58333 14.1333 2.74167L12.6083 4.26667L15.7333 7.39167L17.2583 5.86667C17.5833 5.54167 17.5833 5 17.2583 4.69167L15.3083 2.74167C15.1417 2.575 14.9333 2.5 14.7167 2.5ZM11.7167 5.15833L2.5 14.375V17.5H5.625L14.8417 8.28333L11.7167 5.15833Z" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
type ReorderIconProps = {
|
||||
highlight?: boolean
|
||||
}
|
||||
|
||||
export const ReorderIcon: React.FC<ReorderIconProps> = ({
|
||||
highlight = false,
|
||||
}) => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className={`sn-icon block ${highlight ? 'info' : ''}`}
|
||||
data-testid="reorder-icon"
|
||||
>
|
||||
<path d="M3 15H21V13H3V15ZM3 19H21V17H3V19ZM3 11H21V9H3V11ZM3 5V7H21V5H3Z" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export const TrashIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="sn-icon block"
|
||||
>
|
||||
<path d="M7.49992 2.5V3.33333H3.33325V5H4.16659V15.8333C4.16659 16.2754 4.34218 16.6993 4.65474 17.0118C4.9673 17.3244 5.39122 17.5 5.83325 17.5H14.1666C14.6086 17.5 15.0325 17.3244 15.3451 17.0118C15.6577 16.6993 15.8333 16.2754 15.8333 15.8333V5H16.6666V3.33333H12.4999V2.5H7.49992ZM5.83325 5H14.1666V15.8333H5.83325V5ZM7.49992 6.66667V14.1667H9.16658V6.66667H7.49992ZM10.8333 6.66667V14.1667H12.4999V6.66667H10.8333Z" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export { ChevronDownIcon } from './ChevronDownIcon'
|
||||
export { ChevronUpIcon } from './ChevronUpIcon'
|
||||
export { MergeIcon } from './MergeIcon'
|
||||
export { MoreIcon } from './MoreIcon'
|
||||
export { ReorderIcon } from './ReorderIcon'
|
||||
export { TrashIcon } from './TrashIcon'
|
||||
export { RenameIcon } from './RenameIcon'
|
||||
export { AddIcon } from './AddIcon'
|
||||
export { DottedCircleIcon } from './DottedCircleIcon'
|
||||
@@ -0,0 +1,10 @@
|
||||
export * from './TextInput'
|
||||
export * from './CheckBoxInput'
|
||||
export * from './CircularProgressBar'
|
||||
export * from './GenericInlineText'
|
||||
export * from './MainTitle'
|
||||
export * from './RoundButton'
|
||||
export * from './SubTitle'
|
||||
export * from './TextAreaInput'
|
||||
export * from './WideButton'
|
||||
export * from './ConfirmDialog'
|
||||
@@ -0,0 +1,109 @@
|
||||
$transition-duration: 750ms;
|
||||
|
||||
.checkbox-container {
|
||||
display: block;
|
||||
padding-left: 20px;
|
||||
position: relative;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.checkbox-state {
|
||||
height: 0;
|
||||
left: 0;
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.checkbox-button {
|
||||
bottom: 0;
|
||||
cursor: pointer;
|
||||
fill: none;
|
||||
height: 22px;
|
||||
left: 0;
|
||||
margin: auto;
|
||||
position: absolute;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
stroke-width: 2;
|
||||
stroke: var(--sn-stylekit-neutral-color);
|
||||
top: 0;
|
||||
width: 22px;
|
||||
}
|
||||
|
||||
.checkbox-square,
|
||||
.checkbox-mark {
|
||||
cursor: pointer;
|
||||
transition: stroke-dashoffset $transition-duration
|
||||
cubic-bezier(0.9, 0, 0.5, 1);
|
||||
}
|
||||
|
||||
.checkbox-circle {
|
||||
animation-delay: 1s;
|
||||
animation: none $transition-duration linear;
|
||||
stroke-dasharray: 1 6;
|
||||
stroke-width: 0;
|
||||
stroke: var(--sn-stylekit-neutral-color);
|
||||
transform-origin: 13.5px 12.5px;
|
||||
transform: scale(0.4) rotate(0deg);
|
||||
}
|
||||
|
||||
.checkbox-square {
|
||||
stroke-dasharray: 56.1053, 56.1053;
|
||||
stroke-dashoffset: 0;
|
||||
stroke: var(--sn-stylekit-neutral-color);
|
||||
transition-delay: $transition-duration * 0.2;
|
||||
}
|
||||
|
||||
.checkbox-mark {
|
||||
stroke-dasharray: 9.8995, 9.8995;
|
||||
stroke-dashoffset: 9.8995;
|
||||
stroke: var(--sn-stylekit-neutral-color);
|
||||
transition-duration: $transition-duration * 0.4;
|
||||
}
|
||||
|
||||
.checkbox-circle {
|
||||
animation-delay: $transition-duration * 0.7;
|
||||
animation-duration: $transition-duration * 0.7;
|
||||
}
|
||||
|
||||
.checkbox-state:checked {
|
||||
~ .checkbox-button .checkbox-square {
|
||||
stroke-dashoffset: 56.1053;
|
||||
stroke: var(--sn-stylekit-info-color);
|
||||
transition-delay: 0s;
|
||||
}
|
||||
|
||||
~ .checkbox-button .checkbox-mark {
|
||||
stroke-dashoffset: 0;
|
||||
stroke: var(--sn-stylekit-info-color);
|
||||
transition-delay: $transition-duration * 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes explode {
|
||||
30% {
|
||||
stroke: var(--sn-stylekit-info-color);
|
||||
stroke-opacity: 1;
|
||||
stroke-width: 3;
|
||||
transform: scale(0.8) rotate(40deg);
|
||||
}
|
||||
100% {
|
||||
stroke: var(--sn-stylekit-neutral-color);
|
||||
stroke-opacity: 0;
|
||||
stroke-width: 0;
|
||||
transform: scale(1.1) rotate(60deg);
|
||||
}
|
||||
}
|
||||
|
||||
.explode {
|
||||
.checkbox-circle {
|
||||
animation: explode ease $transition-duration;
|
||||
animation-delay: $transition-duration;
|
||||
animation-fill-mode: forwards;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import './CheckBoxElementsDefs.scss'
|
||||
|
||||
export const CheckBoxElementsDefs = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 0 0"
|
||||
style={{ position: 'absolute', zIndex: -1, opacity: 0 }}
|
||||
>
|
||||
<defs>
|
||||
<path
|
||||
id="checkbox-square"
|
||||
d="M21 12.7v5c0 1.3-1 2.3-2.3 2.3H8.3C7 20 6 19 6 17.7V7.3C6 6 7 5 8.3 5h10.4C20 5 21 6 21 7.3v5.4"
|
||||
></path>
|
||||
<path id="checkbox-mark" d="M10 13l2 2 5-5"></path>
|
||||
<circle id="checkbox-circle" cx="13.5" cy="12.5" r="10"></circle>
|
||||
</defs>
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './CheckBoxElementsDefs'
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
export { ArrowVector } from './ArrowVector'
|
||||
@@ -0,0 +1,280 @@
|
||||
import { GroupPayload, TaskPayload } from '../features/tasks/tasks-slice'
|
||||
import {
|
||||
arrayMoveMutable,
|
||||
arrayMoveImmutable,
|
||||
getPercentage,
|
||||
groupTasksByCompletedStatus,
|
||||
truncateText,
|
||||
getPlainPreview,
|
||||
getTaskArrayFromGroupedTasks,
|
||||
parseMarkdownTasks,
|
||||
} from './utils'
|
||||
|
||||
describe('arrayMoveMutable', () => {
|
||||
it('should not mutate array if there are no elements', () => {
|
||||
const theArray: any[] = []
|
||||
arrayMoveMutable(theArray, 0, 1)
|
||||
|
||||
expect(theArray).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('passing a negative number to fromIndex should use 0 instead', () => {
|
||||
const theArray = ['test', 'another test']
|
||||
arrayMoveMutable(theArray, -1, 1)
|
||||
|
||||
expect(theArray).toHaveLength(2)
|
||||
expect(theArray[0]).toBe('test')
|
||||
expect(theArray[1]).toBe('another test')
|
||||
})
|
||||
|
||||
test('passing a negative number to toIndex should use 0 instead', () => {
|
||||
const theArray = ['test', 'another test']
|
||||
arrayMoveMutable(theArray, 1, -1)
|
||||
|
||||
expect(theArray).toHaveLength(2)
|
||||
expect(theArray[0]).toBe('test')
|
||||
expect(theArray[1]).toBe('another test')
|
||||
})
|
||||
})
|
||||
|
||||
describe('arrayMoveImmutable', () => {
|
||||
it('should move the element to the desired position', () => {
|
||||
const theArray = ['test', 'testing']
|
||||
const newArray = arrayMoveImmutable(theArray, 0, 1)
|
||||
|
||||
expect(theArray).toHaveLength(2)
|
||||
expect(theArray[0]).toBe('test')
|
||||
expect(theArray[1]).toBe('testing')
|
||||
|
||||
expect(newArray).toHaveLength(2)
|
||||
expect(newArray[0]).toBe('testing')
|
||||
expect(newArray[1]).toBe('test')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getPercentage', () => {
|
||||
it('should return 0 if the first number is 0', () => {
|
||||
const percentage = getPercentage(0, 1)
|
||||
expect(percentage).toBe(0)
|
||||
})
|
||||
|
||||
it('should return 0 if the second number is 0', () => {
|
||||
const percentage = getPercentage(1, 0)
|
||||
expect(percentage).toBe(0)
|
||||
})
|
||||
|
||||
it('should swap first number with second number, if the later is greater', () => {
|
||||
const percentage = getPercentage(10, 1)
|
||||
expect(percentage).toBe(10)
|
||||
})
|
||||
|
||||
it('should trucate numbers up to two places', () => {
|
||||
expect(getPercentage(38.2, 125)).toBe(30.56)
|
||||
expect(getPercentage(67.55, 125)).toBe(54.04)
|
||||
expect(getPercentage(86.65, 125)).toBe(69.32)
|
||||
expect(getPercentage(98.85, 125)).toBe(79.08)
|
||||
})
|
||||
|
||||
it('should return the percentage of two numbers', () => {
|
||||
expect(getPercentage(4, 20)).toBe(20)
|
||||
expect(getPercentage(10, 10)).toBe(100)
|
||||
expect(getPercentage(10, 100)).toBe(10)
|
||||
expect(getPercentage(10, 40)).toBe(25)
|
||||
expect(getPercentage(15, 30)).toBe(50)
|
||||
})
|
||||
})
|
||||
|
||||
describe('groupTasksByCompletedStatus', () => {
|
||||
it('should return open tasks and completed tasks', () => {
|
||||
const tasks: TaskPayload[] = [
|
||||
{
|
||||
id: 'test-1',
|
||||
description: 'Testing #1',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-2',
|
||||
description: 'Testing #2',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-3',
|
||||
description: 'Testing #3',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
]
|
||||
|
||||
const { openTasks, completedTasks } = groupTasksByCompletedStatus(tasks)
|
||||
|
||||
expect(openTasks).toHaveLength(2)
|
||||
expect(openTasks[0]).toBe(tasks[0])
|
||||
expect(openTasks[1]).toBe(tasks[1])
|
||||
|
||||
expect(completedTasks).toHaveLength(1)
|
||||
expect(completedTasks[0]).toBe(tasks[2])
|
||||
})
|
||||
})
|
||||
|
||||
describe('getTaskArrayFromGroupedTasks', () => {
|
||||
it('should return an array of tasks', () => {
|
||||
const workTasks = [
|
||||
{
|
||||
id: 'test-b-1',
|
||||
description: 'Test #1',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-b-2',
|
||||
description: 'Test #2',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
]
|
||||
|
||||
const personalTasks = [
|
||||
{
|
||||
id: 'test-c-1',
|
||||
description: 'Test #3',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-c-2',
|
||||
description: 'Test #4',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
]
|
||||
|
||||
const groupedTasks: GroupPayload[] = [
|
||||
{
|
||||
name: 'Work',
|
||||
tasks: workTasks,
|
||||
},
|
||||
{
|
||||
name: 'Personal',
|
||||
tasks: personalTasks,
|
||||
},
|
||||
]
|
||||
|
||||
const taskArray = getTaskArrayFromGroupedTasks(groupedTasks)
|
||||
|
||||
expect(taskArray).toHaveLength(workTasks.length + personalTasks.length)
|
||||
expect(taskArray).toStrictEqual([...workTasks, ...personalTasks])
|
||||
})
|
||||
})
|
||||
|
||||
describe('truncateText', () => {
|
||||
it('should return the text as-is', () => {
|
||||
const text = 'This is a simple text. It should not be truncated.'
|
||||
|
||||
expect(truncateText(text, 100)).toBe(text)
|
||||
})
|
||||
|
||||
it('should return the truncated text', () => {
|
||||
const text = 'This is a simple text. It should not be truncated.'
|
||||
const truncated = truncateText(text, 10)
|
||||
|
||||
expect(truncated).toHaveLength(13) // Includes ellipsis
|
||||
expect(truncated).toBe('This is a ...')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getPlainPreview', () => {
|
||||
it('should return a text preview in the format: {open tasks}/{all tasks}', () => {
|
||||
const workTasks = [
|
||||
{
|
||||
id: 'test-b-1',
|
||||
description: 'Test #1',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-b-2',
|
||||
description: 'Test #2',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
]
|
||||
|
||||
const personalTasks = [
|
||||
{
|
||||
id: 'test-c-1',
|
||||
description: 'Test #3',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-c-2',
|
||||
description: 'Test #4',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-c-3',
|
||||
description: 'Test #5',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
]
|
||||
|
||||
const groupedTasks: GroupPayload[] = [
|
||||
{
|
||||
name: 'Work',
|
||||
tasks: workTasks,
|
||||
},
|
||||
{
|
||||
name: 'Personal',
|
||||
tasks: personalTasks,
|
||||
},
|
||||
]
|
||||
|
||||
expect(getPlainPreview(groupedTasks)).toBe('2/5 tasks completed')
|
||||
expect(getPlainPreview([])).toBe('0/0 tasks completed')
|
||||
expect(getPlainPreview([{ name: 'Test', tasks: [] }])).toBe(
|
||||
'0/0 tasks completed'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('parseMarkdownTasks', () => {
|
||||
it('should not return tasks if payload is not in correct format', () => {
|
||||
expect(parseMarkdownTasks('')).toBeUndefined()
|
||||
expect(parseMarkdownTasks(' ')).toBeUndefined()
|
||||
expect(parseMarkdownTasks('this is just a piece of text')).toBeUndefined()
|
||||
expect(parseMarkdownTasks(undefined)).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should not return tasks without descriptions', () => {
|
||||
const payload = '- [ ] '
|
||||
expect(parseMarkdownTasks(payload)).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should return tasks from a payload with correct format', () => {
|
||||
const payload = `- [ ] Foo
|
||||
- [x] Bar
|
||||
- [ ] Foobar`
|
||||
|
||||
expect(parseMarkdownTasks(payload)).toMatchObject<GroupPayload>({
|
||||
name: 'Checklist',
|
||||
tasks: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
description: 'Foo',
|
||||
completed: false,
|
||||
createdAt: expect.any(Date),
|
||||
},
|
||||
{
|
||||
id: expect.any(String),
|
||||
description: 'Bar',
|
||||
completed: true,
|
||||
createdAt: expect.any(Date),
|
||||
},
|
||||
{
|
||||
id: expect.any(String),
|
||||
description: 'Foobar',
|
||||
completed: false,
|
||||
createdAt: expect.any(Date),
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,146 @@
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { GroupPayload, TaskPayload } from '../features/tasks/tasks-slice'
|
||||
|
||||
export function arrayMoveMutable(
|
||||
array: any[],
|
||||
fromIndex: number,
|
||||
toIndex: number
|
||||
) {
|
||||
const startIndex = fromIndex < 0 ? array.length + fromIndex : fromIndex
|
||||
if (startIndex >= 0 && startIndex < array.length) {
|
||||
const endIndex = toIndex < 0 ? array.length + toIndex : toIndex
|
||||
const [item] = array.splice(fromIndex, 1)
|
||||
array.splice(endIndex, 0, item)
|
||||
}
|
||||
}
|
||||
|
||||
export function arrayMoveImmutable(
|
||||
array: any[],
|
||||
fromIndex: number,
|
||||
toIndex: number
|
||||
) {
|
||||
array = [...array]
|
||||
arrayMoveMutable(array, fromIndex, toIndex)
|
||||
return array
|
||||
}
|
||||
|
||||
export function getPercentage(numberA: number, numberB: number): number {
|
||||
if (numberA === 0 || numberB === 0) {
|
||||
return 0
|
||||
}
|
||||
const min = Math.min(numberA, numberB)
|
||||
const max = Math.max(numberA, numberB)
|
||||
const percentage = (min / max) * 100
|
||||
return Number(percentage.toFixed(2))
|
||||
}
|
||||
|
||||
export function groupTasksByCompletedStatus(tasks: TaskPayload[]) {
|
||||
const openTasks = tasks.filter((task) => !task.completed)
|
||||
const completedTasks = tasks.filter((task) => task.completed)
|
||||
return {
|
||||
openTasks,
|
||||
completedTasks,
|
||||
}
|
||||
}
|
||||
|
||||
export function getTaskArrayFromGroupedTasks(
|
||||
groupedTasks: GroupPayload[]
|
||||
): TaskPayload[] {
|
||||
let taskArray: TaskPayload[] = []
|
||||
|
||||
groupedTasks.forEach((group) => {
|
||||
taskArray = taskArray.concat(group.tasks)
|
||||
})
|
||||
|
||||
return taskArray
|
||||
}
|
||||
|
||||
export function truncateText(text: string, limit: number = 50) {
|
||||
if (text.length <= limit) {
|
||||
return text
|
||||
}
|
||||
return text.substring(0, limit) + '...'
|
||||
}
|
||||
|
||||
export function getPlainPreview(groupedTasks: GroupPayload[]) {
|
||||
const allTasks = getTaskArrayFromGroupedTasks(groupedTasks)
|
||||
const { completedTasks } = groupTasksByCompletedStatus(allTasks)
|
||||
|
||||
return `${completedTasks.length}/${allTasks.length} tasks completed`
|
||||
}
|
||||
|
||||
function createTaskFromLine(rawTask: string): TaskPayload | undefined {
|
||||
const IS_COMPLETED = /^- \[x\] /i
|
||||
const OPEN_PREFIX = '- [ ] '
|
||||
|
||||
const description = rawTask.replace(OPEN_PREFIX, '').replace(IS_COMPLETED, '')
|
||||
|
||||
if (description.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
return {
|
||||
id: uuidv4(),
|
||||
description,
|
||||
completed: IS_COMPLETED.test(rawTask),
|
||||
createdAt: new Date(),
|
||||
}
|
||||
}
|
||||
|
||||
export function parseMarkdownTasks(payload?: string): GroupPayload | undefined {
|
||||
if (!payload) {
|
||||
return
|
||||
}
|
||||
|
||||
const IS_LEGACY_FORMAT = /^- \[[x ]\] .*/gim
|
||||
if (!IS_LEGACY_FORMAT.test(payload)) {
|
||||
return
|
||||
}
|
||||
|
||||
const lines = payload.split('\n')
|
||||
const tasks: TaskPayload[] = []
|
||||
|
||||
lines
|
||||
.filter((line) => line.replace(/ /g, '').length > 0)
|
||||
.map((line) => createTaskFromLine(line))
|
||||
.forEach((item) => item && tasks.push(item))
|
||||
|
||||
if (tasks.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
return {
|
||||
name: 'Checklist',
|
||||
tasks,
|
||||
}
|
||||
}
|
||||
|
||||
export function isJsonString(rawString: string) {
|
||||
try {
|
||||
JSON.parse(rawString)
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
export function isLastActiveGroup(
|
||||
allGroups: GroupPayload[],
|
||||
groupName: string
|
||||
): boolean {
|
||||
if (allGroups.length === 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
const lastActiveGroup = allGroups.reduce((prev, current) => {
|
||||
if (!prev.lastActive) {
|
||||
return current
|
||||
}
|
||||
if (!current.lastActive) {
|
||||
return prev
|
||||
}
|
||||
return prev.lastActive > current.lastActive ? prev : current
|
||||
})
|
||||
|
||||
return lastActiveGroup.name === groupName
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import reducer, {
|
||||
setCanEdit,
|
||||
setIsRunningOnMobile,
|
||||
setSpellCheckerEnabled,
|
||||
} from './settings-slice'
|
||||
import type { SettingsState } from './settings-slice'
|
||||
|
||||
it('should return the initial state', () => {
|
||||
return expect(
|
||||
reducer(undefined, {
|
||||
type: undefined,
|
||||
})
|
||||
).toEqual({
|
||||
canEdit: true,
|
||||
isRunningOnMobile: false,
|
||||
spellCheckerEnabled: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle setting canEdit property', () => {
|
||||
const previousState: SettingsState = {
|
||||
canEdit: false,
|
||||
isRunningOnMobile: false,
|
||||
spellCheckerEnabled: false,
|
||||
}
|
||||
|
||||
expect(reducer(previousState, setCanEdit(true))).toEqual({
|
||||
...previousState,
|
||||
canEdit: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle setting isRunningOnMobile property', () => {
|
||||
const previousState: SettingsState = {
|
||||
canEdit: false,
|
||||
isRunningOnMobile: false,
|
||||
spellCheckerEnabled: false,
|
||||
}
|
||||
|
||||
expect(reducer(previousState, setIsRunningOnMobile(true))).toEqual({
|
||||
...previousState,
|
||||
isRunningOnMobile: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle setting spellCheckerEnabled property', () => {
|
||||
const previousState: SettingsState = {
|
||||
canEdit: false,
|
||||
isRunningOnMobile: false,
|
||||
spellCheckerEnabled: false,
|
||||
}
|
||||
|
||||
expect(reducer(previousState, setSpellCheckerEnabled(true))).toEqual({
|
||||
...previousState,
|
||||
spellCheckerEnabled: true,
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
|
||||
export type SettingsState = {
|
||||
canEdit: boolean
|
||||
isRunningOnMobile: boolean
|
||||
spellCheckerEnabled: boolean
|
||||
}
|
||||
|
||||
const initialState: SettingsState = {
|
||||
canEdit: true,
|
||||
isRunningOnMobile: false,
|
||||
spellCheckerEnabled: true,
|
||||
}
|
||||
|
||||
const settingsSlice = createSlice({
|
||||
name: 'settings',
|
||||
initialState,
|
||||
reducers: {
|
||||
setCanEdit(state, action: PayloadAction<boolean>) {
|
||||
state.canEdit = action.payload
|
||||
},
|
||||
setIsRunningOnMobile(state, action: PayloadAction<boolean>) {
|
||||
state.isRunningOnMobile = action.payload
|
||||
},
|
||||
setSpellCheckerEnabled(state, action: PayloadAction<boolean>) {
|
||||
state.spellCheckerEnabled = action.payload
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export const { setCanEdit, setIsRunningOnMobile, setSpellCheckerEnabled } =
|
||||
settingsSlice.actions
|
||||
export default settingsSlice.reducer
|
||||
@@ -0,0 +1,99 @@
|
||||
import { fireEvent, screen } from '@testing-library/react'
|
||||
import { testRender } from '../../testUtils'
|
||||
|
||||
import { RootState } from '../../app/store'
|
||||
import CompletedTasksActions from './CompletedTasksActions'
|
||||
import { deleteAllCompleted, openAllCompleted } from './tasks-slice'
|
||||
|
||||
const group = 'default group'
|
||||
|
||||
it('renders two buttons', () => {
|
||||
testRender(<CompletedTasksActions groupName={group} />)
|
||||
|
||||
expect(screen.getByTestId('reopen-completed-button')).toHaveTextContent(
|
||||
'Reopen Completed'
|
||||
)
|
||||
expect(screen.getByTestId('delete-completed-button')).toHaveTextContent(
|
||||
'Delete Completed'
|
||||
)
|
||||
})
|
||||
|
||||
it('should not render buttons if can not edit', () => {
|
||||
const defaultState: Partial<RootState> = {
|
||||
settings: {
|
||||
canEdit: false,
|
||||
isRunningOnMobile: false,
|
||||
spellCheckerEnabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
testRender(<CompletedTasksActions groupName={group} />, {}, defaultState)
|
||||
|
||||
expect(
|
||||
screen.queryByTestId('reopen-completed-button')
|
||||
).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByTestId('delete-completed-button')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should dispatch openAllCompleted action', () => {
|
||||
const { mockStore } = testRender(<CompletedTasksActions groupName={group} />)
|
||||
|
||||
const reOpenCompletedButton = screen.getByTestId('reopen-completed-button')
|
||||
fireEvent.click(reOpenCompletedButton)
|
||||
|
||||
const confirmDialog = screen.getByTestId('reopen-all-tasks-dialog')
|
||||
expect(confirmDialog).toBeInTheDocument()
|
||||
expect(confirmDialog).toHaveTextContent(
|
||||
`Are you sure you want to reopen completed tasks in the '${group}' group?`
|
||||
)
|
||||
|
||||
const confirmButton = screen.getByTestId('confirm-dialog-button')
|
||||
fireEvent.click(confirmButton)
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
openAllCompleted({ groupName: group })
|
||||
)
|
||||
})
|
||||
|
||||
it('should dispatch deleteCompleted action', () => {
|
||||
const { mockStore } = testRender(<CompletedTasksActions groupName={group} />)
|
||||
|
||||
const deleteCompletedButton = screen.getByTestId('delete-completed-button')
|
||||
fireEvent.click(deleteCompletedButton)
|
||||
|
||||
const confirmDialog = screen.getByTestId('delete-completed-tasks-dialog')
|
||||
expect(confirmDialog).toBeInTheDocument()
|
||||
expect(confirmDialog).toHaveTextContent(
|
||||
`Are you sure you want to delete completed tasks in the '${group}' group?`
|
||||
)
|
||||
|
||||
const confirmButton = screen.getByTestId('confirm-dialog-button')
|
||||
fireEvent.click(confirmButton)
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
deleteAllCompleted({ groupName: group })
|
||||
)
|
||||
})
|
||||
|
||||
it('should dismiss dialogs', () => {
|
||||
const { mockStore } = testRender(<CompletedTasksActions groupName={group} />)
|
||||
|
||||
const reOpenCompletedButton = screen.getByTestId('reopen-completed-button')
|
||||
fireEvent.click(reOpenCompletedButton)
|
||||
|
||||
fireEvent.click(screen.getByTestId('cancel-dialog-button'))
|
||||
|
||||
const deleteCompletedButton = screen.getByTestId('delete-completed-button')
|
||||
fireEvent.click(deleteCompletedButton)
|
||||
|
||||
fireEvent.click(screen.getByTestId('cancel-dialog-button'))
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(0)
|
||||
})
|
||||
@@ -0,0 +1,87 @@
|
||||
import { useState } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../../app/hooks'
|
||||
import { ConfirmDialog } from '../../common/components'
|
||||
|
||||
import { openAllCompleted, deleteAllCompleted } from './tasks-slice'
|
||||
|
||||
const ActionButton = styled.button`
|
||||
background-color: var(--sn-stylekit-contrast-background-color);
|
||||
border-radius: 4px;
|
||||
border-style: none;
|
||||
color: var(--sn-stylekit-paragraph-text-color);
|
||||
cursor: pointer;
|
||||
display: inline;
|
||||
font-size: var(--sn-stylekit-font-size-h6);
|
||||
font-weight: 500;
|
||||
height: 25px;
|
||||
margin-right: 10px;
|
||||
opacity: 0.96;
|
||||
padding: 4px 10px 4px;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.8;
|
||||
text-decoration: none;
|
||||
}
|
||||
`
|
||||
|
||||
type CompletedTasksActionsProps = {
|
||||
groupName: string
|
||||
}
|
||||
|
||||
const CompletedTasksActions: React.FC<CompletedTasksActionsProps> = ({
|
||||
groupName,
|
||||
}) => {
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
|
||||
const [showReopenDialog, setShowReopenDialog] = useState(false)
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
|
||||
|
||||
if (!canEdit) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
return (
|
||||
<div data-testid="completed-tasks-actions">
|
||||
<ActionButton
|
||||
onClick={() => setShowReopenDialog(true)}
|
||||
data-testid="reopen-completed-button"
|
||||
>
|
||||
Reopen Completed
|
||||
</ActionButton>
|
||||
<ActionButton
|
||||
onClick={() => setShowDeleteDialog(true)}
|
||||
data-testid="delete-completed-button"
|
||||
>
|
||||
Delete Completed
|
||||
</ActionButton>
|
||||
{showReopenDialog && (
|
||||
<ConfirmDialog
|
||||
testId="reopen-all-tasks-dialog"
|
||||
confirmButtonStyle="danger"
|
||||
confirmButtonCb={() => dispatch(openAllCompleted({ groupName }))}
|
||||
cancelButtonCb={() => setShowReopenDialog(false)}
|
||||
>
|
||||
Are you sure you want to reopen completed tasks in the '
|
||||
<strong>{groupName}</strong>' group?
|
||||
</ConfirmDialog>
|
||||
)}
|
||||
{showDeleteDialog && (
|
||||
<ConfirmDialog
|
||||
testId="delete-completed-tasks-dialog"
|
||||
confirmButtonStyle="danger"
|
||||
confirmButtonCb={() => dispatch(deleteAllCompleted({ groupName }))}
|
||||
cancelButtonCb={() => setShowDeleteDialog(false)}
|
||||
>
|
||||
Are you sure you want to delete completed tasks in the '
|
||||
<strong>{groupName}</strong>' group?
|
||||
</ConfirmDialog>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default CompletedTasksActions
|
||||
@@ -0,0 +1,125 @@
|
||||
import { fireEvent, screen } from '@testing-library/react'
|
||||
import { RootState } from '../../app/store'
|
||||
|
||||
import { testRender } from '../../testUtils'
|
||||
import { tasksGroupAdded } from './tasks-slice'
|
||||
import CreateGroup from './CreateGroup'
|
||||
|
||||
const defaultTasksState = {
|
||||
tasks: {
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
name: 'test',
|
||||
tasks: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
it('renders a button by default', () => {
|
||||
testRender(<CreateGroup />)
|
||||
|
||||
expect(screen.queryByTestId('create-group-button')).not.toBeInTheDocument()
|
||||
expect(screen.getByTestId('create-group-input')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders nothing if user can not edit', () => {
|
||||
const defaultState: Partial<RootState> = {
|
||||
settings: {
|
||||
canEdit: false,
|
||||
isRunningOnMobile: false,
|
||||
spellCheckerEnabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
testRender(<CreateGroup />, {}, defaultState)
|
||||
|
||||
expect(screen.queryByTestId('create-group-button')).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('create-group-input')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders an input box when the button is clicked', () => {
|
||||
testRender(<CreateGroup />, {}, defaultTasksState)
|
||||
|
||||
const button = screen.getByTestId('create-group-button')
|
||||
fireEvent.click(button)
|
||||
|
||||
expect(button).not.toBeInTheDocument()
|
||||
|
||||
const inputBox = screen.queryByTestId('create-group-input')
|
||||
expect(inputBox).toBeInTheDocument()
|
||||
expect(inputBox).toHaveTextContent('')
|
||||
})
|
||||
|
||||
it('changes the input box text', () => {
|
||||
testRender(<CreateGroup />)
|
||||
|
||||
const inputBox = screen.getByTestId('create-group-input') as HTMLInputElement
|
||||
fireEvent.change(inputBox, { target: { value: 'This is the new text' } })
|
||||
|
||||
expect(inputBox.value).toBe('This is the new text')
|
||||
})
|
||||
|
||||
test('pressing enter when input box is empty, should not create a new group', () => {
|
||||
const { mockStore } = testRender(<CreateGroup />, {}, defaultTasksState)
|
||||
|
||||
let button = screen.getByTestId('create-group-button')
|
||||
fireEvent.click(button)
|
||||
|
||||
const inputBox = screen.getByTestId('create-group-input')
|
||||
fireEvent.keyPress(inputBox, {
|
||||
key: 'Enter',
|
||||
code: 'Enter',
|
||||
charCode: 13,
|
||||
target: { value: '' },
|
||||
})
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(0)
|
||||
|
||||
button = screen.getByTestId('create-group-button')
|
||||
|
||||
expect(inputBox).not.toBeInTheDocument()
|
||||
expect(button).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('pressing enter should create a new group', () => {
|
||||
const groupName = 'My group name'
|
||||
const { mockStore } = testRender(<CreateGroup />, {}, defaultTasksState)
|
||||
|
||||
let button = screen.getByTestId('create-group-button')
|
||||
fireEvent.click(button)
|
||||
|
||||
const inputBox = screen.getByTestId('create-group-input')
|
||||
fireEvent.keyPress(inputBox, {
|
||||
key: 'Enter',
|
||||
code: 'Enter',
|
||||
charCode: 13,
|
||||
target: { value: groupName },
|
||||
})
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(tasksGroupAdded({ groupName }))
|
||||
|
||||
button = screen.getByTestId('create-group-button')
|
||||
|
||||
expect(inputBox).not.toBeInTheDocument()
|
||||
expect(button).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('the create new group button is shown if the input box loses focus', () => {
|
||||
testRender(<CreateGroup />, {}, defaultTasksState)
|
||||
|
||||
let button = screen.getByTestId('create-group-button')
|
||||
fireEvent.click(button)
|
||||
|
||||
const inputBox = screen.getByTestId('create-group-input')
|
||||
fireEvent.blur(inputBox)
|
||||
|
||||
button = screen.getByTestId('create-group-button')
|
||||
|
||||
expect(inputBox).not.toBeInTheDocument()
|
||||
expect(button).toBeInTheDocument()
|
||||
})
|
||||
@@ -0,0 +1,163 @@
|
||||
import {
|
||||
ChangeEvent,
|
||||
createRef,
|
||||
FocusEvent,
|
||||
KeyboardEvent,
|
||||
useState,
|
||||
} from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../../app/hooks'
|
||||
import { tasksGroupAdded } from './tasks-slice'
|
||||
|
||||
import { TextInput, WideButton } from '../../common/components'
|
||||
import { AddIcon } from '../../common/components/icons'
|
||||
import { ArrowVector } from '../../common/components/vectors'
|
||||
|
||||
const InputContainer = styled.div`
|
||||
background-color: var(--sn-stylekit-background-color);
|
||||
border: 1px solid var(--sn-stylekit-border-color);
|
||||
border-radius: 8px;
|
||||
box-sizing: border-box;
|
||||
padding: 16px;
|
||||
width: 100%;
|
||||
`
|
||||
|
||||
const TutorialContainer = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-top: 9px;
|
||||
position: relative;
|
||||
`
|
||||
|
||||
const Tutorial = styled.div`
|
||||
align-items: center;
|
||||
align-content: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
z-index: 100;
|
||||
`
|
||||
|
||||
const TutorialText = styled.div`
|
||||
color: var(--sn-stylekit-paragraph-text-color);
|
||||
font-size: var(--sn-stylekit-font-size-h2);
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
width: 194px;
|
||||
`
|
||||
|
||||
const BaseEmptyContainer = styled.div`
|
||||
background-color: var(--sn-stylekit-border-color);
|
||||
border-radius: 8px;
|
||||
box-sizing: border-box;
|
||||
height: 66px;
|
||||
padding: 16px;
|
||||
margin-bottom: 9px;
|
||||
`
|
||||
|
||||
const EmptyContainer1 = styled(BaseEmptyContainer)`
|
||||
opacity: 0.8;
|
||||
`
|
||||
|
||||
const EmptyContainer2 = styled(BaseEmptyContainer)`
|
||||
opacity: 0.6;
|
||||
`
|
||||
|
||||
const EmptyContainer3 = styled(BaseEmptyContainer)`
|
||||
opacity: 0.4;
|
||||
`
|
||||
|
||||
const EmptyContainer4 = styled(BaseEmptyContainer)`
|
||||
opacity: 0.2;
|
||||
`
|
||||
|
||||
const CreateGroup: React.FC = () => {
|
||||
const inputRef = createRef<HTMLInputElement>()
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const [group, setGroup] = useState('')
|
||||
const [isCreateMode, setIsCreateMode] = useState(false)
|
||||
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
const spellCheckerEnabled = useAppSelector(
|
||||
(state) => state.settings.spellCheckerEnabled
|
||||
)
|
||||
const groupedTasks = useAppSelector((state) => state.tasks.groups)
|
||||
const taskGroupCount = groupedTasks.length
|
||||
|
||||
function toggleMode() {
|
||||
setIsCreateMode(!isCreateMode)
|
||||
}
|
||||
|
||||
function handleBlur(event: FocusEvent<HTMLInputElement>) {
|
||||
setIsCreateMode(false)
|
||||
setGroup('')
|
||||
}
|
||||
|
||||
function handleTextChange(event: ChangeEvent<HTMLInputElement>) {
|
||||
setGroup(event.target.value)
|
||||
}
|
||||
|
||||
function handleKeyPress(event: KeyboardEvent<HTMLInputElement>) {
|
||||
if (event.key === 'Enter') {
|
||||
const groupName = (event.target as HTMLInputElement).value
|
||||
if (groupName.length > 0) {
|
||||
dispatch(tasksGroupAdded({ groupName }))
|
||||
}
|
||||
|
||||
setIsCreateMode(false)
|
||||
setGroup('')
|
||||
}
|
||||
}
|
||||
|
||||
if (!canEdit) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{!isCreateMode && taskGroupCount > 0 ? (
|
||||
<WideButton data-testid="create-group-button" onClick={toggleMode}>
|
||||
<AddIcon />
|
||||
</WideButton>
|
||||
) : (
|
||||
<>
|
||||
<InputContainer>
|
||||
<TextInput
|
||||
testId="create-group-input"
|
||||
value={group}
|
||||
enterKeyHint={'go'}
|
||||
onBlur={handleBlur}
|
||||
onChange={handleTextChange}
|
||||
onKeyPress={handleKeyPress}
|
||||
placeholder="Name your task group and press enter"
|
||||
ref={inputRef}
|
||||
spellCheck={spellCheckerEnabled}
|
||||
textSize="big"
|
||||
autoFocus
|
||||
/>
|
||||
</InputContainer>
|
||||
{taskGroupCount === 0 && (
|
||||
<TutorialContainer>
|
||||
<Tutorial>
|
||||
<ArrowVector style={{ marginRight: 140, marginBottom: 12 }} />
|
||||
<TutorialText>
|
||||
Get started by naming your first task group
|
||||
</TutorialText>
|
||||
</Tutorial>
|
||||
<EmptyContainer1 />
|
||||
<EmptyContainer2 />
|
||||
<EmptyContainer3 />
|
||||
<EmptyContainer4 />
|
||||
</TutorialContainer>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default CreateGroup
|
||||
@@ -0,0 +1,84 @@
|
||||
import { fireEvent, screen } from '@testing-library/react'
|
||||
import { RootState } from '../../app/store'
|
||||
|
||||
import { testRender } from '../../testUtils'
|
||||
import CreateTask from './CreateTask'
|
||||
import { taskAdded } from './tasks-slice'
|
||||
|
||||
jest.mock('uuid', () => {
|
||||
return {
|
||||
v4: () => 'my-fake-uuid',
|
||||
}
|
||||
})
|
||||
|
||||
const defaultGroup = {
|
||||
name: 'My default group',
|
||||
tasks: [],
|
||||
}
|
||||
|
||||
it('renders a button by default', () => {
|
||||
testRender(<CreateTask group={defaultGroup} />)
|
||||
|
||||
const inputBox = screen.queryByTestId('create-task-input')
|
||||
expect(inputBox).toBeInTheDocument()
|
||||
expect(inputBox).toHaveTextContent('')
|
||||
})
|
||||
|
||||
it('should not render input if can not edit', () => {
|
||||
const defaultState: Partial<RootState> = {
|
||||
settings: {
|
||||
canEdit: false,
|
||||
isRunningOnMobile: false,
|
||||
spellCheckerEnabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
testRender(<CreateTask group={defaultGroup} />, {}, defaultState)
|
||||
|
||||
expect(screen.queryByTestId('create-task-input')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('changes the input box value', () => {
|
||||
testRender(<CreateTask group={defaultGroup} />)
|
||||
|
||||
const inputBox = screen.getByTestId('create-task-input') as HTMLInputElement
|
||||
fireEvent.change(inputBox, { target: { value: 'This is a simple task' } })
|
||||
|
||||
expect(inputBox.value).toBe('This is a simple task')
|
||||
})
|
||||
|
||||
test('pressing enter when input box is empty, should not create a new task', () => {
|
||||
const { mockStore } = testRender(<CreateTask group={defaultGroup} />)
|
||||
|
||||
const inputBox = screen.getByTestId('create-task-input')
|
||||
fireEvent.keyPress(inputBox, {
|
||||
key: 'Enter',
|
||||
code: 'Enter',
|
||||
charCode: 13,
|
||||
target: { value: '' },
|
||||
})
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('pressing enter when input box is not empty, should create a new task', () => {
|
||||
const { mockStore } = testRender(<CreateTask group={defaultGroup} />)
|
||||
|
||||
const inputBox = screen.getByTestId('create-task-input')
|
||||
fireEvent.keyPress(inputBox, {
|
||||
key: 'Enter',
|
||||
code: 'Enter',
|
||||
charCode: 13,
|
||||
target: { value: 'My awesome task' },
|
||||
})
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
taskAdded({
|
||||
task: { id: 'my-fake-uuid', description: 'My awesome task' },
|
||||
groupName: defaultGroup.name,
|
||||
})
|
||||
)
|
||||
})
|
||||
@@ -0,0 +1,86 @@
|
||||
import { ChangeEvent, createRef, KeyboardEvent, useState } from 'react'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../../app/hooks'
|
||||
import { GroupPayload, taskAdded, tasksGroupDraft } from './tasks-slice'
|
||||
|
||||
import { TextInput } from '../../common/components'
|
||||
import { DottedCircleIcon } from '../../common/components/icons'
|
||||
import { isLastActiveGroup } from '../../common/utils'
|
||||
|
||||
const Container = styled.div`
|
||||
align-items: center;
|
||||
display: flex;
|
||||
margin-bottom: 8px;
|
||||
|
||||
& > *:first-child {
|
||||
margin-left: 1px;
|
||||
margin-right: 9px;
|
||||
}
|
||||
`
|
||||
|
||||
type CreateTaskProps = {
|
||||
group: GroupPayload
|
||||
}
|
||||
|
||||
const CreateTask: React.FC<CreateTaskProps> = ({ group }) => {
|
||||
const inputRef = createRef<HTMLInputElement>()
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const spellCheckerEnabled = useAppSelector(
|
||||
(state) => state.settings.spellCheckerEnabled
|
||||
)
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
const allGroups = useAppSelector((state) => state.tasks.groups)
|
||||
|
||||
const groupName = group.name
|
||||
const [taskDraft, setTaskDraft] = useState<string>(group.draft ?? '')
|
||||
|
||||
function onTextChange(event: ChangeEvent<HTMLInputElement>) {
|
||||
const draft = event.target.value
|
||||
dispatch(tasksGroupDraft({ groupName, draft }))
|
||||
setTaskDraft(draft)
|
||||
}
|
||||
|
||||
function handleKeyPress(event: KeyboardEvent<HTMLInputElement>) {
|
||||
if (event.key === 'Enter') {
|
||||
const rawString = (event.target as HTMLInputElement).value
|
||||
if (rawString.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch(
|
||||
taskAdded({ task: { id: uuidv4(), description: rawString }, groupName })
|
||||
)
|
||||
setTaskDraft('')
|
||||
}
|
||||
}
|
||||
|
||||
if (!canEdit) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
const isLastActive = isLastActiveGroup(allGroups, groupName)
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<DottedCircleIcon />
|
||||
<TextInput
|
||||
testId="create-task-input"
|
||||
disabled={!canEdit}
|
||||
enterKeyHint={'go'}
|
||||
onChange={onTextChange}
|
||||
onKeyPress={handleKeyPress}
|
||||
placeholder={'Type a task and press enter'}
|
||||
ref={inputRef}
|
||||
spellCheck={spellCheckerEnabled}
|
||||
value={taskDraft}
|
||||
autoFocus={isLastActive}
|
||||
/>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
export default CreateTask
|
||||
@@ -0,0 +1,24 @@
|
||||
import styled from 'styled-components'
|
||||
import { useAppSelector } from '../../app/hooks'
|
||||
|
||||
const Container = styled.div`
|
||||
background-color: var(--sn-stylekit-background-color);
|
||||
border: 1px solid var(--sn-stylekit-border-color);
|
||||
border-radius: 8px;
|
||||
box-sizing: border-box;
|
||||
height: 100%;
|
||||
padding: 16px;
|
||||
margin-bottom: 9px;
|
||||
`
|
||||
|
||||
const InvalidContentError: React.FC = () => {
|
||||
const lastError = useAppSelector((state) => state.tasks.lastError)
|
||||
return (
|
||||
<Container>
|
||||
{lastError ||
|
||||
'An unknown error has occurred, and the content cannot be displayed.'}
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
export default InvalidContentError
|
||||
@@ -0,0 +1,257 @@
|
||||
import { screen, fireEvent } from '@testing-library/react'
|
||||
import { RootState } from '../../app/store'
|
||||
import { testRender } from '../../testUtils'
|
||||
|
||||
import MergeTaskGroups from './MergeTaskGroups'
|
||||
import { tasksGroupMerged } from './tasks-slice'
|
||||
|
||||
const handleClose = jest.fn()
|
||||
|
||||
it('renders the alert dialog when no groups are available to merge', () => {
|
||||
const defaultGroup = 'Test'
|
||||
const defaultState: Partial<RootState> = {
|
||||
tasks: {
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
name: 'Test',
|
||||
tasks: [
|
||||
{
|
||||
id: 'some-id',
|
||||
description: 'A simple task',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<MergeTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
|
||||
const alertDialog = screen.getByTestId('merge-task-group-dialog')
|
||||
expect(alertDialog).toBeInTheDocument()
|
||||
expect(alertDialog).toHaveTextContent(
|
||||
`There are no other groups to merge '${defaultGroup}' with.`
|
||||
)
|
||||
expect(alertDialog).not.toHaveTextContent(
|
||||
`Select which group you want to merge '${defaultGroup}' into:`
|
||||
)
|
||||
|
||||
// There shouldn't be any radio buttons
|
||||
expect(screen.queryAllByRole('radio')).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('renders the alert dialog when there are groups available to merge', () => {
|
||||
const defaultGroup = 'Test'
|
||||
const defaultState: Partial<RootState> = {
|
||||
tasks: {
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
name: 'Test',
|
||||
tasks: [
|
||||
{
|
||||
id: 'some-id',
|
||||
description: 'A simple task',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Testing',
|
||||
tasks: [
|
||||
{
|
||||
id: 'another-id',
|
||||
description: 'Another simple task',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Tests',
|
||||
tasks: [
|
||||
{
|
||||
id: 'yet-another-id',
|
||||
description: 'Yet another simple task',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<MergeTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
|
||||
const alertDialog = screen.getByTestId('merge-task-group-dialog')
|
||||
expect(alertDialog).toBeInTheDocument()
|
||||
expect(alertDialog).toHaveTextContent(
|
||||
`Select which group you want to merge '${defaultGroup}' into:`
|
||||
)
|
||||
expect(alertDialog).not.toHaveTextContent(
|
||||
`There are no other groups to merge '${defaultGroup}' with.`
|
||||
)
|
||||
|
||||
const radioButtons = screen.queryAllByRole('radio')
|
||||
expect(radioButtons).toHaveLength(2)
|
||||
|
||||
const firstRadioButton = radioButtons[0]
|
||||
expect(firstRadioButton).not.toBeChecked()
|
||||
expect(firstRadioButton).toHaveAttribute('value', 'Testing')
|
||||
|
||||
const secondRadioButton = radioButtons[1]
|
||||
expect(secondRadioButton).not.toBeChecked()
|
||||
expect(secondRadioButton).toHaveAttribute('value', 'Tests')
|
||||
})
|
||||
|
||||
it('should close the dialog if no group is selected and the Merge button is clicked', () => {
|
||||
const defaultGroup = 'Test'
|
||||
const defaultState: Partial<RootState> = {
|
||||
tasks: {
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
name: 'Test',
|
||||
tasks: [
|
||||
{
|
||||
id: 'some-id',
|
||||
description: 'A simple task',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Testing',
|
||||
tasks: [
|
||||
{
|
||||
id: 'another-id',
|
||||
description: 'Another simple task',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Tests',
|
||||
tasks: [
|
||||
{
|
||||
id: 'yet-another-id',
|
||||
description: 'Yet another simple task',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const { mockStore } = testRender(
|
||||
<MergeTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
|
||||
const buttons = screen.queryAllByRole('button')
|
||||
expect(buttons).toHaveLength(2)
|
||||
|
||||
const mergeButton = buttons[1]
|
||||
expect(mergeButton).toHaveTextContent('Merge groups')
|
||||
|
||||
fireEvent.click(mergeButton)
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(0)
|
||||
expect(handleClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should dispatch the action to merge groups', () => {
|
||||
const defaultGroup = 'Test'
|
||||
const defaultState: Partial<RootState> = {
|
||||
tasks: {
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
name: 'Test',
|
||||
tasks: [
|
||||
{
|
||||
id: 'some-id',
|
||||
description: 'A simple task',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Testing',
|
||||
tasks: [
|
||||
{
|
||||
id: 'another-id',
|
||||
description: 'Another simple task',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Tests',
|
||||
tasks: [
|
||||
{
|
||||
id: 'yet-another-id',
|
||||
description: 'Yet another simple task',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const { mockStore } = testRender(
|
||||
<MergeTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
|
||||
const radioButtons = screen.queryAllByRole('radio')
|
||||
|
||||
let dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(0)
|
||||
expect(handleClose).toHaveBeenCalledTimes(0)
|
||||
|
||||
const firstRadioButton = radioButtons[0]
|
||||
fireEvent.click(firstRadioButton)
|
||||
|
||||
const buttons = screen.queryAllByRole('button')
|
||||
expect(buttons).toHaveLength(2)
|
||||
|
||||
const cancelButton = buttons[0]
|
||||
expect(cancelButton).toHaveTextContent('Cancel')
|
||||
|
||||
const mergeButton = buttons[1]
|
||||
expect(mergeButton).toHaveTextContent('Merge groups')
|
||||
|
||||
fireEvent.click(mergeButton)
|
||||
|
||||
dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
tasksGroupMerged({ groupName: defaultGroup, mergeWith: 'Testing' })
|
||||
)
|
||||
expect(handleClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
@@ -0,0 +1,119 @@
|
||||
import '@reach/dialog/styles.css'
|
||||
|
||||
import React, { useRef, useState } from 'react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogLabel,
|
||||
AlertDialogDescription,
|
||||
} from '@reach/alert-dialog'
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../../app/hooks'
|
||||
import { tasksGroupMerged } from './tasks-slice'
|
||||
|
||||
type MergeTaskGroupsProps = {
|
||||
groupName: string
|
||||
handleClose: () => void
|
||||
}
|
||||
|
||||
const MergeTaskGroups: React.FC<MergeTaskGroupsProps> = ({
|
||||
groupName,
|
||||
handleClose,
|
||||
}) => {
|
||||
const cancelRef = useRef<HTMLButtonElement>(null)
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const groupedTasks = useAppSelector((state) => state.tasks.groups)
|
||||
const mergeableGroups = groupedTasks.filter((item) => item.name !== groupName)
|
||||
|
||||
const [mergeWith, setMergeWith] = useState<string>()
|
||||
|
||||
function handleChange(event: React.FormEvent<HTMLFieldSetElement>) {
|
||||
// @ts-ignore
|
||||
const selectedGroup = event.target.value
|
||||
setMergeWith(selectedGroup)
|
||||
}
|
||||
|
||||
function handleMergeGroups() {
|
||||
if (!mergeWith) {
|
||||
handleClose()
|
||||
return
|
||||
}
|
||||
|
||||
dispatch(tasksGroupMerged({ groupName, mergeWith }))
|
||||
handleClose()
|
||||
}
|
||||
|
||||
return (
|
||||
<AlertDialog
|
||||
data-testid="merge-task-group-dialog"
|
||||
leastDestructiveRef={cancelRef}
|
||||
>
|
||||
<div className="sk-modal-content">
|
||||
<div className="sn-component">
|
||||
<div className="sk-panel">
|
||||
<div className="sk-panel-content">
|
||||
<div className="sk-panel-section">
|
||||
<AlertDialogLabel className="sk-h3 sk-panel-section-title">
|
||||
Merging task groups
|
||||
</AlertDialogLabel>
|
||||
|
||||
{mergeableGroups.length > 0 ? (
|
||||
<>
|
||||
<AlertDialogDescription className="sk-panel-row">
|
||||
<p className="color-foreground">
|
||||
Select which group you want to merge '
|
||||
<strong>{groupName}</strong>' into:
|
||||
</p>
|
||||
</AlertDialogDescription>
|
||||
<fieldset className="flex flex-col" onChange={handleChange}>
|
||||
{mergeableGroups.map((item) => (
|
||||
<label
|
||||
key={item.name}
|
||||
className="flex items-center mb-1"
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
value={item.name}
|
||||
checked={item.name === mergeWith}
|
||||
readOnly
|
||||
/>
|
||||
{item.name}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
</>
|
||||
) : (
|
||||
<AlertDialogDescription>
|
||||
<p className="color-foreground">
|
||||
There are no other groups to merge '
|
||||
<strong>{groupName}</strong>' with.
|
||||
</p>
|
||||
</AlertDialogDescription>
|
||||
)}
|
||||
|
||||
<div className="flex my-1 mt-4">
|
||||
<button
|
||||
className="sn-button small neutral"
|
||||
onClick={handleClose}
|
||||
ref={cancelRef}
|
||||
>
|
||||
{!mergeWith ? 'Close' : 'Cancel'}
|
||||
</button>
|
||||
<button
|
||||
className="sn-button small ml-2 info"
|
||||
onClick={handleMergeGroups}
|
||||
>
|
||||
Merge groups
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AlertDialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default MergeTaskGroups
|
||||
@@ -0,0 +1,61 @@
|
||||
import '@reach/dialog/styles.css'
|
||||
|
||||
import React, { useRef } from 'react'
|
||||
import { AlertDialog, AlertDialogLabel } from '@reach/alert-dialog'
|
||||
|
||||
import { useAppDispatch } from '../../app/hooks'
|
||||
import { tasksLegacyContentMigrated } from './tasks-slice'
|
||||
|
||||
const MigrateLegacyContent: React.FC = () => {
|
||||
const cancelRef = useRef<HTMLButtonElement>(null)
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
function handleMigrate() {
|
||||
dispatch(tasksLegacyContentMigrated({ continue: true }))
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
dispatch(tasksLegacyContentMigrated({ continue: false }))
|
||||
}
|
||||
|
||||
return (
|
||||
<AlertDialog
|
||||
data-testid="migrate-legacy-content-dialog"
|
||||
leastDestructiveRef={cancelRef}
|
||||
>
|
||||
<div className="sk-modal-content">
|
||||
<div className="sn-component">
|
||||
<div className="sk-panel">
|
||||
<div className="sk-panel-content">
|
||||
<div className="sk-panel-section">
|
||||
<AlertDialogLabel className="sk-h3 sk-panel-section-title">
|
||||
Are you sure you want to migrate legacy content to the new
|
||||
format?
|
||||
</AlertDialogLabel>
|
||||
|
||||
<div className="flex my-1 mt-4">
|
||||
<button
|
||||
className="sn-button small neutral"
|
||||
onClick={handleCancel}
|
||||
ref={cancelRef}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
className="sn-button small ml-2 info"
|
||||
onClick={handleMigrate}
|
||||
>
|
||||
Migrate
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AlertDialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default MigrateLegacyContent
|
||||
@@ -0,0 +1,132 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import NotePreview from './NotePreview'
|
||||
import { GroupPayload } from './tasks-slice'
|
||||
|
||||
const workTasks = [
|
||||
{
|
||||
id: 'test-b-1',
|
||||
description: 'Test #1',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-b-2',
|
||||
description: 'Test #2',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
]
|
||||
|
||||
const personalTasks = [
|
||||
{
|
||||
id: 'test-c-1',
|
||||
description: 'Test #3',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-c-2',
|
||||
description: 'Test #4',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
]
|
||||
|
||||
const miscTasks = [
|
||||
{
|
||||
id: 'test-d-1',
|
||||
description: 'Test #5',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-d-2',
|
||||
description: 'Test #6',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
]
|
||||
|
||||
it('should render without tasks', () => {
|
||||
const groupedTasks: GroupPayload[] = []
|
||||
|
||||
render(<NotePreview groupedTasks={groupedTasks} />)
|
||||
|
||||
const header = screen.getByText('0/0 tasks completed')
|
||||
expect(header).toBeVisible()
|
||||
|
||||
const progressBar = screen.getByTestId('circular-progress-bar')
|
||||
expect(progressBar).toBeVisible()
|
||||
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
const progressBarBackground = progressBar.firstChild
|
||||
expect(progressBarBackground).toHaveClass('background')
|
||||
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
const progressBarStroke = progressBar.lastChild
|
||||
expect(progressBarStroke).toHaveClass('progress p-0')
|
||||
|
||||
const groupList = screen.queryAllByTestId('group-summary')
|
||||
expect(groupList).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('should render with tasks', () => {
|
||||
const groupedTasks = [
|
||||
{
|
||||
name: 'Work',
|
||||
tasks: workTasks,
|
||||
},
|
||||
{
|
||||
name: 'Personal',
|
||||
tasks: personalTasks,
|
||||
},
|
||||
]
|
||||
|
||||
render(<NotePreview groupedTasks={groupedTasks} />)
|
||||
|
||||
const header = screen.getByText('2/4 tasks completed')
|
||||
expect(header).toBeVisible()
|
||||
|
||||
const progressBar = screen.getByTestId('circular-progress-bar')
|
||||
expect(progressBar).toBeVisible()
|
||||
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
const progressBarBackground = progressBar.firstChild
|
||||
expect(progressBarBackground).toHaveClass('background')
|
||||
|
||||
// eslint-disable-next-line testing-library/no-node-access
|
||||
const progressBarStroke = progressBar.lastChild
|
||||
expect(progressBarStroke).toHaveClass('progress p-50')
|
||||
|
||||
const groupList = screen.getAllByTestId('group-summary')
|
||||
expect(groupList).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('should render a summary of the remaining group(s)', () => {
|
||||
const groupedTasks = [
|
||||
{
|
||||
name: 'Work',
|
||||
tasks: workTasks,
|
||||
},
|
||||
{
|
||||
name: 'Personal',
|
||||
tasks: personalTasks,
|
||||
},
|
||||
{
|
||||
name: 'Misc',
|
||||
tasks: miscTasks,
|
||||
},
|
||||
{
|
||||
name: 'Groceries',
|
||||
tasks: [
|
||||
{
|
||||
id: 'test-e-1',
|
||||
description: 'Test #7',
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
render(<NotePreview groupedTasks={groupedTasks} />)
|
||||
|
||||
const remainingGroups = screen.getByTestId('groups-remaining')
|
||||
expect(remainingGroups).toHaveTextContent('And 1 other group')
|
||||
expect(remainingGroups).toBeVisible()
|
||||
})
|
||||
@@ -0,0 +1,95 @@
|
||||
import {
|
||||
getPercentage,
|
||||
getTaskArrayFromGroupedTasks,
|
||||
groupTasksByCompletedStatus,
|
||||
truncateText,
|
||||
} from '../../common/utils'
|
||||
import { GroupPayload, TaskPayload } from './tasks-slice'
|
||||
|
||||
const GROUPS_PREVIEW_LIMIT = 3
|
||||
const MAX_GROUP_DESCRIPTION_LENGTH = 30
|
||||
|
||||
const Title: React.FC = ({ children }) => {
|
||||
return <p className="ml-2 w-full font-medium">{children}</p>
|
||||
}
|
||||
|
||||
type GroupSummaryProps = {
|
||||
groups: GroupPayload[]
|
||||
}
|
||||
|
||||
const GroupSummary: React.FC<GroupSummaryProps> = ({ groups }) => {
|
||||
const totalGroups = groups.length
|
||||
const groupsToPreview = groups.slice(
|
||||
0,
|
||||
Math.min(totalGroups, GROUPS_PREVIEW_LIMIT)
|
||||
)
|
||||
if (groupsToPreview.length === 0) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
const remainingGroups = totalGroups - groupsToPreview.length
|
||||
const groupNoun = remainingGroups > 1 ? 'groups' : 'group'
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="my-2">
|
||||
{groupsToPreview.map((group, index) => {
|
||||
const totalTasks = group.tasks.length
|
||||
const totalCompletedTasks = group.tasks.filter(
|
||||
(task) => task.completed === true
|
||||
).length
|
||||
|
||||
return (
|
||||
<p
|
||||
data-testid="group-summary"
|
||||
key={`group-${group.name}`}
|
||||
className="mb-1"
|
||||
>
|
||||
{truncateText(group.name, MAX_GROUP_DESCRIPTION_LENGTH)}
|
||||
<span className="px-2 neutral">
|
||||
{totalCompletedTasks}/{totalTasks}
|
||||
</span>
|
||||
</p>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
{remainingGroups > 0 && (
|
||||
<p data-testid="groups-remaining">
|
||||
And {remainingGroups} other {groupNoun}
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
type NotePreviewProps = {
|
||||
groupedTasks: GroupPayload[]
|
||||
}
|
||||
|
||||
const NotePreview: React.FC<NotePreviewProps> = ({ groupedTasks }) => {
|
||||
const allTasks: TaskPayload[] = getTaskArrayFromGroupedTasks(groupedTasks)
|
||||
const { completedTasks } = groupTasksByCompletedStatus(allTasks)
|
||||
const percentage = getPercentage(allTasks.length, completedTasks.length)
|
||||
const roundedPercentage = Math.floor(percentage / 10) * 10
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-grow items-center mb-3">
|
||||
<svg
|
||||
data-testid="circular-progress-bar"
|
||||
className="sk-circular-progress"
|
||||
viewBox="0 0 18 18"
|
||||
>
|
||||
<circle className="background" />
|
||||
<circle className={`progress p-${roundedPercentage}`} />
|
||||
</svg>
|
||||
<Title>
|
||||
{completedTasks.length}/{allTasks.length} tasks completed
|
||||
</Title>
|
||||
</div>
|
||||
<GroupSummary groups={groupedTasks} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default NotePreview
|
||||
@@ -0,0 +1,171 @@
|
||||
import { screen, fireEvent } from '@testing-library/react'
|
||||
import { RootState } from '../../app/store'
|
||||
import { testRender } from '../../testUtils'
|
||||
|
||||
import RenameTaskGroups from './RenameTaskGroups'
|
||||
import { tasksGroupRenamed } from './tasks-slice'
|
||||
|
||||
const handleClose = jest.fn()
|
||||
|
||||
it('renders the alert dialog with an input box', () => {
|
||||
const defaultGroup = 'Test'
|
||||
const defaultState: Partial<RootState> = {
|
||||
tasks: {
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
name: defaultGroup,
|
||||
tasks: [
|
||||
{
|
||||
id: 'some-id',
|
||||
description: 'A simple task',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<RenameTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
|
||||
const alertDialog = screen.getByTestId('rename-task-group-dialog')
|
||||
expect(alertDialog).toBeInTheDocument()
|
||||
expect(alertDialog).toHaveTextContent(`Renaming group '${defaultGroup}':`)
|
||||
|
||||
const inputBox = screen.getByTestId('new-group-name-input')
|
||||
expect(inputBox).toBeInTheDocument()
|
||||
expect(inputBox).toHaveTextContent('')
|
||||
})
|
||||
|
||||
it('should dispatch the action to merge groups', () => {
|
||||
const defaultGroup = 'Test'
|
||||
const defaultState: Partial<RootState> = {
|
||||
tasks: {
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
name: defaultGroup,
|
||||
tasks: [
|
||||
{
|
||||
id: 'some-id',
|
||||
description: 'A simple task',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Testing',
|
||||
tasks: [
|
||||
{
|
||||
id: 'another-id',
|
||||
description: 'Another simple task',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const { mockStore } = testRender(
|
||||
<RenameTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
|
||||
const newGroupName = 'My new group name'
|
||||
|
||||
const inputBox = screen.getByTestId(
|
||||
'new-group-name-input'
|
||||
) as HTMLInputElement
|
||||
|
||||
fireEvent.change(inputBox, { target: { value: newGroupName } })
|
||||
|
||||
expect(inputBox.value).toBe(newGroupName)
|
||||
|
||||
const buttons = screen.queryAllByRole('button')
|
||||
expect(buttons).toHaveLength(2)
|
||||
|
||||
const cancelButton = buttons[0]
|
||||
expect(cancelButton).toHaveTextContent('Cancel')
|
||||
|
||||
const mergeButton = buttons[1]
|
||||
expect(mergeButton).toHaveTextContent('Rename')
|
||||
|
||||
fireEvent.click(mergeButton)
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
tasksGroupRenamed({ groupName: defaultGroup, newName: newGroupName })
|
||||
)
|
||||
expect(handleClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should dispatch the action to merge groups on Enter press', () => {
|
||||
const defaultGroup = 'Test'
|
||||
const defaultState: Partial<RootState> = {
|
||||
tasks: {
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
name: defaultGroup,
|
||||
tasks: [
|
||||
{
|
||||
id: 'some-id',
|
||||
description: 'A simple task',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Testing',
|
||||
tasks: [
|
||||
{
|
||||
id: 'another-id',
|
||||
description: 'Another simple task',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const { mockStore } = testRender(
|
||||
<RenameTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
|
||||
const newGroupName = 'My new group name'
|
||||
|
||||
const inputBox = screen.getByTestId(
|
||||
'new-group-name-input'
|
||||
) as HTMLInputElement
|
||||
|
||||
fireEvent.change(inputBox, { target: { value: newGroupName } })
|
||||
fireEvent.keyPress(inputBox, {
|
||||
key: 'Enter',
|
||||
code: 'Enter',
|
||||
charCode: 13,
|
||||
target: { value: newGroupName },
|
||||
})
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
tasksGroupRenamed({ groupName: defaultGroup, newName: newGroupName })
|
||||
)
|
||||
expect(handleClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
@@ -0,0 +1,96 @@
|
||||
import '@reach/dialog/styles.css'
|
||||
|
||||
import React, { KeyboardEvent, useRef, useState } from 'react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogLabel,
|
||||
AlertDialogDescription,
|
||||
} from '@reach/alert-dialog'
|
||||
|
||||
import { useAppDispatch } from '../../app/hooks'
|
||||
import { tasksGroupRenamed } from './tasks-slice'
|
||||
import { TextInput } from '../../common/components'
|
||||
|
||||
type RenameTaskGroupsProps = {
|
||||
groupName: string
|
||||
handleClose: () => void
|
||||
}
|
||||
|
||||
const RenameTaskGroups: React.FC<RenameTaskGroupsProps> = ({
|
||||
groupName,
|
||||
handleClose,
|
||||
}) => {
|
||||
const cancelRef = useRef<HTMLButtonElement>(null)
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const [renameTo, setRenameTo] = useState<string>(groupName)
|
||||
|
||||
function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
|
||||
const newName = event.target.value
|
||||
setRenameTo(newName)
|
||||
}
|
||||
|
||||
function handleKeyPress(event: KeyboardEvent<HTMLInputElement>) {
|
||||
if (event.key === 'Enter') {
|
||||
const rawString = (event.target as HTMLInputElement).value
|
||||
rawString.length > 0 && handleRenameGroup()
|
||||
}
|
||||
}
|
||||
|
||||
function handleRenameGroup() {
|
||||
dispatch(tasksGroupRenamed({ groupName, newName: renameTo }))
|
||||
handleClose()
|
||||
}
|
||||
|
||||
return (
|
||||
<AlertDialog
|
||||
data-testid="rename-task-group-dialog"
|
||||
leastDestructiveRef={cancelRef}
|
||||
>
|
||||
<div className="sk-modal-content">
|
||||
<div className="sn-component">
|
||||
<div className="sk-panel">
|
||||
<div className="sk-panel-content">
|
||||
<div className="sk-panel-section">
|
||||
<AlertDialogLabel className="sk-h3 sk-panel-section-title">
|
||||
Renaming group '<strong>{groupName}</strong>':
|
||||
</AlertDialogLabel>
|
||||
|
||||
<AlertDialogDescription>
|
||||
<TextInput
|
||||
testId="new-group-name-input"
|
||||
autoFocus
|
||||
onChange={handleChange}
|
||||
onKeyPress={handleKeyPress}
|
||||
placeholder="Enter new group name"
|
||||
value={renameTo}
|
||||
/>
|
||||
</AlertDialogDescription>
|
||||
|
||||
<div className="flex my-1 mt-4">
|
||||
<button
|
||||
className="sn-button small neutral"
|
||||
onClick={handleClose}
|
||||
ref={cancelRef}
|
||||
>
|
||||
{renameTo.length === 0 ? 'Close' : 'Cancel'}
|
||||
</button>
|
||||
<button
|
||||
className="sn-button small ml-2 info"
|
||||
disabled={renameTo.length === 0}
|
||||
onClick={handleRenameGroup}
|
||||
>
|
||||
Rename
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AlertDialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default RenameTaskGroups
|
||||
@@ -0,0 +1,140 @@
|
||||
import { screen, fireEvent } from '@testing-library/react'
|
||||
|
||||
import { RootState } from '../../app/store'
|
||||
import { testRender } from '../../testUtils'
|
||||
import TaskGroup from './TaskGroup'
|
||||
|
||||
const defaultGroup = {
|
||||
name: 'default group',
|
||||
tasks: [
|
||||
{
|
||||
id: 'test-1',
|
||||
description: 'Testing',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-2',
|
||||
description: 'Testing',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
it('renders the group name', () => {
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />)
|
||||
|
||||
expect(screen.getByText(defaultGroup.name)).toBeVisible()
|
||||
})
|
||||
|
||||
it('renders the number of completed tasks and total tasks', () => {
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />)
|
||||
|
||||
const completedTasks = defaultGroup.tasks.filter(
|
||||
(task) => task.completed
|
||||
).length
|
||||
const totalTasks = defaultGroup.tasks.length
|
||||
|
||||
expect(screen.getByTestId('task-group-stats')).toHaveTextContent(
|
||||
`${completedTasks}/${totalTasks}`
|
||||
)
|
||||
})
|
||||
|
||||
it('renders the circular progress bar', () => {
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />)
|
||||
|
||||
expect(screen.getByTestId('circular-progress-bar')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not render a thematic break element', () => {
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />)
|
||||
|
||||
expect(screen.queryByTestId('task-group-separator')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders the element that is used to create a new task', () => {
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />)
|
||||
|
||||
expect(screen.getByTestId('create-task-input')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders the element that is used to display the list of tasks', () => {
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />)
|
||||
|
||||
expect(screen.getByTestId('task-list')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('collapses the group', () => {
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />)
|
||||
|
||||
const createTask = screen.getByTestId('create-task-input')
|
||||
const taskItemList = screen.getByTestId('task-list')
|
||||
|
||||
expect(createTask).toBeVisible()
|
||||
expect(taskItemList).toBeVisible()
|
||||
|
||||
const collapseButton = screen.getByTestId('collapse-task-group')
|
||||
fireEvent.click(collapseButton)
|
||||
|
||||
expect(createTask).not.toBeVisible()
|
||||
expect(taskItemList).not.toBeVisible()
|
||||
})
|
||||
|
||||
it('shows group options', () => {
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />)
|
||||
|
||||
expect(screen.getByTestId('task-group-options')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides group options if can not edit', () => {
|
||||
const defaultState: Partial<RootState> = {
|
||||
settings: {
|
||||
canEdit: false,
|
||||
isRunningOnMobile: false,
|
||||
spellCheckerEnabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<TaskGroup group={defaultGroup} isDragging={false} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
|
||||
expect(screen.queryByTestId('task-group-options')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows a reorder icon when on mobile', () => {
|
||||
let defaultState: Partial<RootState> = {
|
||||
settings: {
|
||||
canEdit: false,
|
||||
isRunningOnMobile: true,
|
||||
spellCheckerEnabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<TaskGroup group={defaultGroup} isDragging={false} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
|
||||
expect(screen.queryByTestId('reorder-icon')).not.toBeInTheDocument()
|
||||
|
||||
defaultState = {
|
||||
settings: {
|
||||
canEdit: true,
|
||||
isRunningOnMobile: true,
|
||||
spellCheckerEnabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<TaskGroup group={defaultGroup} isDragging={false} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
|
||||
expect(screen.getByTestId('reorder-icon')).toBeInTheDocument()
|
||||
})
|
||||
@@ -0,0 +1,141 @@
|
||||
import { useState } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../../app/hooks'
|
||||
import { getPercentage } from '../../common/utils'
|
||||
import { GroupPayload, tasksGroupCollapsed } from './tasks-slice'
|
||||
|
||||
import CreateTask from './CreateTask'
|
||||
import TaskItemList from './TaskItemList'
|
||||
|
||||
import TaskGroupOptions from './TaskGroupOptions'
|
||||
|
||||
import {
|
||||
CircularProgressBar,
|
||||
GenericInlineText,
|
||||
MainTitle,
|
||||
RoundButton,
|
||||
} from '../../common/components'
|
||||
import {
|
||||
ChevronDownIcon,
|
||||
ReorderIcon,
|
||||
ChevronUpIcon,
|
||||
} from '../../common/components/icons'
|
||||
|
||||
const TaskGroupContainer = styled.div<{ isLast?: boolean }>`
|
||||
background-color: var(--sn-stylekit-background-color);
|
||||
border: 1px solid var(--sn-stylekit-border-color);
|
||||
border-radius: 8px;
|
||||
box-sizing: border-box;
|
||||
padding: 16px;
|
||||
margin-bottom: ${({ isLast }) => (!isLast ? '9px' : '0px')};
|
||||
`
|
||||
|
||||
type CollapsableContainerProps = {
|
||||
collapsed: boolean
|
||||
}
|
||||
|
||||
const CollapsableContainer = styled.div<CollapsableContainerProps>`
|
||||
display: ${({ collapsed }) => (collapsed ? 'none' : 'block')};
|
||||
`
|
||||
|
||||
type TaskGroupProps = {
|
||||
group: GroupPayload
|
||||
isDragging: boolean
|
||||
isLast?: boolean
|
||||
style?: React.CSSProperties
|
||||
innerRef?: (element?: HTMLElement | null | undefined) => any
|
||||
onDragStart?: React.DragEventHandler<any>
|
||||
onTransitionEnd?: React.TransitionEventHandler<any>
|
||||
}
|
||||
|
||||
const TaskGroup: React.FC<TaskGroupProps> = ({
|
||||
group,
|
||||
isDragging,
|
||||
isLast,
|
||||
style,
|
||||
innerRef,
|
||||
onDragStart,
|
||||
onTransitionEnd,
|
||||
...props
|
||||
}) => {
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const groupName = group.name
|
||||
|
||||
const completedTasks = group.tasks.filter((task) => task.completed).length
|
||||
const totalTasks = group.tasks.length
|
||||
const percentageCompleted = getPercentage(completedTasks, totalTasks)
|
||||
|
||||
const [collapsed, setCollapsed] = useState<boolean>(!!group.collapsed)
|
||||
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
|
||||
const allTasksCompleted = totalTasks > 0 && totalTasks === completedTasks
|
||||
|
||||
function handleCollapse() {
|
||||
dispatch(tasksGroupCollapsed({ groupName, collapsed: !collapsed }))
|
||||
setCollapsed(!collapsed)
|
||||
}
|
||||
|
||||
function handleClick() {
|
||||
if (!collapsed) {
|
||||
return
|
||||
}
|
||||
setCollapsed(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<TaskGroupContainer
|
||||
ref={innerRef}
|
||||
style={style}
|
||||
onDragStart={onDragStart}
|
||||
onTransitionEnd={onTransitionEnd}
|
||||
isLast={isLast}
|
||||
>
|
||||
<div className="flex items-center justify-between h-8 mt-1 mb-1">
|
||||
<div className="flex flex-grow items-center" onClick={handleClick}>
|
||||
{canEdit && (
|
||||
<div className="mr-3 pt-1px" {...props}>
|
||||
<ReorderIcon highlight={isDragging} />
|
||||
</div>
|
||||
)}
|
||||
<MainTitle
|
||||
crossed={allTasksCompleted && collapsed}
|
||||
highlight={isDragging}
|
||||
>
|
||||
{groupName}
|
||||
</MainTitle>
|
||||
<CircularProgressBar size={18} percentage={percentageCompleted} />
|
||||
<GenericInlineText data-testid="task-group-stats">
|
||||
{completedTasks}/{totalTasks}
|
||||
</GenericInlineText>
|
||||
</div>
|
||||
{!isDragging && (
|
||||
<div className="flex items-center">
|
||||
{canEdit && (
|
||||
<div className="ml-3">
|
||||
<TaskGroupOptions groupName={groupName} />
|
||||
</div>
|
||||
)}
|
||||
<div className="ml-3">
|
||||
<RoundButton
|
||||
testId="collapse-task-group"
|
||||
onClick={handleCollapse}
|
||||
>
|
||||
{!collapsed ? <ChevronUpIcon /> : <ChevronDownIcon />}
|
||||
</RoundButton>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<CollapsableContainer collapsed={collapsed}>
|
||||
<CreateTask group={group} />
|
||||
<TaskItemList group={group} />
|
||||
</CollapsableContainer>
|
||||
</TaskGroupContainer>
|
||||
)
|
||||
}
|
||||
|
||||
export default TaskGroup
|
||||
@@ -0,0 +1,86 @@
|
||||
import React from 'react'
|
||||
import {
|
||||
DragDropContext,
|
||||
Draggable,
|
||||
Droppable,
|
||||
DropResult,
|
||||
} from 'react-beautiful-dnd'
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../../app/hooks'
|
||||
import { tasksGroupReordered } from './tasks-slice'
|
||||
|
||||
import TaskGroup from './TaskGroup'
|
||||
|
||||
const TaskGroupList: React.FC = () => {
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
const groupedTasks = useAppSelector((state) => state.tasks.groups)
|
||||
|
||||
function onDragEnd(result: DropResult) {
|
||||
const droppedOutsideList = !result.destination
|
||||
if (droppedOutsideList) {
|
||||
return
|
||||
}
|
||||
|
||||
const { source, destination } = result
|
||||
if (!destination) {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch(
|
||||
tasksGroupReordered({
|
||||
swapGroupIndex: source.index,
|
||||
withGroupIndex: destination.index,
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<DragDropContext data-testid="task-group-list" onDragEnd={onDragEnd}>
|
||||
<Droppable
|
||||
droppableId={'droppable-task-group-list'}
|
||||
isDropDisabled={!canEdit}
|
||||
>
|
||||
{(provided) => (
|
||||
<div {...provided.droppableProps} ref={provided.innerRef}>
|
||||
{groupedTasks.map((group, index) => {
|
||||
return (
|
||||
<Draggable
|
||||
key={`draggable-${group.name}`}
|
||||
draggableId={`draggable-${group.name}`}
|
||||
index={index}
|
||||
isDragDisabled={!canEdit}
|
||||
>
|
||||
{(
|
||||
{ innerRef, draggableProps, dragHandleProps },
|
||||
{ isDragging }
|
||||
) => {
|
||||
const { onTransitionEnd, ...restDraggableProps } =
|
||||
draggableProps
|
||||
return (
|
||||
<TaskGroup
|
||||
key={`group-${group.name}`}
|
||||
group={group}
|
||||
isDragging={isDragging}
|
||||
innerRef={innerRef}
|
||||
onTransitionEnd={onTransitionEnd}
|
||||
onDragStart={dragHandleProps?.onDragStart}
|
||||
isLast={groupedTasks.length - 1 === index}
|
||||
{...dragHandleProps}
|
||||
{...restDraggableProps}
|
||||
/>
|
||||
)
|
||||
}}
|
||||
</Draggable>
|
||||
)
|
||||
})}
|
||||
{provided.placeholder}
|
||||
</div>
|
||||
)}
|
||||
</Droppable>
|
||||
</DragDropContext>
|
||||
)
|
||||
}
|
||||
|
||||
export default TaskGroupList
|
||||
@@ -0,0 +1,143 @@
|
||||
import { fireEvent, screen } from '@testing-library/react'
|
||||
import { testRender } from '../../testUtils'
|
||||
|
||||
import TaskGroupOptions from './TaskGroupOptions'
|
||||
import { tasksGroupDeleted } from './tasks-slice'
|
||||
|
||||
function clickButton(element: HTMLElement) {
|
||||
fireEvent.mouseDown(element)
|
||||
fireEvent.mouseUp(element)
|
||||
fireEvent.click(element)
|
||||
fireEvent.mouseMove(element)
|
||||
fireEvent.mouseUp(element)
|
||||
}
|
||||
|
||||
const groupName = 'default group'
|
||||
|
||||
it('renders an options menu', () => {
|
||||
testRender(<TaskGroupOptions groupName={groupName} />)
|
||||
|
||||
const optionsButton = screen.getByTestId('task-group-options')
|
||||
expect(optionsButton).toBeInTheDocument()
|
||||
|
||||
const deleteTaskGroup = screen.getByTestId('delete-task-group')
|
||||
const mergeTaskGroup = screen.getByTestId('merge-task-group')
|
||||
|
||||
expect(deleteTaskGroup).not.toBeVisible()
|
||||
expect(mergeTaskGroup).not.toBeVisible()
|
||||
|
||||
clickButton(optionsButton)
|
||||
|
||||
expect(deleteTaskGroup).toBeVisible()
|
||||
expect(mergeTaskGroup).toBeVisible()
|
||||
})
|
||||
|
||||
it('should dispatch tasksGroupDeleted action', () => {
|
||||
const { mockStore } = testRender(<TaskGroupOptions groupName={groupName} />)
|
||||
|
||||
const optionsButton = screen.getByTestId('task-group-options')
|
||||
fireEvent.click(optionsButton)
|
||||
|
||||
const deleteTaskGroup = screen.getByTestId('delete-task-group')
|
||||
clickButton(deleteTaskGroup)
|
||||
|
||||
const confirmDialog = screen.getByTestId('delete-task-group-dialog')
|
||||
expect(confirmDialog).toBeInTheDocument()
|
||||
expect(confirmDialog).toHaveTextContent(
|
||||
`Are you sure you want to delete the group '${groupName}'?`
|
||||
)
|
||||
|
||||
const confirmButton = screen.getByTestId('confirm-dialog-button')
|
||||
fireEvent.click(confirmButton)
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(tasksGroupDeleted({ groupName }))
|
||||
})
|
||||
|
||||
it('should open the merge task group dialog', () => {
|
||||
testRender(<TaskGroupOptions groupName={groupName} />)
|
||||
|
||||
const optionsButton = screen.getByTestId('task-group-options')
|
||||
fireEvent.click(optionsButton)
|
||||
|
||||
const mergeTaskGroup = screen.getByTestId('merge-task-group')
|
||||
clickButton(mergeTaskGroup)
|
||||
|
||||
expect(screen.getByTestId('merge-task-group-dialog')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should open the delete task group dialog', () => {
|
||||
testRender(<TaskGroupOptions groupName={groupName} />)
|
||||
|
||||
const optionsButton = screen.getByTestId('task-group-options')
|
||||
fireEvent.click(optionsButton)
|
||||
|
||||
const deleteTaskGroup = screen.getByTestId('delete-task-group')
|
||||
clickButton(deleteTaskGroup)
|
||||
|
||||
expect(screen.getByTestId('delete-task-group-dialog')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should open the rename task group dialog', () => {
|
||||
testRender(<TaskGroupOptions groupName={groupName} />)
|
||||
|
||||
const optionsButton = screen.getByTestId('task-group-options')
|
||||
fireEvent.click(optionsButton)
|
||||
|
||||
const renameTaskGroup = screen.getByTestId('rename-task-group')
|
||||
clickButton(renameTaskGroup)
|
||||
|
||||
expect(screen.getByTestId('rename-task-group-dialog')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should close the delete task group dialog', () => {
|
||||
testRender(<TaskGroupOptions groupName={groupName} />)
|
||||
|
||||
const optionsButton = screen.getByTestId('task-group-options')
|
||||
fireEvent.click(optionsButton)
|
||||
|
||||
const deleteTaskGroup = screen.getByTestId('delete-task-group')
|
||||
clickButton(deleteTaskGroup)
|
||||
|
||||
const cancelButton = screen.getByTestId('cancel-dialog-button')
|
||||
clickButton(cancelButton)
|
||||
|
||||
expect(
|
||||
screen.queryByTestId('trash-task-group-dialog')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should close the merge task group dialog', () => {
|
||||
testRender(<TaskGroupOptions groupName={groupName} />)
|
||||
|
||||
const optionsButton = screen.getByTestId('task-group-options')
|
||||
fireEvent.click(optionsButton)
|
||||
|
||||
const mergeTaskGroup = screen.getByTestId('merge-task-group')
|
||||
clickButton(mergeTaskGroup)
|
||||
|
||||
const cancelButton = screen.queryAllByRole('button')[0]
|
||||
clickButton(cancelButton)
|
||||
|
||||
expect(
|
||||
screen.queryByTestId('merge-task-group-dialog')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should close the rename task group dialog', () => {
|
||||
testRender(<TaskGroupOptions groupName={groupName} />)
|
||||
|
||||
const optionsButton = screen.getByTestId('task-group-options')
|
||||
fireEvent.click(optionsButton)
|
||||
|
||||
const renameTaskGroup = screen.getByTestId('rename-task-group')
|
||||
clickButton(renameTaskGroup)
|
||||
|
||||
const cancelButton = screen.queryAllByRole('button')[0]
|
||||
clickButton(cancelButton)
|
||||
|
||||
expect(
|
||||
screen.queryByTestId('rename-task-group-dialog')
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
@@ -0,0 +1,91 @@
|
||||
import { useState } from 'react'
|
||||
import { Menu, MenuList, MenuButton, MenuItem } from '@reach/menu-button'
|
||||
import VisuallyHidden from '@reach/visually-hidden'
|
||||
|
||||
import { useAppDispatch } from '../../app/hooks'
|
||||
import { tasksGroupDeleted } from './tasks-slice'
|
||||
|
||||
import {
|
||||
MoreIcon,
|
||||
MergeIcon,
|
||||
TrashIcon,
|
||||
RenameIcon,
|
||||
} from '../../common/components/icons'
|
||||
|
||||
import { ConfirmDialog } from '../../common/components'
|
||||
|
||||
import MergeTaskGroups from './MergeTaskGroups'
|
||||
import RenameTaskGroups from './RenameTaskGroups'
|
||||
|
||||
type TaskGroupOptionsProps = {
|
||||
groupName: string
|
||||
}
|
||||
|
||||
const TaskGroupOptions: React.FC<TaskGroupOptionsProps> = ({ groupName }) => {
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const [showMergeDialog, setShowMergeDialog] = useState(false)
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
|
||||
const [showRenameDialog, setShowRenameDialog] = useState(false)
|
||||
|
||||
return (
|
||||
<>
|
||||
<Menu>
|
||||
<MenuButton data-testid="task-group-options" className="sn-icon-button">
|
||||
<VisuallyHidden>Options for '{groupName}' group</VisuallyHidden>
|
||||
<MoreIcon />
|
||||
</MenuButton>
|
||||
<MenuList>
|
||||
<MenuItem
|
||||
data-testid="delete-task-group"
|
||||
onSelect={() => setShowDeleteDialog(true)}
|
||||
>
|
||||
<TrashIcon />
|
||||
<span className="px-1">Delete group</span>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
data-testid="merge-task-group"
|
||||
onSelect={() => setShowMergeDialog(true)}
|
||||
>
|
||||
<MergeIcon />
|
||||
<span className="px-1">Merge into another group</span>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
data-testid="rename-task-group"
|
||||
onSelect={() => setShowRenameDialog(true)}
|
||||
>
|
||||
<RenameIcon />
|
||||
<span className="px-1">Rename</span>
|
||||
</MenuItem>
|
||||
</MenuList>
|
||||
</Menu>
|
||||
{showDeleteDialog && (
|
||||
<ConfirmDialog
|
||||
testId="delete-task-group-dialog"
|
||||
title="Delete group"
|
||||
confirmButtonText="Delete"
|
||||
confirmButtonStyle="danger"
|
||||
confirmButtonCb={() => dispatch(tasksGroupDeleted({ groupName }))}
|
||||
cancelButtonCb={() => setShowDeleteDialog(false)}
|
||||
>
|
||||
Are you sure you want to delete the group '
|
||||
<strong>{groupName}</strong>'?
|
||||
</ConfirmDialog>
|
||||
)}
|
||||
{showMergeDialog && (
|
||||
<MergeTaskGroups
|
||||
groupName={groupName}
|
||||
handleClose={() => setShowMergeDialog(false)}
|
||||
/>
|
||||
)}
|
||||
{showRenameDialog && (
|
||||
<RenameTaskGroups
|
||||
groupName={groupName}
|
||||
handleClose={() => setShowRenameDialog(false)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default TaskGroupOptions
|
||||
@@ -0,0 +1,35 @@
|
||||
$transition-duration: 750ms;
|
||||
|
||||
@keyframes fadeOut {
|
||||
100% {
|
||||
opacity: 0;
|
||||
max-height: 0;
|
||||
}
|
||||
0% {
|
||||
opacity: 1;
|
||||
max-height: 25px;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
0% {
|
||||
opacity: 0;
|
||||
max-height: 0;
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
max-height: 25px;
|
||||
}
|
||||
}
|
||||
|
||||
.task-item.fade-out {
|
||||
animation: fadeOut ease $transition-duration;
|
||||
animation-delay: $transition-duration;
|
||||
animation-fill-mode: forwards;
|
||||
}
|
||||
|
||||
.task-item.fade-in {
|
||||
animation: fadeIn ease $transition-duration;
|
||||
animation-delay: 0s;
|
||||
animation-fill-mode: forwards;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
||||
|
||||
import {
|
||||
taskDeleted,
|
||||
taskModified,
|
||||
TaskPayload,
|
||||
taskToggled,
|
||||
} from './tasks-slice'
|
||||
import { testRender } from '../../testUtils'
|
||||
import TaskItem from './TaskItem'
|
||||
|
||||
const groupName = 'default group'
|
||||
const task: TaskPayload = {
|
||||
id: 'test-1',
|
||||
description: 'Testing #1',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
}
|
||||
|
||||
it('renders a check box and textarea input', async () => {
|
||||
testRender(<TaskItem groupName={groupName} task={task} />)
|
||||
|
||||
expect(screen.getByTestId('check-box-input')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('text-area-input')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('clicking the check box should toggle the task as open/completed', () => {
|
||||
jest.useFakeTimers()
|
||||
|
||||
const { mockStore } = testRender(
|
||||
<TaskItem groupName={groupName} task={task} />
|
||||
)
|
||||
|
||||
const checkBox = screen.getByTestId('check-box-input')
|
||||
fireEvent.click(checkBox)
|
||||
|
||||
jest.runAllTimers()
|
||||
|
||||
let dispatchedActions = mockStore.getActions()
|
||||
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
taskToggled({
|
||||
id: task.id,
|
||||
groupName,
|
||||
})
|
||||
)
|
||||
|
||||
fireEvent.click(checkBox)
|
||||
|
||||
dispatchedActions = mockStore.getActions()
|
||||
|
||||
jest.runAllTimers()
|
||||
|
||||
expect(dispatchedActions).toHaveLength(2)
|
||||
expect(dispatchedActions[1]).toMatchObject(
|
||||
taskToggled({
|
||||
id: task.id,
|
||||
groupName,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test('changing the textarea input text should update the task description', async () => {
|
||||
jest.useFakeTimers()
|
||||
|
||||
const newTaskDescription = 'My new task'
|
||||
|
||||
const { mockStore } = testRender(
|
||||
<TaskItem groupName={groupName} task={task} />
|
||||
)
|
||||
|
||||
const textAreaInput = screen.getByTestId(
|
||||
'text-area-input'
|
||||
) as HTMLTextAreaElement
|
||||
fireEvent.change(textAreaInput, {
|
||||
target: { value: newTaskDescription },
|
||||
})
|
||||
fireEvent.keyUp(textAreaInput, {
|
||||
target: { value: newTaskDescription },
|
||||
})
|
||||
|
||||
await waitFor(() => {
|
||||
expect(textAreaInput.value).toBe(newTaskDescription)
|
||||
})
|
||||
|
||||
jest.runAllTimers()
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
taskModified({
|
||||
task: {
|
||||
id: task.id,
|
||||
description: newTaskDescription,
|
||||
},
|
||||
groupName,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test('clearing the textarea input text should delete the task', () => {
|
||||
const { mockStore } = testRender(
|
||||
<TaskItem groupName={groupName} task={task} />
|
||||
)
|
||||
|
||||
const textAreaInput = screen.getByTestId('text-area-input')
|
||||
fireEvent.change(textAreaInput, {
|
||||
target: { value: '' },
|
||||
})
|
||||
fireEvent.keyUp(textAreaInput, {
|
||||
key: 'Enter',
|
||||
code: 'Enter',
|
||||
charCode: 13,
|
||||
target: { value: '' },
|
||||
})
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
taskDeleted({
|
||||
id: task.id,
|
||||
groupName,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test('pressing enter should not update the task description', () => {
|
||||
const { mockStore } = testRender(
|
||||
<TaskItem groupName={groupName} task={task} />
|
||||
)
|
||||
|
||||
const textAreaInput = screen.getByTestId('text-area-input')
|
||||
fireEvent.keyPress(textAreaInput, {
|
||||
key: 'Enter',
|
||||
code: 'Enter',
|
||||
charCode: 13,
|
||||
target: { value: 'This is a test' },
|
||||
})
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
|
||||
expect(dispatchedActions).toHaveLength(0)
|
||||
})
|
||||
@@ -0,0 +1,175 @@
|
||||
import './TaskItem.scss'
|
||||
|
||||
import {
|
||||
ChangeEvent,
|
||||
createRef,
|
||||
KeyboardEvent,
|
||||
useEffect,
|
||||
useState,
|
||||
} from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import {
|
||||
taskDeleted,
|
||||
taskModified,
|
||||
TaskPayload,
|
||||
taskToggled,
|
||||
} from './tasks-slice'
|
||||
import { useAppDispatch, useAppSelector, useDidMount } from '../../app/hooks'
|
||||
|
||||
import { CheckBoxInput, TextAreaInput } from '../../common/components'
|
||||
|
||||
/**
|
||||
* A delay in the dispatch function, when a task is opened.
|
||||
* Necessary to allow for transitions to occur.
|
||||
*/
|
||||
const DISPATCH_OPENED_DELAY_MS = 1_250
|
||||
|
||||
/**
|
||||
* A delay in the dispatch function, when a task is completed.
|
||||
* Necessary to allow for transitions to occur.
|
||||
*/
|
||||
const DISPATCH_COMPLETED_DELAY_MS = 1_850
|
||||
|
||||
const Container = styled.div<{ completed?: boolean }>`
|
||||
align-content: center;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
${({ completed }) =>
|
||||
completed &&
|
||||
`
|
||||
color: var(--sn-stylekit-info-color);
|
||||
`}
|
||||
|
||||
min-width: 10%;
|
||||
max-width: 85%;
|
||||
`
|
||||
|
||||
export type TaskItemProps = {
|
||||
task: TaskPayload
|
||||
groupName: string
|
||||
innerRef?: (element?: HTMLElement | null | undefined) => any
|
||||
}
|
||||
|
||||
const TaskItem: React.FC<TaskItemProps> = ({
|
||||
task,
|
||||
groupName,
|
||||
innerRef,
|
||||
...props
|
||||
}) => {
|
||||
const textAreaRef = createRef<HTMLTextAreaElement>()
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
const spellCheckEnabled = useAppSelector(
|
||||
(state) => state.settings.spellCheckerEnabled
|
||||
)
|
||||
|
||||
const [completed, setCompleted] = useState(!!task.completed)
|
||||
const [description, setDescription] = useState(task.description)
|
||||
|
||||
function resizeTextArea(textarea: HTMLTextAreaElement | null): void {
|
||||
if (!textarea) {
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to 1px first to reset scroll height in case it shrunk.
|
||||
*/
|
||||
const heightOffset = 4
|
||||
textarea.style.height = '1px'
|
||||
textarea.style.height = textarea.scrollHeight - heightOffset + 'px'
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
resizeTextArea(textAreaRef.current)
|
||||
})
|
||||
|
||||
function onCheckBoxToggle() {
|
||||
const newCompletedState = !completed
|
||||
setCompleted(newCompletedState)
|
||||
|
||||
newCompletedState
|
||||
? textAreaRef.current!.classList.add('cross-out')
|
||||
: textAreaRef.current!.classList.add('no-text-decoration')
|
||||
|
||||
const dispatchDelay = newCompletedState
|
||||
? DISPATCH_COMPLETED_DELAY_MS
|
||||
: DISPATCH_OPENED_DELAY_MS
|
||||
|
||||
setTimeout(() => {
|
||||
dispatch(taskToggled({ id: task.id, groupName }))
|
||||
}, dispatchDelay)
|
||||
}
|
||||
|
||||
function onTextChange(event: ChangeEvent<HTMLTextAreaElement>) {
|
||||
setDescription(event.target.value)
|
||||
}
|
||||
|
||||
function onKeyUp(event: KeyboardEvent<HTMLTextAreaElement>) {
|
||||
// Delete task if empty and enter pressed
|
||||
if (event.key === 'Enter') {
|
||||
if (description.length === 0) {
|
||||
dispatch(taskDeleted({ id: task.id, groupName }))
|
||||
event.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
const element = event.target as HTMLTextAreaElement
|
||||
resizeTextArea(element)
|
||||
}
|
||||
|
||||
function onKeyPress(event: KeyboardEvent<HTMLTextAreaElement>) {
|
||||
if (event.key === 'Enter') {
|
||||
// We want to disable any action on enter.
|
||||
event.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the task after the user has stopped typing.
|
||||
*/
|
||||
useDidMount(() => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
if (description !== task.description) {
|
||||
dispatch(
|
||||
taskModified({ task: { id: task.id, description }, groupName })
|
||||
)
|
||||
}
|
||||
}, 500)
|
||||
|
||||
return () => clearTimeout(timeoutId)
|
||||
}, [description, groupName])
|
||||
|
||||
return (
|
||||
<Container
|
||||
data-testid="task-item"
|
||||
completed={completed}
|
||||
ref={innerRef}
|
||||
{...props}
|
||||
>
|
||||
<CheckBoxInput
|
||||
testId="check-box-input"
|
||||
checked={completed}
|
||||
disabled={!canEdit}
|
||||
onChange={onCheckBoxToggle}
|
||||
/>
|
||||
<TextAreaInput
|
||||
testId="text-area-input"
|
||||
className="text-area-input"
|
||||
disabled={!canEdit || !!completed}
|
||||
onChange={onTextChange}
|
||||
onKeyPress={onKeyPress}
|
||||
onKeyUp={onKeyUp}
|
||||
ref={textAreaRef}
|
||||
spellCheck={spellCheckEnabled}
|
||||
value={description}
|
||||
/>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
export default TaskItem
|
||||
@@ -0,0 +1,67 @@
|
||||
import { screen, within } from '@testing-library/react'
|
||||
|
||||
import { testRender } from '../../testUtils'
|
||||
import TaskItemList from './TaskItemList'
|
||||
|
||||
const defaultGroup = {
|
||||
name: 'default group',
|
||||
tasks: [
|
||||
{
|
||||
id: 'test-1',
|
||||
description: 'Testing #1',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 'test-2',
|
||||
description: 'Testing #2',
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
it('renders the open tasks container', async () => {
|
||||
testRender(<TaskItemList group={defaultGroup} />)
|
||||
|
||||
const openTasksContainer = screen.getByTestId('open-tasks-container')
|
||||
|
||||
expect(openTasksContainer).toBeInTheDocument()
|
||||
expect(openTasksContainer).toHaveTextContent('open tasks')
|
||||
|
||||
const taskItems = within(openTasksContainer).getAllByTestId('task-item')
|
||||
expect(taskItems).toHaveLength(2)
|
||||
|
||||
const completedTasksActions = screen.queryByTestId('completed-tasks-actions')
|
||||
expect(completedTasksActions).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders the completed tasks container', () => {
|
||||
const groupWithCompletedTask = {
|
||||
name: 'a new group',
|
||||
tasks: [
|
||||
...defaultGroup.tasks,
|
||||
{
|
||||
id: 'test-3',
|
||||
description: 'Testing #3',
|
||||
completed: true,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
testRender(<TaskItemList group={groupWithCompletedTask} />)
|
||||
|
||||
const completedTasksContainer = screen.getByTestId(
|
||||
'completed-tasks-container'
|
||||
)
|
||||
|
||||
expect(completedTasksContainer).toBeInTheDocument()
|
||||
expect(completedTasksContainer).toHaveTextContent('completed tasks')
|
||||
|
||||
const taskItems = within(completedTasksContainer).getAllByTestId('task-item')
|
||||
expect(taskItems).toHaveLength(1)
|
||||
|
||||
const completedTasksActions = screen.getByTestId('completed-tasks-actions')
|
||||
expect(completedTasksActions).toBeInTheDocument()
|
||||
})
|
||||
@@ -0,0 +1,71 @@
|
||||
import React from 'react'
|
||||
import { DragDropContext, DropResult } from 'react-beautiful-dnd'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import { useAppDispatch } from '../../app/hooks'
|
||||
import { groupTasksByCompletedStatus } from '../../common/utils'
|
||||
import { GroupPayload, tasksReordered } from './tasks-slice'
|
||||
|
||||
import TasksContainer from './TasksContainer'
|
||||
import CompletedTasksActions from './CompletedTasksActions'
|
||||
|
||||
const Container = styled.div`
|
||||
position: relative;
|
||||
`
|
||||
|
||||
type TaskItemListProps = {
|
||||
group: GroupPayload
|
||||
}
|
||||
|
||||
const TaskItemList: React.FC<TaskItemListProps> = ({ group }) => {
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const { openTasks, completedTasks } = groupTasksByCompletedStatus(group.tasks)
|
||||
|
||||
function onDragEnd(result: DropResult) {
|
||||
const droppedOutsideList = !result.destination
|
||||
if (droppedOutsideList) {
|
||||
return
|
||||
}
|
||||
|
||||
const { source, destination } = result
|
||||
if (!destination) {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch(
|
||||
tasksReordered({
|
||||
groupName: group.name,
|
||||
swapTaskIndex: source.index,
|
||||
withTaskIndex: destination.index,
|
||||
isSameSection: source.droppableId === destination.droppableId,
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Container data-testid="task-list">
|
||||
<DragDropContext onDragEnd={onDragEnd}>
|
||||
<TasksContainer
|
||||
testId="open-tasks-container"
|
||||
type="open"
|
||||
tasks={openTasks}
|
||||
groupName={group.name}
|
||||
/>
|
||||
|
||||
<TasksContainer
|
||||
testId="completed-tasks-container"
|
||||
type="completed"
|
||||
tasks={completedTasks}
|
||||
groupName={group.name}
|
||||
>
|
||||
{completedTasks.length > 0 && (
|
||||
<CompletedTasksActions groupName={group.name} />
|
||||
)}
|
||||
</TasksContainer>
|
||||
</DragDropContext>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
export default TaskItemList
|
||||
@@ -0,0 +1,10 @@
|
||||
.completed-tasks-container {
|
||||
.task-item .checkbox-button * {
|
||||
stroke: var(--sn-stylekit-neutral-color) !important;
|
||||
}
|
||||
|
||||
.task-item .text-area-input {
|
||||
color: var(--sn-stylekit-neutral-color) !important;
|
||||
text-decoration: line-through 1px solid var(--sn-stylekit-neutral-color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
import './TasksContainer.scss'
|
||||
|
||||
import React from 'react'
|
||||
import {
|
||||
Draggable,
|
||||
DraggingStyle,
|
||||
Droppable,
|
||||
NotDraggingStyle,
|
||||
} from 'react-beautiful-dnd'
|
||||
import styled from 'styled-components'
|
||||
import { CSSTransition, TransitionGroup } from 'react-transition-group'
|
||||
|
||||
import { useAppSelector } from '../../app/hooks'
|
||||
import { SubTitle } from '../../common/components'
|
||||
import { TaskPayload } from './tasks-slice'
|
||||
|
||||
import TaskItem from './TaskItem'
|
||||
|
||||
const InnerTasksContainer = styled.div<{
|
||||
type: ContainerType
|
||||
items: number
|
||||
}>`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
& > *:not(:last-child) {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
${({ type, items }) =>
|
||||
type === 'completed' && items > 0 ? 'margin-bottom: 28px' : ''};
|
||||
`
|
||||
|
||||
const OuterContainer = styled.div<{ type: ContainerType; items: number }>`
|
||||
${({ type, items }) =>
|
||||
type === 'open' && items > 0 ? 'margin-bottom: 18px' : ''};
|
||||
`
|
||||
|
||||
const SubTitleContainer = styled.div`
|
||||
align-items: center;
|
||||
display: flex;
|
||||
|
||||
& > *:first-child {
|
||||
margin-right: 14px;
|
||||
}
|
||||
`
|
||||
|
||||
const Wrapper = styled.div`
|
||||
color: var(--sn-stylekit-foreground-color);
|
||||
`
|
||||
|
||||
const getItemStyle = (
|
||||
isDragging: boolean,
|
||||
draggableStyle?: DraggingStyle | NotDraggingStyle
|
||||
) => ({
|
||||
...draggableStyle,
|
||||
...(isDragging && {
|
||||
color: 'var(--sn-stylekit-info-color)',
|
||||
fontWeight: 500,
|
||||
}),
|
||||
})
|
||||
|
||||
type ContainerType = 'open' | 'completed'
|
||||
|
||||
type TasksContainerProps = {
|
||||
groupName: string
|
||||
tasks: TaskPayload[]
|
||||
type: ContainerType
|
||||
testId?: string
|
||||
}
|
||||
|
||||
const TasksContainer: React.FC<TasksContainerProps> = ({
|
||||
groupName,
|
||||
tasks,
|
||||
type,
|
||||
testId,
|
||||
children,
|
||||
}) => {
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
const droppableId = `${type}-tasks-droppable`
|
||||
|
||||
return (
|
||||
<OuterContainer data-testid={testId} type={type} items={tasks.length}>
|
||||
<Droppable droppableId={droppableId} isDropDisabled={!canEdit}>
|
||||
{(provided) => (
|
||||
<Wrapper>
|
||||
<SubTitleContainer>
|
||||
<SubTitle>{type} tasks</SubTitle>
|
||||
</SubTitleContainer>
|
||||
<InnerTasksContainer
|
||||
{...provided.droppableProps}
|
||||
className={`${type}-tasks-container`}
|
||||
items={tasks.length}
|
||||
ref={provided.innerRef}
|
||||
type={type}
|
||||
>
|
||||
<TransitionGroup
|
||||
component={null}
|
||||
childFactory={(child) => React.cloneElement(child)}
|
||||
>
|
||||
{tasks.map((task, index) => {
|
||||
return (
|
||||
<CSSTransition
|
||||
key={`${task.id}-${!!task.completed}`}
|
||||
classNames={{
|
||||
enter: 'fade-in',
|
||||
enterActive: 'fade-in',
|
||||
enterDone: 'fade-in',
|
||||
exit: 'fade-out',
|
||||
exitActive: 'fade-out',
|
||||
exitDone: 'fade-out',
|
||||
}}
|
||||
timeout={{
|
||||
enter: 1_500,
|
||||
exit: 1_250,
|
||||
}}
|
||||
onEnter={(node: HTMLElement) => {
|
||||
node.classList.remove('explode')
|
||||
}}
|
||||
onEntered={(node: HTMLElement) => {
|
||||
node.classList.remove('fade-in')
|
||||
|
||||
const completed = !!task.completed
|
||||
completed && node.classList.add('explode')
|
||||
|
||||
node.addEventListener(
|
||||
'animationend',
|
||||
() => {
|
||||
node.classList.remove('explode')
|
||||
},
|
||||
false
|
||||
)
|
||||
}}
|
||||
onExited={(node: HTMLElement) => {
|
||||
node.classList.remove('fade-out')
|
||||
}}
|
||||
addEndListener={(node, done) => {
|
||||
done()
|
||||
}}
|
||||
mountOnEnter
|
||||
unmountOnExit
|
||||
>
|
||||
<Draggable
|
||||
key={`draggable-${task.id}`}
|
||||
draggableId={`draggable-${task.id}`}
|
||||
index={index}
|
||||
isDragDisabled={!canEdit}
|
||||
>
|
||||
{(
|
||||
{ innerRef, draggableProps, dragHandleProps },
|
||||
{ isDragging }
|
||||
) => {
|
||||
const { style, ...restDraggableProps } =
|
||||
draggableProps
|
||||
return (
|
||||
<div
|
||||
className="task-item"
|
||||
style={getItemStyle(isDragging, style)}
|
||||
{...restDraggableProps}
|
||||
>
|
||||
<TaskItem
|
||||
key={`task-item-${task.id}`}
|
||||
task={task}
|
||||
groupName={groupName}
|
||||
innerRef={innerRef}
|
||||
{...dragHandleProps}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}}
|
||||
</Draggable>
|
||||
</CSSTransition>
|
||||
)
|
||||
})}
|
||||
</TransitionGroup>
|
||||
{provided.placeholder}
|
||||
</InnerTasksContainer>
|
||||
{children}
|
||||
</Wrapper>
|
||||
)}
|
||||
</Droppable>
|
||||
</OuterContainer>
|
||||
)
|
||||
}
|
||||
|
||||
export default TasksContainer
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,358 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import {
|
||||
arrayMoveImmutable,
|
||||
isJsonString,
|
||||
parseMarkdownTasks,
|
||||
} from '../../common/utils'
|
||||
|
||||
export type TasksState = {
|
||||
schemaVersion: string
|
||||
groups: GroupPayload[]
|
||||
initialized?: boolean
|
||||
legacyContent?: GroupPayload
|
||||
lastError?: string
|
||||
}
|
||||
|
||||
const initialState: TasksState = {
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [],
|
||||
}
|
||||
|
||||
export type TaskPayload = {
|
||||
id: string
|
||||
description: string
|
||||
completed?: boolean
|
||||
createdAt: Date
|
||||
updatedAt?: Date
|
||||
completedAt?: Date
|
||||
}
|
||||
|
||||
export type GroupPayload = {
|
||||
name: string
|
||||
collapsed?: boolean
|
||||
draft?: string
|
||||
lastActive?: Date
|
||||
tasks: TaskPayload[]
|
||||
}
|
||||
|
||||
const tasksSlice = createSlice({
|
||||
name: 'tasks',
|
||||
initialState,
|
||||
reducers: {
|
||||
taskAdded(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
task: { id: string; description: string }
|
||||
groupName: string
|
||||
}>
|
||||
) {
|
||||
const { groupName, task } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
delete group.draft
|
||||
group.tasks.unshift({
|
||||
...task,
|
||||
completed: false,
|
||||
createdAt: new Date(),
|
||||
})
|
||||
},
|
||||
taskModified(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
task: { id: string; description: string }
|
||||
groupName: string
|
||||
}>
|
||||
) {
|
||||
const { groupName, task } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
const currentTask = group.tasks.find((item) => item.id === task.id)
|
||||
if (!currentTask) {
|
||||
return
|
||||
}
|
||||
currentTask.description = task.description
|
||||
currentTask.updatedAt = new Date()
|
||||
},
|
||||
taskDeleted(
|
||||
state,
|
||||
action: PayloadAction<{ id: string; groupName: string }>
|
||||
) {
|
||||
const { id, groupName } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
group.tasks = group.tasks.filter((task) => task.id !== id)
|
||||
},
|
||||
taskToggled(
|
||||
state,
|
||||
action: PayloadAction<{ id: string; groupName: string }>
|
||||
) {
|
||||
const { id, groupName } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
const currentTask = group.tasks.find((task) => task.id === id)
|
||||
if (!currentTask) {
|
||||
return
|
||||
}
|
||||
currentTask.completed = !currentTask.completed
|
||||
currentTask.updatedAt = new Date()
|
||||
if (currentTask.completed) {
|
||||
currentTask.completedAt = new Date()
|
||||
} else {
|
||||
delete currentTask.completedAt
|
||||
}
|
||||
/**
|
||||
* Puts the recently toggled task on top
|
||||
*/
|
||||
const tasks = group.tasks.filter((task) => task.id !== id)
|
||||
group.tasks = [currentTask, ...tasks]
|
||||
},
|
||||
openAllCompleted(state, action: PayloadAction<{ groupName: string }>) {
|
||||
const { groupName } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
group.tasks.forEach((task) => {
|
||||
task.completed = false
|
||||
delete task.completedAt
|
||||
})
|
||||
},
|
||||
deleteAllCompleted(state, action: PayloadAction<{ groupName: string }>) {
|
||||
const { groupName } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
group.tasks = group.tasks.filter((task) => task.completed === false)
|
||||
},
|
||||
tasksReordered(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
swapTaskIndex: number
|
||||
withTaskIndex: number
|
||||
isSameSection: boolean
|
||||
}>
|
||||
) {
|
||||
const { groupName, swapTaskIndex, withTaskIndex, isSameSection } =
|
||||
action.payload
|
||||
if (!isSameSection) {
|
||||
return
|
||||
}
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
group.tasks = arrayMoveImmutable(
|
||||
group.tasks,
|
||||
swapTaskIndex,
|
||||
withTaskIndex
|
||||
)
|
||||
},
|
||||
tasksGroupAdded(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
}>
|
||||
) {
|
||||
const { groupName } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (group) {
|
||||
return
|
||||
}
|
||||
state.groups.push({
|
||||
name: groupName,
|
||||
tasks: [],
|
||||
})
|
||||
},
|
||||
tasksGroupReordered(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
swapGroupIndex: number
|
||||
withGroupIndex: number
|
||||
}>
|
||||
) {
|
||||
const { swapGroupIndex, withGroupIndex } = action.payload
|
||||
state.groups = arrayMoveImmutable(
|
||||
state.groups,
|
||||
swapGroupIndex,
|
||||
withGroupIndex
|
||||
)
|
||||
},
|
||||
tasksGroupDeleted(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
}>
|
||||
) {
|
||||
const { groupName } = action.payload
|
||||
state.groups = state.groups.filter((item) => item.name !== groupName)
|
||||
},
|
||||
tasksGroupMerged(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
mergeWith: string
|
||||
}>
|
||||
) {
|
||||
const { groupName, mergeWith } = action.payload
|
||||
if (groupName === mergeWith) {
|
||||
return
|
||||
}
|
||||
const groupA = state.groups.find((item) => item.name === groupName)
|
||||
if (!groupA) {
|
||||
return
|
||||
}
|
||||
const groupB = state.groups.find((item) => item.name === mergeWith)
|
||||
if (!groupB) {
|
||||
return
|
||||
}
|
||||
groupA.name = mergeWith
|
||||
groupA.tasks = [...(groupB.tasks ?? []), ...groupA.tasks]
|
||||
state.groups = state.groups.filter((group) => group !== groupB)
|
||||
},
|
||||
tasksGroupRenamed(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
newName: string
|
||||
}>
|
||||
) {
|
||||
const { groupName, newName } = action.payload
|
||||
if (groupName === newName) {
|
||||
return
|
||||
}
|
||||
const groupA = state.groups.find((item) => item.name === groupName)
|
||||
if (!groupA) {
|
||||
return
|
||||
}
|
||||
groupA.name = newName
|
||||
},
|
||||
tasksGroupCollapsed(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
collapsed: boolean
|
||||
}>
|
||||
) {
|
||||
const { groupName, collapsed } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
group.collapsed = collapsed
|
||||
},
|
||||
tasksGroupDraft(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
draft: string
|
||||
}>
|
||||
) {
|
||||
const { groupName, draft } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
group.draft = draft
|
||||
},
|
||||
tasksGroupLastActive(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
}>
|
||||
) {
|
||||
const { groupName } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
group.lastActive = new Date()
|
||||
},
|
||||
tasksLegacyContentMigrated(
|
||||
state,
|
||||
{ payload }: PayloadAction<{ continue: boolean }>
|
||||
) {
|
||||
if (!state.legacyContent) {
|
||||
return
|
||||
}
|
||||
|
||||
if (payload.continue) {
|
||||
state.initialized = true
|
||||
state.groups.push(state.legacyContent)
|
||||
delete state.lastError
|
||||
} else {
|
||||
state.initialized = false
|
||||
state.groups = []
|
||||
state.lastError =
|
||||
'The legacy content migration has been canceled by the user. ' +
|
||||
'Please reload this note to try again or switch to the Basic Checklist editor.'
|
||||
}
|
||||
|
||||
delete state.legacyContent
|
||||
},
|
||||
tasksLoaded(state, { payload }: PayloadAction<string>) {
|
||||
if (!payload && !state.initialized) {
|
||||
payload = '{}'
|
||||
}
|
||||
|
||||
try {
|
||||
const isJson = isJsonString(payload)
|
||||
if (!isJson) {
|
||||
const legacyContent = parseMarkdownTasks(payload)
|
||||
if (legacyContent) {
|
||||
state.legacyContent = legacyContent
|
||||
state.initialized = false
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const parsedState = JSON.parse(payload) as TasksState
|
||||
const newState: TasksState = {
|
||||
schemaVersion: parsedState.schemaVersion ?? '1.0.0',
|
||||
groups: parsedState.groups ?? [],
|
||||
}
|
||||
|
||||
if (newState !== initialState) {
|
||||
state.schemaVersion = newState.schemaVersion
|
||||
state.groups = newState.groups
|
||||
state.initialized = true
|
||||
delete state.lastError
|
||||
}
|
||||
} catch (error: any) {
|
||||
state.initialized = false
|
||||
state.lastError = `An error has occurred while parsing the note's content: ${error}`
|
||||
return
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export const {
|
||||
taskAdded,
|
||||
taskModified,
|
||||
taskToggled,
|
||||
taskDeleted,
|
||||
openAllCompleted,
|
||||
deleteAllCompleted,
|
||||
tasksLoaded,
|
||||
tasksLegacyContentMigrated,
|
||||
tasksGroupAdded,
|
||||
tasksReordered,
|
||||
tasksGroupReordered,
|
||||
tasksGroupDeleted,
|
||||
tasksGroupMerged,
|
||||
tasksGroupRenamed,
|
||||
tasksGroupCollapsed,
|
||||
tasksGroupDraft,
|
||||
tasksGroupLastActive,
|
||||
} = tasksSlice.actions
|
||||
export default tasksSlice.reducer
|
||||
@@ -0,0 +1,190 @@
|
||||
import './stylesheets/main.scss'
|
||||
|
||||
import React, { useCallback, useEffect, useRef } from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import { renderToString } from 'react-dom/server'
|
||||
import { Provider } from 'react-redux'
|
||||
import EditorKit, { EditorKitDelegate } from '@standardnotes/editor-kit'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import { store } from './app/store'
|
||||
import { useAppDispatch, useAppSelector } from './app/hooks'
|
||||
import CreateGroup from './features/tasks/CreateGroup'
|
||||
import {
|
||||
setCanEdit,
|
||||
setIsRunningOnMobile,
|
||||
setSpellCheckerEnabled,
|
||||
} from './features/settings/settings-slice'
|
||||
import { tasksLoaded } from './features/tasks/tasks-slice'
|
||||
import InvalidContentError from './features/tasks/InvalidContentError'
|
||||
import MigrateLegacyContent from './features/tasks/MigrateLegacyContent'
|
||||
import NotePreview from './features/tasks/NotePreview'
|
||||
import TaskGroupList from './features/tasks/TaskGroupList'
|
||||
|
||||
import { getPlainPreview } from './common/utils'
|
||||
import { CheckBoxElementsDefs } from './common/components/svg'
|
||||
|
||||
const MainContainer = styled.div`
|
||||
margin: 16px;
|
||||
padding-bottom: 60px;
|
||||
`
|
||||
|
||||
const FloatingContainer = styled.div`
|
||||
background-color: var(--sn-stylekit-secondary-background-color);
|
||||
border-top: 1px solid var(--sn-stylekit-border-color);
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
`
|
||||
|
||||
const CenteredContainer = styled.div`
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 0px;
|
||||
padding: 12px 16px;
|
||||
position: relative;
|
||||
width: 98%;
|
||||
`
|
||||
|
||||
const TaskEditor: React.FC = () => {
|
||||
const note = useRef<any>()
|
||||
const editorKit = useRef<EditorKit>()
|
||||
|
||||
const initialized = useAppSelector((state) => state.tasks.initialized)
|
||||
const groupedTasks = useAppSelector((state) => state.tasks.groups)
|
||||
const legacyContent = useAppSelector((state) => state.tasks.legacyContent)
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
function isRunningOnMobile(): boolean {
|
||||
return editorKit.current!.isRunningInMobileApplication()
|
||||
}
|
||||
|
||||
const configureEditorKit = useCallback(() => {
|
||||
const editorKitDelegate: EditorKitDelegate = {
|
||||
setEditorRawText: (rawString: string) => {
|
||||
dispatch(tasksLoaded(rawString))
|
||||
},
|
||||
onNoteValueChange: async (currentNote: any) => {
|
||||
note.current = currentNote
|
||||
|
||||
const editable =
|
||||
!currentNote.content.appData['org.standardnotes.sn'].locked ?? true
|
||||
const spellCheckEnabled = currentNote.content.spellcheck
|
||||
|
||||
dispatch(setCanEdit(editable))
|
||||
dispatch(setSpellCheckerEnabled(spellCheckEnabled))
|
||||
dispatch(setIsRunningOnMobile(isRunningOnMobile()))
|
||||
},
|
||||
onNoteLockToggle: (locked: boolean) => {
|
||||
dispatch(setCanEdit(!locked))
|
||||
},
|
||||
}
|
||||
|
||||
editorKit.current = new EditorKit(editorKitDelegate, {
|
||||
mode: 'json',
|
||||
supportsFileSafe: false,
|
||||
})
|
||||
}, [dispatch])
|
||||
|
||||
useEffect(() => {
|
||||
configureEditorKit()
|
||||
}, [configureEditorKit])
|
||||
|
||||
const saveNote = useCallback(() => {
|
||||
const { initialized } = store.getState().tasks
|
||||
const currentNote = note.current
|
||||
if (!currentNote || !initialized) {
|
||||
return
|
||||
}
|
||||
|
||||
const canEdit = store.getState().settings.canEdit
|
||||
if (!canEdit) {
|
||||
return
|
||||
}
|
||||
|
||||
editorKit.current!.saveItemWithPresave(currentNote, () => {
|
||||
const { schemaVersion, groups } = store.getState().tasks
|
||||
currentNote.content.text = JSON.stringify(
|
||||
{ schemaVersion, groups },
|
||||
null,
|
||||
2
|
||||
)
|
||||
|
||||
currentNote.content.preview_plain = getPlainPreview(groups)
|
||||
currentNote.content.preview_html = renderToString(
|
||||
<NotePreview groupedTasks={groups} />
|
||||
)
|
||||
})
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = store.subscribe(() => initialized && saveNote())
|
||||
return unsubscribe
|
||||
})
|
||||
|
||||
/**
|
||||
* Prevents dragging and dropping files
|
||||
*/
|
||||
useEffect(() => {
|
||||
function rejectDragAndDrop(event: DragEvent) {
|
||||
event && event.preventDefault()
|
||||
}
|
||||
|
||||
window.addEventListener('drop', rejectDragAndDrop)
|
||||
window.addEventListener('dragover', rejectDragAndDrop)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('drop', rejectDragAndDrop)
|
||||
window.removeEventListener('dragover', rejectDragAndDrop)
|
||||
}
|
||||
}, [])
|
||||
|
||||
if (legacyContent) {
|
||||
return (
|
||||
<MainContainer>
|
||||
<MigrateLegacyContent />
|
||||
</MainContainer>
|
||||
)
|
||||
}
|
||||
|
||||
if (!initialized) {
|
||||
return (
|
||||
<MainContainer>
|
||||
<InvalidContentError />
|
||||
</MainContainer>
|
||||
)
|
||||
}
|
||||
|
||||
if (groupedTasks.length === 0) {
|
||||
return (
|
||||
<MainContainer>
|
||||
<CreateGroup />
|
||||
</MainContainer>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<CheckBoxElementsDefs />
|
||||
<MainContainer>
|
||||
<TaskGroupList />
|
||||
</MainContainer>
|
||||
<FloatingContainer>
|
||||
<CenteredContainer>
|
||||
<CreateGroup />
|
||||
</CenteredContainer>
|
||||
</FloatingContainer>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<Provider store={store}>
|
||||
<TaskEditor />
|
||||
</Provider>
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
)
|
||||
1
packages/components/src/org.standardnotes.advanced-checklist/src/react-app-env.d.ts
vendored
Normal file
1
packages/components/src/org.standardnotes.advanced-checklist/src/react-app-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="react-scripts" />
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user