├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── api ├── add.go ├── api.go ├── done.go ├── list.go ├── remove.go ├── server.go ├── types.go └── update.go ├── client ├── .gitignore ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt ├── src │ ├── App.test.tsx │ ├── App.tsx │ ├── api │ │ ├── API.ts │ │ ├── HttpClient.ts │ │ └── types.ts │ ├── base.css │ ├── components │ │ ├── AddTask │ │ │ └── index.tsx │ │ ├── Overview │ │ │ └── index.tsx │ │ └── TaskItem │ │ │ ├── actions.tsx │ │ │ ├── index.test.tsx │ │ │ ├── index.tsx │ │ │ └── styles.module.sass │ ├── index.tsx │ ├── logo.svg │ ├── react-app-env.d.ts │ ├── setupTests.ts │ └── styles.module.sass ├── tsconfig.json └── yarn.lock ├── cmd └── root.go ├── go.mod ├── go.sum └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore vscode folder 2 | .vscode 3 | 4 | # ignore output build dir 5 | dist -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [2021] [Martin Eskdale Moen] [martin@martinmoen.com] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all build 2 | 3 | all: build 4 | 5 | deps: 6 | go get github.com/GeertJohan/go.rice/rice 7 | 8 | debug: 9 | go run . & yarn --cwd client run start 10 | 11 | build: 12 | cd client && yarn install && yarn build 13 | rice embed-go 14 | GOOS=linux CGO_ENABLED=0 go build -a -ldflags="-s -w" -o dist/dstask-gui . 15 | (type upx && upx dist/dstask-gui) || { echo "Missing upx, can't make smaller bin :("; } 16 | rice clean -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dstask-gui (placeholder) 2 | 3 | The name of this project is a placeholder, suggestions are more than welcome. 4 | 5 | ## What 6 | 7 | This is a HTTP API layer and Web frontend on top of [dstask](https://github.com/naggie/dstask/). It's born out of a need to manage my tasks when I'm using my phone. 8 | 9 | It does this by using dstask as a library and doesn't simply `exec` out to dstask. 10 | 11 | It's very early days still and expect bugs (possibly destroying your entire task history) 12 | 13 | ## Todo 14 | 15 | - [ ] Complete basic CRUD API 16 | - [ ] Priorities (filter and add to task) 17 | - [ ] Templates (add to task and show templates) 18 | - [ ] Tags (filter and add to task) 19 | - [ ] Contexts (filter and add to task) 20 | - [ ] Project (filter and add to task) 21 | - [ ] State (filter and set on task) 22 | - [ ] Add redux toolkit slices 23 | - [ ] Add toaster for error notification 24 | 25 | ## Dev setup 26 | 27 | For development the app is broken in to 2 pieces 28 | 29 | - Frontend end client 30 | - Backend API server 31 | 32 | To run the frontend client you will need nodejs and yarn. 33 | Nodejs can either be installed through your OS package manager or using [nvm](https://github.com/nvm-sh/nvm) 34 | Yarn can be installed with npm once you have node in stalled `npm -g install yarn` 35 | 36 | To run the backend API you will need golang, this can be installed through your OS package manager. 37 | 38 | Once those two dependencies are installed you can use `make debug` or if you want to start them individually, look below. 39 | 40 | ### Frontend 41 | 42 | The frontend is a react based webapp that uses CRA as it's base, blueprint for component library and axios for API calls. 43 | 44 | To start the FE app: 45 | 46 | ```shell 47 | cd client 48 | yarn 49 | yarn run start 50 | ``` 51 | 52 | ### Backend 53 | 54 | The backend app is a simple go http api that has handlers to call dstask library function. 55 | 56 | At the moment the backend relies on a modified version of `dstask` that includes tweaks so that dstask behaves better when used as a lib. 57 | The advised way is to clone the modified version `git clone --branch lib-tweaks https://github.com/botto/dstask.git` and update the replace line in go mod to point to the correct path of the lib tweaks version. 58 | 59 | To start the BE API: 60 | 61 | ```shell 62 | go get 63 | go run . 64 | ``` 65 | -------------------------------------------------------------------------------- /api/add.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-gonic/gin" 7 | "github.com/naggie/dstask" 8 | ) 9 | 10 | func addTaskHandler(c *gin.Context) { 11 | var newTask dstask.Task 12 | 13 | // Unpack JSON data 14 | if err := c.BindJSON(&newTask); err != nil { 15 | c.JSON(http.StatusInternalServerError, gin.H{ 16 | "error": "failed to unpack task data", 17 | "detail": err, 18 | }) 19 | } 20 | 21 | ts, err := dstask.LoadTaskSet( 22 | dstaskConfig.Repo, 23 | dstaskConfig.IDsFile, 24 | false, 25 | ) 26 | if err != nil { 27 | c.JSON(http.StatusInternalServerError, gin.H{ 28 | "error": "failed to load task set", 29 | "detail": err, 30 | }) 31 | } 32 | 33 | newTask.WritePending = true 34 | newTask.Status = dstask.STATUS_PENDING 35 | task, err := ts.LoadTask(&newTask) 36 | if err != nil { 37 | c.JSON(http.StatusInternalServerError, gin.H{ 38 | "error": "failed to add task to taskset", 39 | "detail": err.Error(), 40 | }) 41 | return 42 | } 43 | ts.SavePendingChanges() 44 | dstask.GitCommit(dstaskConfig.Repo, "Added %s", task) 45 | c.JSON(http.StatusNoContent, gin.H{}) 46 | } 47 | -------------------------------------------------------------------------------- /api/api.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "net/http" 5 | 6 | rice "github.com/GeertJohan/go.rice" 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | // Routes all the gin routes 11 | func apiRoutes(router *gin.Engine) { 12 | apiGroup := router.Group("/api/v1") 13 | box, err := rice.FindBox("client/build") 14 | 15 | if err == nil { 16 | // Serve frontend static files 17 | router.StaticFS("/client", box.HTTPBox()) 18 | 19 | router.GET("/", func(c *gin.Context) { 20 | c.Redirect(http.StatusPermanentRedirect, "/client") 21 | }) 22 | } 23 | 24 | apiGroup.GET("/", getTasksHandler) 25 | apiGroup.POST("/", addTaskHandler) 26 | apiGroup.DELETE("/:id", removeTaskHandler) 27 | apiGroup.POST("/:id/done", doneTaskHandler) 28 | apiGroup.POST("/:id", updateTaskHandler) 29 | } 30 | -------------------------------------------------------------------------------- /api/done.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "net/http" 5 | "strconv" 6 | "time" 7 | 8 | "github.com/gin-gonic/gin" 9 | "github.com/naggie/dstask" 10 | ) 11 | 12 | func doneTaskHandler(c *gin.Context) { 13 | idString := c.Param("id") 14 | id, err := strconv.Atoi(idString) 15 | 16 | if err != nil { 17 | c.JSON(http.StatusInternalServerError, gin.H{ 18 | "error": "failed to parse id", 19 | "defail": err, 20 | }) 21 | } 22 | 23 | // Get the taskset 24 | ts, err := dstask.LoadTaskSet( 25 | dstaskConfig.Repo, 26 | dstaskConfig.IDsFile, 27 | false, 28 | ) 29 | if err != nil { 30 | c.JSON(http.StatusInternalServerError, gin.H{ 31 | "error": "failed to load task set", 32 | "detail": err, 33 | }) 34 | } 35 | 36 | // Get task from set by ID 37 | task, err := ts.GetByID(id) 38 | if err != nil { 39 | c.JSON(http.StatusInternalServerError, gin.H{ 40 | "error": "failed to load task", 41 | "detail": err, 42 | }) 43 | return 44 | } 45 | 46 | // Mark task as done 47 | task.Status = dstask.STATUS_RESOLVED 48 | task.Resolved = time.Now() 49 | 50 | ts.UpdateTask(*task) 51 | // TODO: Fix this so we don't have exit fails futher down the tree 52 | ts.SavePendingChanges() 53 | 54 | dstask.GitCommit(dstaskConfig.Repo, "Resolved: %s", task) 55 | c.Status(204) 56 | } 57 | -------------------------------------------------------------------------------- /api/list.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-gonic/gin" 7 | "github.com/naggie/dstask" 8 | ) 9 | 10 | func getTasksHandler(c *gin.Context) { 11 | ts, err := dstask.LoadTaskSet( 12 | dstaskConfig.Repo, 13 | dstaskConfig.IDsFile, 14 | false, 15 | ) 16 | 17 | if err != nil { 18 | c.JSON(http.StatusInternalServerError, gin.H{ 19 | "error": "failed to get tasklist", 20 | "detail": err, 21 | }) 22 | return 23 | } 24 | unfilteredTasks := ts.Tasks() 25 | c.JSON(200, unfilteredTasks) 26 | } 27 | -------------------------------------------------------------------------------- /api/remove.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "net/http" 5 | "strconv" 6 | 7 | "github.com/gin-gonic/gin" 8 | "github.com/naggie/dstask" 9 | ) 10 | 11 | func removeTaskHandler(c *gin.Context) { 12 | idString := c.Param("id") 13 | id, err := strconv.Atoi(idString) 14 | 15 | if err != nil { 16 | c.JSON(http.StatusInternalServerError, gin.H{ 17 | "error": "failed to parse id", 18 | "defail": err, 19 | }) 20 | } 21 | 22 | // Get the taskset 23 | ts, err := dstask.LoadTaskSet( 24 | dstaskConfig.Repo, 25 | dstaskConfig.IDsFile, 26 | false, 27 | ) 28 | if err != nil { 29 | c.JSON(http.StatusInternalServerError, gin.H{ 30 | "error": "failed to load task set", 31 | "detail": err, 32 | }) 33 | } 34 | 35 | // Get task from set by ID 36 | task, err := ts.GetByID(id) 37 | if err != nil { 38 | c.JSON(http.StatusInternalServerError, gin.H{ 39 | "error": "failed to load task", 40 | "detail": err, 41 | }) 42 | return 43 | } 44 | 45 | // Mark task as deleted 46 | task.Deleted = true 47 | 48 | ts.UpdateTask(*task) 49 | // TODO: Fix this so we don't have exit fails futher down the tree 50 | ts.SavePendingChanges() 51 | 52 | dstask.GitCommit(dstaskConfig.Repo, "Removed: %s", task) 53 | c.Status(204) 54 | } 55 | -------------------------------------------------------------------------------- /api/server.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/http" 7 | "os" 8 | "os/signal" 9 | "strings" 10 | 11 | "github.com/gin-gonic/gin" 12 | "github.com/naggie/dstask" 13 | "github.com/spf13/viper" 14 | ) 15 | 16 | var router = gin.Default() 17 | var dstaskConfig = &dstask.Config{} 18 | var state dstask.State 19 | 20 | // Start launches the HTTP server. This method will not return until the server 21 | // is shutdown. 22 | func Start(configIn dstask.Config) { 23 | port := viper.GetString("port") 24 | env := viper.GetString("env") 25 | 26 | gin.SetMode(env) 27 | 28 | dstaskConfig = &configIn 29 | // Load state for getting and setting ctx 30 | state = dstask.LoadState(dstaskConfig.StateFile) 31 | 32 | listenString := fmt.Sprintf(":%v", port) 33 | 34 | addCORSHandler() 35 | add404Handler() 36 | 37 | apiRoutes(router) 38 | 39 | listenAndServe(listenString) 40 | } 41 | 42 | // Add CORS header handling 43 | func addCORSHandler() { 44 | router.Use(func(c *gin.Context) { 45 | c.Writer.Header().Set("Access-Control-Allow-Origin", "*") 46 | c.Writer.Header().Set("Access-Control-Allow-Credentials", "true") 47 | c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With") 48 | c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT") 49 | 50 | if c.Request.Method == "OPTIONS" { 51 | c.AbortWithStatus(204) 52 | return 53 | } 54 | 55 | c.Next() 56 | }) 57 | } 58 | 59 | // Add 404 handler for unknown routes 60 | func add404Handler() { 61 | router.NoRoute(func(c *gin.Context) { 62 | path := c.Request.URL.Path 63 | if strings.HasPrefix(path, "/api") { 64 | c.JSON(404, map[string]interface{}{"Error": "API Endpoint not found"}) 65 | } else { 66 | c.String(404, "404 not found") 67 | } 68 | }) 69 | } 70 | 71 | // Start a HTTP listener and handle requests. Blocks until the server is stopped. 72 | func listenAndServe(listenString string) { 73 | srv := &http.Server{ 74 | Addr: listenString, 75 | Handler: router, 76 | } 77 | go func() { 78 | err := srv.ListenAndServe() 79 | if err != nil && err != http.ErrServerClosed { 80 | log.Fatalf("server error: %s\n", err) 81 | } 82 | }() 83 | 84 | log.Printf("waiting for incoming connections on: %s", listenString) 85 | 86 | quit := make(chan os.Signal) 87 | signal.Notify(quit, os.Interrupt) 88 | sig := <-quit 89 | log.Printf("shutting down: %+v\n", sig) 90 | } 91 | -------------------------------------------------------------------------------- /api/types.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | // Task is fields for a task 4 | type Task struct { 5 | Text string 6 | Tags []string 7 | Project string 8 | Priority string 9 | Note string 10 | } 11 | -------------------------------------------------------------------------------- /api/update.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "net/http" 5 | "strconv" 6 | 7 | "github.com/gin-gonic/gin" 8 | "github.com/naggie/dstask" 9 | ) 10 | 11 | func updateTaskHandler(c *gin.Context) { 12 | var postData dstask.Task 13 | idString := c.Param("id") 14 | id, err := strconv.Atoi(idString) 15 | 16 | if err != nil { 17 | c.JSON(http.StatusInternalServerError, gin.H{ 18 | "error": "failed to parse id", 19 | "defail": err.Error(), 20 | }) 21 | } 22 | 23 | // Unpack JSON data 24 | if err := c.BindJSON(&postData); err != nil { 25 | c.JSON(http.StatusInternalServerError, gin.H{ 26 | "error": "failed to unpack task data", 27 | "detail": err.Error(), 28 | }) 29 | } 30 | 31 | ts, err := dstask.LoadTaskSet( 32 | dstaskConfig.Repo, 33 | dstaskConfig.IDsFile, 34 | false, 35 | ) 36 | if err != nil { 37 | c.JSON(http.StatusInternalServerError, gin.H{ 38 | "error": "failed to load task set", 39 | "detail": err.Error(), 40 | }) 41 | } 42 | 43 | // Get task from set by ID 44 | task, err := ts.GetByID(id) 45 | if err != nil { 46 | c.JSON(http.StatusInternalServerError, gin.H{ 47 | "error": "failed to load task", 48 | "detail": err.Error(), 49 | }) 50 | return 51 | } 52 | 53 | task.Summary = postData.Summary 54 | 55 | ts.UpdateTask(*task) 56 | // TODO: Fix this so we don't have exit fails futher down the tree 57 | ts.SavePendingChanges() 58 | 59 | dstask.GitCommit(dstaskConfig.Repo, "Modified: %s", task) 60 | c.Status(204) 61 | } 62 | -------------------------------------------------------------------------------- /client/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dstask-gui", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@blueprintjs/core": "^3.38.2", 7 | "@testing-library/jest-dom": "^5.11.4", 8 | "@testing-library/react": "^11.1.0", 9 | "@testing-library/user-event": "^12.1.10", 10 | "@types/jest": "^26.0.15", 11 | "@types/node": "^12.0.0", 12 | "@types/react": "^17.0.0", 13 | "@types/react-dom": "^17.0.0", 14 | "axios": "^0.21.1", 15 | "node-sass": "^5.0.0", 16 | "react": "^17.0.1", 17 | "react-dom": "^17.0.1", 18 | "react-query": "^3.8.2", 19 | "react-scripts": "4.0.2", 20 | "typescript": "^4.1.2", 21 | "web-vitals": "^1.0.1" 22 | }, 23 | "scripts": { 24 | "start": "react-scripts start", 25 | "build": "react-scripts build", 26 | "test": "react-scripts test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": [ 31 | "react-app", 32 | "react-app/jest" 33 | ] 34 | }, 35 | "browserslist": { 36 | "production": [ 37 | ">0.2%", 38 | "not dead", 39 | "not op_mini all" 40 | ], 41 | "development": [ 42 | "last 1 chrome version", 43 | "last 1 firefox version", 44 | "last 1 safari version" 45 | ] 46 | }, 47 | "homepage": "/client", 48 | "proxy": "http://127.0.0.1:20090" 49 | } 50 | -------------------------------------------------------------------------------- /client/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/botto/dstask-gui/de6662108e00120c914da2f6c6176315eee402b0/client/public/favicon.ico -------------------------------------------------------------------------------- /client/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | dstask 15 | 16 | 17 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /client/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/botto/dstask-gui/de6662108e00120c914da2f6c6176315eee402b0/client/public/logo192.png -------------------------------------------------------------------------------- /client/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/botto/dstask-gui/de6662108e00120c914da2f6c6176315eee402b0/client/public/logo512.png -------------------------------------------------------------------------------- /client/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "dstask", 3 | "name": "dead simple tasks", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /client/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /client/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import React from 'react'; 3 | import App from './App'; 4 | 5 | describe('app landing page', () => { 6 | test('renders overview component', () => { 7 | render(); 8 | const overviewElement = screen.getByTestId('overview'); 9 | expect(overviewElement).toBeInTheDocument(); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /client/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { Colors } from '@blueprintjs/core'; 2 | import { QueryClient, QueryClientProvider } from "react-query"; 3 | import './base.css'; 4 | // Load custom comps after blueprint css. 5 | import Overview from './components/Overview'; 6 | import styles from './styles.module.sass'; 7 | 8 | const queryClient = new QueryClient() 9 | 10 | const App = () => ( 11 | 12 |
13 |
14 | 15 |
16 |
17 |
18 | ); 19 | 20 | export default App; 21 | -------------------------------------------------------------------------------- /client/src/api/API.ts: -------------------------------------------------------------------------------- 1 | import HttpClient from './HttpClient'; 2 | import { Task } from './types'; 3 | 4 | class API extends HttpClient { 5 | public constructor() { 6 | super(process.env.REACT_APP_API_BASE_URL); 7 | } 8 | 9 | public getTasks = () => this.instance.get('/'); 10 | public removeTask = (id: number) => this.instance.delete(`/${id}`); 11 | public updateTask = (id: number, task: Task) => this.instance.post(`/${id}`, task); 12 | 13 | // Post endpoint 14 | public newTask = (task: Task) => this.instance.post('/', task); 15 | public doneTask = (id: number) => this.instance.post(`/${id}/done`); 16 | } 17 | 18 | export const api = new API(); 19 | -------------------------------------------------------------------------------- /client/src/api/HttpClient.ts: -------------------------------------------------------------------------------- 1 | import axios, { AxiosInstance, AxiosResponse } from 'axios'; 2 | 3 | declare module 'axios' { 4 | interface AxiosResponse extends Promise {} 5 | } 6 | export default abstract class HttpClient { 7 | protected readonly instance: AxiosInstance; 8 | 9 | public constructor(apiURL?: string) { 10 | const baseURL = apiURL ? apiURL : `${window.location.origin}/api/v1`; 11 | this.instance = axios.create({ 12 | baseURL, 13 | }); 14 | 15 | this._initializeResponseInterceptor(); 16 | } 17 | 18 | private _initializeResponseInterceptor = () => { 19 | this.instance.interceptors.response.use( 20 | this._handleResponse, 21 | this._handleError, 22 | ); 23 | }; 24 | 25 | private _handleResponse = ({ data }: AxiosResponse) => data; 26 | 27 | protected _handleError = (error: any) => Promise.reject(error); 28 | } -------------------------------------------------------------------------------- /client/src/api/types.ts: -------------------------------------------------------------------------------- 1 | export class Task { 2 | readonly tags: string[] = [] 3 | readonly project: string = '' 4 | readonly priority: string = '' 5 | readonly note: string = '' 6 | readonly summary: string 7 | readonly id: number = NaN 8 | 9 | constructor(summary: string) { 10 | this.summary = summary 11 | } 12 | } -------------------------------------------------------------------------------- /client/src/base.css: -------------------------------------------------------------------------------- 1 | @import "~normalize.css"; 2 | @import "~@blueprintjs/core/lib/css/blueprint.css"; 3 | @import "~@blueprintjs/icons/lib/css/blueprint-icons.css"; 4 | 5 | html, body, #root { 6 | height: 100%; 7 | } 8 | -------------------------------------------------------------------------------- /client/src/components/AddTask/index.tsx: -------------------------------------------------------------------------------- 1 | import { Button, InputGroup, Intent } from '@blueprintjs/core'; 2 | import React, { useRef, useState } from 'react'; 3 | import { useMutation } from "react-query"; 4 | import { api } from '../../api/API'; 5 | import { Task } from '../../api/types'; 6 | 7 | 8 | const AddTask = (props: { onAdd: () => void }) => { 9 | const newTaskInput = useRef(null); 10 | const [ showAdd, setShowAdd ] = useState(false); 11 | 12 | const mutation = useMutation( 13 | async (task:Task) => await api.newTask(task), 14 | { 15 | onError: (error) => window.alert(error.message), 16 | onSuccess: () => { 17 | if (newTaskInput.current?.value === undefined) { 18 | return 19 | } 20 | newTaskInput.current.value = ''; 21 | props.onAdd(); 22 | }, 23 | } 24 | ); 25 | 26 | const doAdd = async () => { 27 | if (newTaskInput.current) { 28 | const task = new Task(newTaskInput.current?.value!); 29 | mutation.mutate(task) 30 | } 31 | }; 32 | 33 | const onKeyPress = (e: React.KeyboardEvent) => { 34 | if (e.code === 'Enter') { 35 | doAdd(); 36 | } 37 | } 38 | 39 | const onChange = () => { 40 | if (newTaskInput.current) { 41 | setShowAdd(newTaskInput.current.value.trim().length > 0); 42 | } 43 | }; 44 | 45 | const AddBtn = () => (showAdd ?