├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── db.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── algorithms │ └── graph │ │ ├── Dijkstra.ts │ │ ├── Edge.ts │ │ ├── Graph.ts │ │ ├── PriorityQueue.ts │ │ ├── Utils.ts │ │ ├── Vertex.ts │ │ └── __tests__ │ │ ├── Dijkstra.test.ts │ │ ├── Edge.test.ts │ │ ├── Graph.test.ts │ │ ├── PriorityQueue.test.ts │ │ ├── Utils.test.ts │ │ └── Vertex.test.ts ├── components │ ├── App │ │ ├── App.module.scss │ │ ├── App.tsx │ │ ├── __tests__ │ │ │ └── App.test.tsx │ │ └── index.tsx │ ├── FloorMapSvg │ │ ├── FloorMapSvg.module.scss │ │ ├── FloorMapSvg.tsx │ │ ├── __tests__ │ │ │ └── FloorMapSvg.test.tsx │ │ └── index.ts │ ├── Main │ │ ├── Main.module.scss │ │ ├── Main.tsx │ │ ├── __tests__ │ │ │ └── Main.test.tsx │ │ └── index.ts │ ├── Map │ │ ├── Map.module.scss │ │ ├── Map.tsx │ │ ├── __tests__ │ │ │ └── Map.test.tsx │ │ ├── index.ts │ │ └── mapData.ts │ ├── Modals │ │ ├── ModalObjectInfo │ │ │ ├── ModalObjectInfo.module.scss │ │ │ ├── ModalObjectInfo.tsx │ │ │ ├── __tests__ │ │ │ │ └── ModalObjectInfo.test.tsx │ │ │ └── index.ts │ │ ├── ModalSettings │ │ │ ├── ModalSettings.module.scss │ │ │ ├── ModalSettings.tsx │ │ │ ├── __tests__ │ │ │ │ └── ModalSettings.test.tsx │ │ │ └── index.ts │ │ └── modalTypes.ts │ └── Sidebar │ │ ├── Sidebar.module.scss │ │ ├── Sidebar.tsx │ │ ├── __tests__ │ │ └── Sidebar.test.tsx │ │ └── index.ts ├── containers │ └── Layout │ │ ├── Layout.module.scss │ │ ├── Layout.tsx │ │ ├── __tests__ │ │ └── Layout.test.tsx │ │ └── index.ts ├── index.tsx ├── react-app-env.d.ts ├── store │ ├── actions.ts │ ├── api │ │ ├── actions.ts │ │ ├── api.ts │ │ ├── constants.ts │ │ ├── db.ts │ │ ├── reducer.ts │ │ └── sagas.ts │ ├── graph │ │ ├── actions.ts │ │ ├── constants.ts │ │ ├── reducer.ts │ │ └── sagas.ts │ ├── index.ts │ ├── modals │ │ ├── actions.ts │ │ ├── constants.ts │ │ └── reducer.ts │ ├── path │ │ ├── actions.ts │ │ ├── constants.ts │ │ ├── reducer.ts │ │ └── sagas.ts │ ├── rootReducer.ts │ ├── rootSaga.ts │ ├── search │ │ ├── actions.ts │ │ ├── api.ts │ │ ├── constants.ts │ │ ├── reducer.ts │ │ └── sagas.ts │ ├── settings │ │ ├── actions.ts │ │ ├── constants.ts │ │ └── reducer.ts │ └── sidebar │ │ ├── actions.ts │ │ ├── constants.ts │ │ └── reducer.ts ├── styles │ ├── index.scss │ ├── themes.scss │ └── variables.scss └── utils │ ├── __tests__ │ ├── helpers.test.ts │ └── initLocalStorage.test.ts │ ├── helpers.ts │ ├── i18n │ ├── index.ts │ └── translations │ │ ├── en.json │ │ └── pl.json │ ├── initLocalStorage.ts │ ├── serviceWorker.ts │ └── setupTests.ts ├── tsconfig.json └── yarn.lock /.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 | 25 | /.vscode 26 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "always", 3 | "bracketSpacing": true, 4 | "endOfLine": "crlf", 5 | "htmlWhitespaceSensitivity": "css", 6 | "insertPragma": false, 7 | "jsxBracketSameLine": false, 8 | "jsxSingleQuote": false, 9 | "printWidth": 80, 10 | "proseWrap": "preserve", 11 | "quoteProps": "as-needed", 12 | "requirePragma": false, 13 | "semi": true, 14 | "singleQuote": false, 15 | "tabWidth": 2, 16 | "breakBeforeElse": true, 17 | "trailingComma": "es5", 18 | "useTabs": false, 19 | "vueIndentScriptAndStyle": false 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pathfinding - Interactive SVG Map 2 | [![Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.](https://www.repostatus.org/badges/latest/inactive.svg)](https://www.repostatus.org/#inactive) 3 | 4 | My goal of this project was to implement from scratch Graph data structure and Dijkstra algorithm in Typescript. 5 | 6 | To visualize how it's working, you can find shortest path on map of shop to product you're searching for from different starting points. 7 | 8 | Online version: https://pathfinding-app.vercel.app 9 | 10 | Technology stack: `React` `Typescript` 11 | 12 | ## Getting started 13 | 14 | Download this repo: 15 | 16 | ``` 17 | git clone https://github.com/maciejb2k/wayfinding-js.git 18 | ``` 19 | 20 | Install and run, this command will run in parallel dev server and json-server: 21 | 22 | Using NPM: 23 | 24 | ``` 25 | npm install 26 | npm run start 27 | ``` 28 | 29 | Using Yarn: 30 | 31 | ``` 32 | yarn install 33 | yarn start 34 | ``` 35 | 36 | ## Design 37 | 38 | Below I've made concept UI of how it's going to looks like. 39 | 40 | ![preview](https://user-images.githubusercontent.com/6316812/98004910-c3d7fa00-1df0-11eb-8810-b1fb6179c1af.png) 41 | 42 | ![preview](https://user-images.githubusercontent.com/6316812/90241083-a5361880-de2a-11ea-843b-d3b08a6e83ca.jpg) 43 | -------------------------------------------------------------------------------- /db.json: -------------------------------------------------------------------------------- 1 | { 2 | "categories": [ 3 | { 4 | "id": 1, 5 | "name": "alcohol" 6 | }, 7 | { 8 | "id": 2, 9 | "name": "bakery products" 10 | }, 11 | { 12 | "id": 3, 13 | "name": "groceries" 14 | }, 15 | { 16 | "id": 4, 17 | "name": "teas and coffees" 18 | }, 19 | { 20 | "id": 5, 21 | "name": "sweets" 22 | }, 23 | { 24 | "id": 6, 25 | "name": "mineral water" 26 | }, 27 | { 28 | "id": 7, 29 | "name": "beverages and juices" 30 | }, 31 | { 32 | "id": 8, 33 | "name": "meat and cold cuts" 34 | }, 35 | { 36 | "id": 9, 37 | "name": "cheeses" 38 | }, 39 | { 40 | "id": 10, 41 | "name": "frozen foods" 42 | }, 43 | { 44 | "id": 11, 45 | "name": "savoury snacks" 46 | }, 47 | { 48 | "id": 12, 49 | "name": "fishes" 50 | }, 51 | { 52 | "id": 13, 53 | "name": "honey and dried fruits" 54 | }, 55 | { 56 | "id": 14, 57 | "name": "eggs" 58 | }, 59 | { 60 | "id": 15, 61 | "name": "delicatessen" 62 | }, 63 | { 64 | "id": 16, 65 | "name": "spices" 66 | }, 67 | { 68 | "id": 17, 69 | "name": "preserves" 70 | }, 71 | { 72 | "id": 18, 73 | "name": "ready meals" 74 | }, 75 | { 76 | "id": 19, 77 | "name": "cleaning products" 78 | }, 79 | { 80 | "id": 20, 81 | "name": "animal world" 82 | }, 83 | { 84 | "id": 21, 85 | "name": "ice creams" 86 | }, 87 | { 88 | "id": 22, 89 | "name": "dairy products" 90 | }, 91 | { 92 | "id": 23, 93 | "name": "deals" 94 | }, 95 | { 96 | "id": 24, 97 | "name": "checkout" 98 | }, 99 | { 100 | "id": 25, 101 | "name": "fruits and vegetables" 102 | } 103 | ], 104 | "products": [ 105 | { 106 | "id":1, 107 | "name":"Guinness Draught", 108 | "desc":"-", 109 | "price":"2.50", 110 | "objectId":"o_5" 111 | }, 112 | { 113 | "id":2, 114 | "name":"Orange juice", 115 | "desc":"-", 116 | "price":"2.50", 117 | "objectId":"o_10" 118 | }, 119 | { 120 | "id":3, 121 | "name":"Milk", 122 | "desc":"-", 123 | "price":"2.50", 124 | "objectId":"o_8" 125 | }, 126 | { 127 | "id":4, 128 | "name":"Chocolate", 129 | "desc":"-", 130 | "price":"2.50", 131 | "objectId":"o_25" 132 | }, 133 | { 134 | "id":5, 135 | "name":"Salmon", 136 | "desc":"-", 137 | "price":"2.50", 138 | "objectId":"o_21" 139 | }, 140 | { 141 | "id":6, 142 | "name":"Pasta", 143 | "desc":"-", 144 | "price":"2.50", 145 | "objectId":"o_35" 146 | }, 147 | { 148 | "id":7, 149 | "name":"Eggs", 150 | "desc":"-", 151 | "price":"2.50", 152 | "objectId":"o_18" 153 | }, 154 | { 155 | "id":8, 156 | "name":"Heineken", 157 | "desc":"-", 158 | "price":"2.50", 159 | "objectId":"o_11" 160 | }, 161 | { 162 | "id":9, 163 | "name":"Corona Extra", 164 | "desc":"-", 165 | "price":"2.50", 166 | "objectId":"o_11" 167 | }, 168 | { 169 | "id":10, 170 | "name":"Punk IPA", 171 | "desc":"-", 172 | "price":"2.50", 173 | "objectId":"o_1" 174 | }, 175 | { 176 | "id":11, 177 | "name":"Bud Light", 178 | "desc":"-", 179 | "price":"2.50", 180 | "objectId":"o_5" 181 | }, 182 | { 183 | "id":12, 184 | "name":"Traditional Lager", 185 | "desc":"-", 186 | "price":"2.50", 187 | "objectId":"o_5" 188 | }, 189 | { 190 | "id":13, 191 | "name":"Lay's salted", 192 | "desc":"-", 193 | "price":"5.99", 194 | "objectId":"o_28" 195 | }, 196 | { 197 | "id":14, 198 | "name":"Pepper", 199 | "desc":"-", 200 | "price":"2.00", 201 | "objectId":"o_15" 202 | }, 203 | { 204 | "id":15, 205 | "name":"Pierogi", 206 | "desc":"True polish OG food", 207 | "price":"9.99", 208 | "objectId":"o_24" 209 | }, 210 | { 211 | "id":16, 212 | "name":"Instant soup", 213 | "desc":"-", 214 | "price":"2.50", 215 | "objectId":"o_14" 216 | }, 217 | { 218 | "id":17, 219 | "name":"Salt", 220 | "desc":"-", 221 | "price":"1.00", 222 | "objectId":"o_16" 223 | }, 224 | { 225 | "id":18, 226 | "name":"Coffee", 227 | "desc":"-", 228 | "price":"15.00", 229 | "objectId":"o_33" 230 | }, 231 | { 232 | "id":19, 233 | "name":"Black tea", 234 | "desc":"-", 235 | "price":"1.00", 236 | "objectId":"o_32" 237 | }, 238 | { 239 | "id":20, 240 | "name":"Green tea", 241 | "desc":"-", 242 | "price":"1.00", 243 | "objectId":"o_32" 244 | }, 245 | { 246 | "id":21, 247 | "name":"Tomatoes", 248 | "desc":"-", 249 | "price":"2.00", 250 | "objectId":"o_34" 251 | }, 252 | { 253 | "id":22, 254 | "name":"Bananas", 255 | "desc":"-", 256 | "price":"4.99", 257 | "objectId":"o_30" 258 | }, 259 | { 260 | "id":23, 261 | "name":"Apples", 262 | "desc":"-", 263 | "price":"3.99", 264 | "objectId":"o_30" 265 | }, 266 | { 267 | "id":24, 268 | "name":"Salty sticks", 269 | "desc":"-", 270 | "price":"3.99", 271 | "objectId":"o_28" 272 | }, 273 | { 274 | "id":25, 275 | "name":"Cream tubes", 276 | "desc":"-", 277 | "price":"4.50", 278 | "objectId":"o_26" 279 | }, 280 | { 281 | "id":26, 282 | "name":"Waffles", 283 | "desc":"-", 284 | "price":"4.50", 285 | "objectId":"o_27" 286 | }, 287 | { 288 | "id":27, 289 | "name":"American cookies", 290 | "desc":"-", 291 | "price":"4.39", 292 | "objectId":"o_25" 293 | }, 294 | { 295 | "id":28, 296 | "name":"Bread", 297 | "desc":"-", 298 | "price":"3.00", 299 | "objectId":"o_38" 300 | }, 301 | { 302 | "id":29, 303 | "name":"Roll", 304 | "desc":"-", 305 | "price":"3.29", 306 | "objectId":"o_43" 307 | }, 308 | { 309 | "id":30, 310 | "name":"Corn", 311 | "desc":"-", 312 | "price":"2.40", 313 | "objectId":"o_36" 314 | }, 315 | { 316 | "id":31, 317 | "name":"Tomato sauce", 318 | "desc":"-", 319 | "price":"5.19", 320 | "objectId":"o_37" 321 | }, 322 | { 323 | "id":32, 324 | "name":"Gouda cheese", 325 | "desc":"-", 326 | "price":"5.19", 327 | "objectId":"o_13" 328 | }, 329 | { 330 | "id":33, 331 | "name":"Blue cheese", 332 | "desc":"-", 333 | "price":"6.00", 334 | "objectId":"o_39" 335 | }, 336 | { 337 | "id":34, 338 | "name":"Ham", 339 | "desc":"-", 340 | "price":"5.00", 341 | "objectId":"o_42" 342 | }, 343 | { 344 | "id":35, 345 | "name":"Salami", 346 | "desc":"-", 347 | "price":"3.00", 348 | "objectId":"o_41" 349 | }, 350 | { 351 | "id":36, 352 | "name":"Peanuts", 353 | "desc":"-", 354 | "price":"6.00", 355 | "objectId":"o_22" 356 | }, 357 | { 358 | "id":37, 359 | "name":"Honey", 360 | "desc":"-", 361 | "price":"20.00", 362 | "objectId":"o_22" 363 | }, 364 | { 365 | "id":38, 366 | "name":"Jam", 367 | "desc":"-", 368 | "price":"7.00", 369 | "objectId":"o_23" 370 | }, 371 | { 372 | "id":39, 373 | "name":"Detergent", 374 | "desc":"-", 375 | "price":"25.00", 376 | "objectId":"o_31" 377 | }, 378 | { 379 | "id":40, 380 | "name":"karma dla psa", 381 | "desc":"-", 382 | "price":"30.00", 383 | "objectId":"o_29" 384 | }, 385 | { 386 | "id":41, 387 | "name":"Ice cream", 388 | "desc":"-", 389 | "price":"2.89", 390 | "objectId":"o_20" 391 | }, 392 | { 393 | "id":42, 394 | "name":"Frozen vegetables", 395 | "desc":"-", 396 | "price":"12.00", 397 | "objectId":"o_17" 398 | }, 399 | { 400 | "id":43, 401 | "name":"Candy box", 402 | "desc":"-", 403 | "price":"5.00", 404 | "objectId":"o_19" 405 | }, 406 | { 407 | "id":44, 408 | "name":"Natural yogurt", 409 | "desc":"-", 410 | "price":"3.00", 411 | "objectId":"o_7" 412 | }, 413 | { 414 | "id":45, 415 | "name":"Cottage cheese", 416 | "desc":"-", 417 | "price":"3.00", 418 | "objectId":"o_2" 419 | }, 420 | { 421 | "id":46, 422 | "name":"Sparkling water", 423 | "desc":"-", 424 | "price":"1.79", 425 | "objectId":"o_4" 426 | }, 427 | { 428 | "id":47, 429 | "name":"Mineral water", 430 | "desc":"-", 431 | "price":"2.79", 432 | "objectId":"o_9" 433 | }, 434 | { 435 | "id":48, 436 | "name":"Cola", 437 | "desc":"-", 438 | "price":"4.79", 439 | "objectId":"o_6" 440 | }, 441 | { 442 | "id":49, 443 | "name":"Orange soda", 444 | "desc":"-", 445 | "price":"4.79", 446 | "objectId":"o_3" 447 | }, 448 | { 449 | "id":50, 450 | "name":"Vodka", 451 | "desc":"-", 452 | "price":"25.00", 453 | "objectId":"o_12" 454 | }, 455 | { 456 | "id":51, 457 | "name":"Chewing gums", 458 | "desc":"-", 459 | "price":"3.00", 460 | "objectId":"o_40" 461 | } 462 | ], 463 | "object-to-category": [ 464 | { 465 | "id": 1, 466 | "categoryId": 1, 467 | "objectId": "o_1" 468 | }, 469 | { 470 | "id": 2, 471 | "categoryId": 22, 472 | "objectId": "o_2" 473 | }, 474 | { 475 | "id": 3, 476 | "categoryId": 7, 477 | "objectId": "o_3" 478 | }, 479 | { 480 | "id": 4, 481 | "categoryId": 6, 482 | "objectId": "o_4" 483 | }, 484 | { 485 | "id": 5, 486 | "categoryId": 1, 487 | "objectId": "o_5" 488 | }, 489 | { 490 | "id": 6, 491 | "categoryId": 7, 492 | "objectId": "o_6" 493 | }, 494 | { 495 | "id": 7, 496 | "categoryId": 22, 497 | "objectId": "o_7" 498 | }, 499 | { 500 | "id": 8, 501 | "categoryId": 22, 502 | "objectId": "o_8" 503 | }, 504 | { 505 | "id": 9, 506 | "categoryId": 6, 507 | "objectId": "o_9" 508 | }, 509 | { 510 | "id": 10, 511 | "categoryId": 7, 512 | "objectId": "o_10" 513 | }, 514 | { 515 | "id": 11, 516 | "categoryId": 1, 517 | "objectId": "o_11" 518 | }, 519 | { 520 | "id": 12, 521 | "categoryId": 1, 522 | "objectId": "o_12" 523 | }, 524 | { 525 | "id": 13, 526 | "categoryId": 9, 527 | "objectId": "o_13" 528 | }, 529 | { 530 | "id": 14, 531 | "categoryId": 18, 532 | "objectId": "o_14" 533 | }, 534 | { 535 | "id": 15, 536 | "categoryId": 16, 537 | "objectId": "o_15" 538 | }, 539 | { 540 | "id": 16, 541 | "categoryId": 16, 542 | "objectId": "o_16" 543 | }, 544 | { 545 | "id": 17, 546 | "categoryId": 10, 547 | "objectId": "o_17" 548 | }, 549 | { 550 | "id": 18, 551 | "categoryId": 14, 552 | "objectId": "o_18" 553 | }, 554 | { 555 | "id": 19, 556 | "categoryId": 23, 557 | "objectId": "o_19" 558 | }, 559 | { 560 | "id": 20, 561 | "categoryId": 21, 562 | "objectId": "o_20" 563 | }, 564 | { 565 | "id": 21, 566 | "categoryId": 12, 567 | "objectId": "o_21" 568 | }, 569 | { 570 | "id": 22, 571 | "categoryId": 13, 572 | "objectId": "o_22" 573 | }, 574 | { 575 | "id": 23, 576 | "categoryId": 17, 577 | "objectId": "o_23" 578 | }, 579 | { 580 | "id": 24, 581 | "categoryId": 15, 582 | "objectId": "o_24" 583 | }, 584 | { 585 | "id": 25, 586 | "categoryId": 5, 587 | "objectId": "o_25" 588 | }, 589 | { 590 | "id": 26, 591 | "categoryId": 5, 592 | "objectId": "o_26" 593 | }, 594 | { 595 | "id": 27, 596 | "categoryId": 5, 597 | "objectId": "o_27" 598 | }, 599 | { 600 | "id": 28, 601 | "categoryId": 11, 602 | "objectId": "o_28" 603 | }, 604 | { 605 | "id": 29, 606 | "categoryId": 20, 607 | "objectId": "o_29" 608 | }, 609 | { 610 | "id": 30, 611 | "categoryId": 25, 612 | "objectId": "o_30" 613 | }, 614 | { 615 | "id": 31, 616 | "categoryId": 19, 617 | "objectId": "o_31" 618 | }, 619 | { 620 | "id": 32, 621 | "categoryId": 4, 622 | "objectId": "o_32" 623 | }, 624 | { 625 | "id": 33, 626 | "categoryId": 4, 627 | "objectId": "o_33" 628 | }, 629 | { 630 | "id": 34, 631 | "categoryId": 25, 632 | "objectId": "o_34" 633 | }, 634 | { 635 | "id": 35, 636 | "categoryId": 3, 637 | "objectId": "o_35" 638 | }, 639 | { 640 | "id": 36, 641 | "categoryId": 3, 642 | "objectId": "o_36" 643 | }, 644 | { 645 | "id": 37, 646 | "categoryId": 3, 647 | "objectId": "o_37" 648 | }, 649 | { 650 | "id": 38, 651 | "categoryId": 2, 652 | "objectId": "o_38" 653 | }, 654 | { 655 | "id": 39, 656 | "categoryId": 9, 657 | "objectId": "o_39" 658 | }, 659 | { 660 | "id": 40, 661 | "categoryId": 24, 662 | "objectId": "o_40" 663 | }, 664 | { 665 | "id": 41, 666 | "categoryId": 8, 667 | "objectId": "o_41" 668 | }, 669 | { 670 | "id": 42, 671 | "categoryId": 8, 672 | "objectId": "o_42" 673 | }, 674 | { 675 | "id": 43, 676 | "categoryId": 2, 677 | "objectId": "o_43" 678 | } 679 | ] 680 | } 681 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wayfinding-app", 3 | "homepage": ".", 4 | "version": "0.1.0", 5 | "private": true, 6 | "dependencies": { 7 | "@testing-library/jest-dom": "^5.11.5", 8 | "@testing-library/react": "^9.3.2", 9 | "@testing-library/user-event": "^7.1.2", 10 | "@types/classnames": "^2.2.10", 11 | "@types/history": "^4.7.7", 12 | "@types/jest": "^24.0.0", 13 | "@types/node": "^12.0.0", 14 | "@types/react": "^16.9.0", 15 | "@types/react-dom": "^16.9.0", 16 | "@types/react-loader-spinner": "^3.1.0", 17 | "@types/react-modal": "^3.10.6", 18 | "@types/react-redux": "^7.1.9", 19 | "@types/react-world-flags": "^1.4.0", 20 | "@types/redux": "^3.6.0", 21 | "@types/redux-saga": "^0.10.5", 22 | "@types/webfontloader": "^1.6.32", 23 | "axios": "^0.20.0", 24 | "classnames": "^2.2.6", 25 | "concurrently": "^5.3.0", 26 | "final-form": "^4.20.1", 27 | "gsap": "^3.4.2", 28 | "history": "^5.0.0", 29 | "i18next": "^19.7.0", 30 | "json-server": "^0.16.1", 31 | "node-sass": "^4.14.1", 32 | "normalize.css": "^8.0.1", 33 | "react": "^16.13.1", 34 | "react-dom": "^16.13.1", 35 | "react-final-form": "^6.5.1", 36 | "react-i18next": "^11.7.1", 37 | "react-icons": "^3.11.0", 38 | "react-loader-spinner": "^3.1.14", 39 | "react-modal": "^3.11.2", 40 | "react-redux": "^7.2.1", 41 | "react-responsive-pinch-zoom-pan": "^0.3.0", 42 | "react-scripts": "3.4.0", 43 | "react-world-flags": "^1.4.0", 44 | "react-zoom-pan-pinch": "^1.6.1", 45 | "redux": "^4.0.5", 46 | "redux-devtools-extension": "^2.13.8", 47 | "redux-saga": "^1.1.3", 48 | "reset-css": "^5.0.1", 49 | "tinykeys": "^1.0.4", 50 | "typesafe-actions": "^5.1.0", 51 | "typescript": "~3.7.2", 52 | "webfontloader": "^1.6.28" 53 | }, 54 | "scripts": { 55 | "start": "react-scripts start", 56 | "build": "react-scripts build", 57 | "test": "react-scripts test", 58 | "eject": "react-scripts eject" 59 | }, 60 | "eslintConfig": { 61 | "extends": "react-app" 62 | }, 63 | "browserslist": { 64 | "production": [ 65 | ">0.2%", 66 | "not dead", 67 | "not op_mini all" 68 | ], 69 | "development": [ 70 | "last 1 chrome version", 71 | "last 1 firefox version", 72 | "last 1 safari version" 73 | ] 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejb2k/pathfinding_app/40b3880586173b0f55dbcf496cc07228c143f455/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | Pathfinding App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejb2k/pathfinding_app/40b3880586173b0f55dbcf496cc07228c143f455/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejb2k/pathfinding_app/40b3880586173b0f55dbcf496cc07228c143f455/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 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 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/algorithms/graph/Dijkstra.ts: -------------------------------------------------------------------------------- 1 | import Graph from "./Graph"; 2 | import Vertex from "./Vertex"; 3 | import PriorityQueue from "./PriorityQueue"; 4 | 5 | function dijkstra(graph: Graph, startVertex: Vertex) { 6 | const queue = new PriorityQueue(); 7 | const distances: { [vertexKey: string]: number } = {}; 8 | const previousVertices: { [vertexKey: string]: Vertex | null } = {}; 9 | const visitedVertices: { [vertexKey: string]: boolean } = {}; 10 | 11 | distances[startVertex.getKey()] = 0; 12 | 13 | Object.keys(graph.vertices).forEach((key: string) => { 14 | if (key !== startVertex.getKey()) { 15 | distances[key] = Infinity; 16 | previousVertices[key] = null; 17 | } 18 | 19 | queue.insert(graph.vertices[key], distances[key]); 20 | }); 21 | 22 | visitedVertices[startVertex.getKey()] = true; 23 | 24 | while (!queue.isEmpty()) { 25 | const currentVertex = queue.pop(); 26 | 27 | if (currentVertex) { 28 | graph.getNeighbours(currentVertex.value).forEach((edge) => { 29 | const neighbour = edge.endVertex; 30 | const currentVertexKey = currentVertex.value.getKey(); 31 | 32 | if (!visitedVertices[neighbour.getKey()]) { 33 | let distanceToNeighbour = distances[currentVertexKey] + edge.weight; 34 | 35 | if (distanceToNeighbour < distances[neighbour.getKey()]) { 36 | distances[neighbour.getKey()] = distanceToNeighbour; 37 | previousVertices[neighbour.getKey()] = currentVertex.value; 38 | 39 | queue.changePriority(edge.endVertex, distanceToNeighbour); 40 | } 41 | } 42 | }); 43 | 44 | visitedVertices[currentVertex.value.getKey()] = true; 45 | } 46 | } 47 | 48 | return { 49 | distances, 50 | previousVertices, 51 | }; 52 | } 53 | 54 | export default dijkstra; 55 | -------------------------------------------------------------------------------- /src/algorithms/graph/Edge.ts: -------------------------------------------------------------------------------- 1 | import Vertex from "./Vertex"; 2 | 3 | type EdgeOptions = { [key: string]: any }; 4 | 5 | interface Edge { 6 | startVertex: Vertex; 7 | endVertex: Vertex; 8 | options: EdgeOptions; 9 | weight: number; 10 | } 11 | 12 | class Edge { 13 | constructor( 14 | startVertex: Vertex, 15 | endVertex: Vertex, 16 | weight: number = 1, 17 | options: EdgeOptions = {} 18 | ) { 19 | this.startVertex = startVertex; 20 | this.endVertex = endVertex; 21 | this.options = options; 22 | this.weight = weight; 23 | } 24 | 25 | reverse() { 26 | return new Edge( 27 | this.endVertex, 28 | this.startVertex, 29 | this.weight, 30 | this.options 31 | ); 32 | } 33 | 34 | getKey() { 35 | return `${this.startVertex}__${this.endVertex}`; 36 | } 37 | 38 | getReverseKey() { 39 | return `${this.endVertex}__${this.startVertex}`; 40 | } 41 | 42 | toString() { 43 | return this.getKey(); 44 | } 45 | } 46 | 47 | export default Edge; 48 | -------------------------------------------------------------------------------- /src/algorithms/graph/Graph.ts: -------------------------------------------------------------------------------- 1 | import Vertex from "./Vertex"; 2 | import Edge from "./Edge"; 3 | 4 | type GraphOptions = { [key: string]: any }; 5 | 6 | interface Graph { 7 | vertices: { [vertexName: string]: Vertex }; 8 | edges: { [edgeName: string]: Edge }; 9 | adjencyList: { [vertexName: string]: { [neighbourVertex: string]: Edge } }; 10 | options: GraphOptions; 11 | isDirected: boolean; 12 | } 13 | 14 | class Graph { 15 | constructor(isDirected: boolean = true, options: GraphOptions = {}) { 16 | this.isDirected = isDirected; 17 | this.vertices = {}; 18 | this.edges = {}; 19 | this.adjencyList = {}; 20 | this.options = options; 21 | } 22 | 23 | hasVertex(vertex: Vertex) { 24 | return vertex.getKey() in this.vertices ? true : false; 25 | } 26 | 27 | addVertex(vertex: Vertex) { 28 | if (this.hasVertex(vertex)) { 29 | return false; 30 | } 31 | 32 | this.vertices[vertex.getKey()] = vertex; 33 | this.adjencyList[vertex.getKey()] = {}; 34 | return true; 35 | } 36 | 37 | delVertex(vertex: Vertex) { 38 | if (!this.hasVertex(vertex)) { 39 | return false; 40 | } 41 | 42 | const key = vertex.getKey(); 43 | 44 | // Refactor to only neighbours 45 | // Loops through ajdency list linearly to match key 46 | Object.keys(this.adjencyList).forEach((startVertex) => { 47 | Object.keys(this.adjencyList[startVertex]).forEach((endVertex) => { 48 | if (key === endVertex) { 49 | delete this.adjencyList[startVertex][endVertex]; 50 | } 51 | }); 52 | }); 53 | 54 | delete this.vertices[key]; 55 | delete this.adjencyList[key]; 56 | 57 | return true; 58 | } 59 | 60 | // TODO REFACTOR !!! 61 | addEdge(edge: Edge) { 62 | const [startVertex, endVertex] = this.getVerticesFromEdge(edge); 63 | 64 | // Checks whether vertices exists in graph 65 | if (!(startVertex in this.vertices) || !(endVertex in this.vertices)) { 66 | return false; 67 | } 68 | 69 | if (this.isDirected) { 70 | if (edge.getKey() in this.edges) { 71 | return false; 72 | } 73 | 74 | this.edges[edge.getKey()] = edge; 75 | 76 | this.adjencyList[startVertex][endVertex] = edge; 77 | } else { 78 | const reverseEdge: Edge = edge.reverse(); 79 | 80 | if (edge.getKey() in this.edges || reverseEdge.getKey() in this.edges) { 81 | return false; 82 | } 83 | 84 | this.edges[edge.getKey()] = edge; 85 | this.edges[reverseEdge.getKey()] = reverseEdge; 86 | 87 | this.adjencyList[startVertex][endVertex] = edge; 88 | this.adjencyList[endVertex][startVertex] = reverseEdge; 89 | } 90 | 91 | return true; 92 | } 93 | 94 | // TODO REFACTOR !!! 95 | delEdge(edge: Edge) { 96 | const [startVertex, endVertex] = this.getVerticesFromEdge(edge); 97 | const key = edge.getKey(); 98 | 99 | if (this.isDirected) { 100 | if (key in this.edges) { 101 | delete this.adjencyList[startVertex][endVertex]; 102 | delete this.edges[key]; 103 | return true; 104 | } 105 | } else { 106 | const reverseEdge: Edge = edge.reverse(); 107 | if (key in this.edges && reverseEdge.getKey() in this.edges) { 108 | delete this.adjencyList[startVertex][endVertex]; 109 | delete this.adjencyList[endVertex][startVertex]; 110 | 111 | delete this.edges[key]; 112 | delete this.edges[reverseEdge.getKey()]; 113 | return true; 114 | } 115 | } 116 | 117 | return false; 118 | } 119 | 120 | getVerticesFromEdge(edge: Edge) { 121 | const startVertex = edge.startVertex.getKey(); 122 | const endVertex = edge.endVertex.getKey(); 123 | 124 | return [startVertex, endVertex]; 125 | } 126 | 127 | hasEdge(edge: Edge) { 128 | return edge.getKey() in this.edges ? true : false; 129 | } 130 | 131 | getNeighbours(vertex: Vertex): Array { 132 | return Object.values(this.adjencyList[vertex.getKey()]); 133 | } 134 | 135 | getVertices() { 136 | return this.vertices; 137 | } 138 | 139 | getEdges() { 140 | return this.edges; 141 | } 142 | 143 | getAdjencyList() { 144 | return this.adjencyList; 145 | } 146 | 147 | printGraph() { 148 | const graph = Object.keys(this.adjencyList) 149 | .map((startVertex) => { 150 | const edges = Object.keys(this.adjencyList[startVertex]).map( 151 | (e) => `(${startVertex}, ${e})` 152 | ); 153 | return `${startVertex} : ${edges.length} -> ${edges.join(", ")}`; 154 | }) 155 | .join("\n"); 156 | 157 | return graph; 158 | } 159 | 160 | toString() { 161 | return "GraphInstance"; 162 | } 163 | } 164 | 165 | export default Graph; 166 | -------------------------------------------------------------------------------- /src/algorithms/graph/PriorityQueue.ts: -------------------------------------------------------------------------------- 1 | // Sorry for using naive O(n) arrays instead of O(log n) heaps, 2 | // but right now my goal is to create the simplest version, 3 | // not the most efficent XD 4 | 5 | class PriorityQueue { 6 | queue: { 7 | value: T; 8 | priority: number; 9 | }[]; 10 | 11 | constructor() { 12 | this.queue = []; 13 | } 14 | 15 | insert(value: T, priority: number) { 16 | let i = 0; 17 | 18 | // Search for duplicates, only unique values 19 | for (i = 0; i < this.queue.length; i++) { 20 | if (this.queue[i].value === value) { 21 | return false; 22 | } 23 | } 24 | 25 | i = 0; 26 | 27 | // Search for bigger priority, to insert element to that index 28 | for (i = 0; i < this.queue.length; i++) { 29 | if (this.queue[i].priority > priority) { 30 | break; 31 | } 32 | } 33 | 34 | this.queue.splice(i, 0, { 35 | value, 36 | priority, 37 | }); 38 | 39 | return true; 40 | } 41 | 42 | remove(value: T) { 43 | for (let i = 0; i < this.queue.length; i++) { 44 | let current = this.queue[i]; 45 | if (current.value === value) { 46 | this.queue.splice(i, 1); 47 | } 48 | } 49 | } 50 | 51 | changePriority(value: T, newPriority: number) { 52 | this.remove(value); 53 | this.insert(value, newPriority); 54 | } 55 | 56 | pop() { 57 | return this.isEmpty() ? false : this.queue.shift(); 58 | } 59 | 60 | minimum() { 61 | return this.isEmpty() ? false : this.queue[0]; 62 | } 63 | 64 | isEmpty() { 65 | return this.queue.length ? false : true; 66 | } 67 | 68 | size() { 69 | return this.queue.length; 70 | } 71 | 72 | toString() { 73 | return "PriorityQueue"; 74 | } 75 | } 76 | 77 | export default PriorityQueue; 78 | -------------------------------------------------------------------------------- /src/algorithms/graph/Utils.ts: -------------------------------------------------------------------------------- 1 | import Vertex from "algorithms/graph/Vertex"; 2 | import Edge from "algorithms/graph/Edge"; 3 | import Graph from "algorithms/graph/Graph"; 4 | import { mapData, vertexData, edgeData } from "components/Map/mapData"; 5 | 6 | export const getGraphFromJSON = (map: mapData, isDirected = false) => { 7 | const graph = new Graph(isDirected); 8 | 9 | Object.values(map.v).forEach((v: vertexData) => { 10 | let key = v.key.trim().toLowerCase(); 11 | let vertex = new Vertex(key, { ...v.options }); 12 | graph.addVertex(vertex); 13 | }); 14 | 15 | Object.values(map.e).forEach((e: edgeData) => { 16 | let [startVertex, endVertex] = e.key 17 | .split("__") 18 | .map((item: string) => item.trim().toLowerCase()); 19 | 20 | let edge = new Edge( 21 | graph.getVertices()[startVertex], 22 | graph.getVertices()[endVertex], 23 | e.weight 24 | ); 25 | 26 | graph.addEdge(edge); 27 | }); 28 | 29 | return graph; 30 | }; 31 | 32 | export const getPathFromDijkstra = ( 33 | edgesList: { [edgeName: string]: Edge }, 34 | previousVertices: { 35 | [vertexKey: string]: Vertex | null; 36 | }, 37 | endVertex: Vertex 38 | ) => { 39 | const vertices: Vertex[] = []; 40 | const edges: Edge[] = []; 41 | 42 | const createListOfVertices = (destinationVertex: Vertex) => { 43 | const nextVertex = previousVertices[destinationVertex.getKey()]; 44 | 45 | if (nextVertex) { 46 | vertices.unshift(nextVertex); 47 | createListOfVertices(nextVertex); 48 | } 49 | }; 50 | 51 | const createListOfEdges = (vertices: Vertex[]) => { 52 | for (let i = 1; i < vertices.length; i++) { 53 | let edgeKey = `${vertices[i - 1].getKey()}__${vertices[i].getKey()}`; 54 | if (edgesList[edgeKey]) { 55 | edges.push(edgesList[edgeKey]); 56 | } 57 | } 58 | }; 59 | 60 | createListOfVertices(endVertex); 61 | 62 | if (vertices.length) { 63 | vertices.push(endVertex); 64 | createListOfEdges(vertices); 65 | } 66 | 67 | return { 68 | vertices, 69 | edges, 70 | }; 71 | }; 72 | 73 | export const objectToVertexKey = (objectKey: string) => { 74 | const map: mapData = mapData; 75 | 76 | if (map.o[objectKey]) { 77 | return map.o[objectKey].ref; 78 | } 79 | 80 | return false; 81 | }; 82 | -------------------------------------------------------------------------------- /src/algorithms/graph/Vertex.ts: -------------------------------------------------------------------------------- 1 | type VertexOptions = { [key: string]: any }; 2 | 3 | interface Vertex { 4 | name: string; 5 | options: VertexOptions; 6 | } 7 | 8 | class Vertex { 9 | constructor(name: string, options: VertexOptions = {}) { 10 | this.name = name; 11 | this.options = options; 12 | } 13 | 14 | getKey(): string { 15 | return this.name; 16 | } 17 | 18 | toString() { 19 | return this.getKey(); 20 | } 21 | } 22 | 23 | export default Vertex; 24 | -------------------------------------------------------------------------------- /src/algorithms/graph/__tests__/Dijkstra.test.ts: -------------------------------------------------------------------------------- 1 | import Vertex from "algorithms/graph/Vertex"; 2 | import Edge from "algorithms/graph/Edge"; 3 | import Graph from "algorithms/graph/Graph"; 4 | import dijkstra from "algorithms/graph/Dijkstra"; 5 | 6 | describe("Dijkstra", () => { 7 | it("should find paths to all vertices", () => { 8 | const graph = new Graph(); 9 | 10 | const vertex_a = new Vertex("A"); 11 | const vertex_b = new Vertex("B"); 12 | const vertex_c = new Vertex("C"); 13 | const vertex_d = new Vertex("D"); 14 | const vertex_e = new Vertex("E"); 15 | const vertex_f = new Vertex("F"); 16 | const vertex_g = new Vertex("G"); 17 | const vertex_h = new Vertex("H"); 18 | 19 | const edge_a_b = new Edge(vertex_a, vertex_b, 1); 20 | const edge_b_c = new Edge(vertex_b, vertex_c, 2); 21 | const edge_c_d = new Edge(vertex_c, vertex_d, 3); 22 | const edge_d_h = new Edge(vertex_d, vertex_h, 20); 23 | const edge_b_d = new Edge(vertex_b, vertex_d, 1); 24 | const edge_h_g = new Edge(vertex_h, vertex_g, 3); 25 | const edge_g_h = new Edge(vertex_g, vertex_h, 1); 26 | const edge_g_f = new Edge(vertex_g, vertex_f, 4); 27 | const edge_f_g = new Edge(vertex_f, vertex_g, 3); 28 | const edge_e_f = new Edge(vertex_e, vertex_f, 2); 29 | const edge_f_e = new Edge(vertex_f, vertex_e, 3); 30 | const edge_e_b = new Edge(vertex_e, vertex_b, 3); 31 | const edge_b_e = new Edge(vertex_b, vertex_e, 3); 32 | 33 | graph.addVertex(vertex_a); 34 | graph.addVertex(vertex_b); 35 | graph.addVertex(vertex_c); 36 | graph.addVertex(vertex_d); 37 | graph.addVertex(vertex_e); 38 | graph.addVertex(vertex_f); 39 | graph.addVertex(vertex_g); 40 | graph.addVertex(vertex_h); 41 | 42 | graph.addEdge(edge_a_b); 43 | graph.addEdge(edge_b_c); 44 | graph.addEdge(edge_c_d); 45 | graph.addEdge(edge_d_h); 46 | graph.addEdge(edge_b_d); 47 | graph.addEdge(edge_h_g); 48 | graph.addEdge(edge_g_h); 49 | graph.addEdge(edge_g_f); 50 | graph.addEdge(edge_f_g); 51 | graph.addEdge(edge_e_f); 52 | graph.addEdge(edge_f_e); 53 | graph.addEdge(edge_e_b); 54 | graph.addEdge(edge_b_e); 55 | 56 | const { distances, previousVertices } = dijkstra(graph, vertex_h); 57 | 58 | expect(distances).toStrictEqual({ 59 | A: Infinity, 60 | B: 13, 61 | C: 15, 62 | D: 14, 63 | E: 10, 64 | F: 7, 65 | G: 3, 66 | H: 0, 67 | }); 68 | 69 | expect(previousVertices.A).toBeNull(); 70 | expect(previousVertices.B?.getKey()).toBe("E"); 71 | expect(previousVertices.C?.getKey()).toBe("B"); 72 | }); 73 | }); 74 | 75 | export {}; 76 | -------------------------------------------------------------------------------- /src/algorithms/graph/__tests__/Edge.test.ts: -------------------------------------------------------------------------------- 1 | import Vertex from "algorithms/graph/Vertex"; 2 | import Edge from "algorithms/graph/Edge"; 3 | 4 | describe("Edge", () => { 5 | it("returns proper key", () => { 6 | const edge = new Edge(new Vertex("A"), new Vertex("B"), 5); 7 | 8 | expect(edge.getKey()).toBe("A__B"); 9 | }); 10 | 11 | it("reverses edge", () => { 12 | const edge = new Edge(new Vertex("A"), new Vertex("B"), 5); 13 | const newEdge = edge.reverse(); 14 | 15 | expect(newEdge.getKey()).toBe("B__A"); 16 | }); 17 | }); 18 | 19 | export {}; 20 | -------------------------------------------------------------------------------- /src/algorithms/graph/__tests__/Graph.test.ts: -------------------------------------------------------------------------------- 1 | import Vertex from "algorithms/graph/Vertex"; 2 | import Edge from "algorithms/graph/Edge"; 3 | import Graph from "algorithms/graph/Graph"; 4 | 5 | describe("Graph", () => { 6 | it("adds vertex to graph", () => { 7 | const graph = new Graph(); 8 | const vertex_a = new Vertex("A"); 9 | 10 | graph.addVertex(vertex_a); 11 | 12 | expect(graph.hasVertex(vertex_a)).toBe(true); 13 | }); 14 | 15 | it("throws when adding same vertex", () => { 16 | const graph = new Graph(); 17 | const vertex_a = new Vertex("A"); 18 | 19 | graph.addVertex(vertex_a); 20 | graph.addVertex(vertex_a); 21 | 22 | expect(Object.keys(graph.getAdjencyList())).toHaveLength(1); 23 | }); 24 | 25 | it("deletes vertex", () => { 26 | const graph = new Graph(); 27 | const vertex_a = new Vertex("A"); 28 | 29 | graph.addVertex(vertex_a); 30 | graph.delVertex(vertex_a); 31 | 32 | expect(Object.keys(graph.getAdjencyList())).toHaveLength(0); 33 | }); 34 | 35 | it("throws when vertex not in graph", () => { 36 | const graph = new Graph(); 37 | const vertex_a = new Vertex("A"); 38 | 39 | const result = graph.delVertex(vertex_a); 40 | 41 | expect(result).toBe(false); 42 | }); 43 | 44 | it("checks whether graph has vertex", () => { 45 | const graph = new Graph(); 46 | const vertex_a = new Vertex("A"); 47 | graph.addVertex(vertex_a); 48 | 49 | expect(graph.hasVertex(vertex_a)).toBe(true); 50 | }); 51 | 52 | it("adds edge", () => { 53 | const graph = new Graph(); 54 | const vertex_a = new Vertex("A"); 55 | const vertex_b = new Vertex("B"); 56 | const edge_a_b = new Edge(vertex_a, vertex_b); 57 | 58 | graph.addVertex(vertex_a); 59 | graph.addVertex(vertex_b); 60 | graph.addEdge(edge_a_b); 61 | 62 | expect(graph.getAdjencyList()[vertex_a.getKey()]).toMatchObject({ 63 | [vertex_b.getKey()]: edge_a_b, 64 | }); 65 | }); 66 | 67 | it("throws when adding same edge", () => { 68 | const graph = new Graph(); 69 | const vertex_a = new Vertex("A"); 70 | const vertex_b = new Vertex("B"); 71 | const edge_a_b = new Edge(vertex_a, vertex_b); 72 | 73 | graph.addVertex(vertex_a); 74 | graph.addVertex(vertex_b); 75 | graph.addEdge(edge_a_b); 76 | graph.addEdge(edge_a_b); 77 | 78 | expect(Object.keys(graph.getAdjencyList()[vertex_a.getKey()])).toHaveLength( 79 | 1 80 | ); 81 | }); 82 | 83 | it("deletes edge", () => { 84 | const graph = new Graph(); 85 | const vertex_a = new Vertex("A"); 86 | const vertex_b = new Vertex("B"); 87 | const edge_a_b = new Edge(vertex_a, vertex_b); 88 | 89 | graph.addVertex(vertex_a); 90 | graph.addVertex(vertex_b); 91 | graph.addEdge(edge_a_b); 92 | graph.delEdge(edge_a_b); 93 | 94 | expect(Object.keys(graph.getEdges())).toHaveLength(0); 95 | }); 96 | 97 | it("throws when edge not in graph", () => { 98 | const graph = new Graph(); 99 | const vertex_a = new Vertex("A"); 100 | const vertex_b = new Vertex("B"); 101 | const edge_a_b = new Edge(vertex_a, vertex_b); 102 | 103 | const result = graph.hasEdge(edge_a_b); 104 | 105 | expect(result).toBe(false); 106 | }); 107 | 108 | it("throws when deleting edge not in graph", () => { 109 | const graph = new Graph(); 110 | const vertex_a = new Vertex("A"); 111 | const vertex_b = new Vertex("B"); 112 | const edge_a_b = new Edge(vertex_a, vertex_b); 113 | 114 | const result = graph.delEdge(edge_a_b); 115 | 116 | expect(result).toBe(false); 117 | }); 118 | 119 | it("throws when adding edge without vertcies present", () => { 120 | const graph = new Graph(); 121 | const vertex_a = new Vertex("A"); 122 | const vertex_b = new Vertex("B"); 123 | const edge_a_b = new Edge(vertex_a, vertex_b); 124 | 125 | const result = graph.addEdge(edge_a_b); 126 | 127 | expect(result).toBe(false); 128 | }); 129 | 130 | it("checks whether edge exists in graph", () => { 131 | const graph = new Graph(); 132 | const vertex_a = new Vertex("A"); 133 | const vertex_b = new Vertex("B"); 134 | const edge_a_b = new Edge(vertex_a, vertex_b); 135 | 136 | graph.addVertex(vertex_a); 137 | graph.addVertex(vertex_b); 138 | graph.addEdge(edge_a_b); 139 | 140 | expect(graph.hasEdge(edge_a_b)).toBe(true); 141 | }); 142 | 143 | it("returns list of edges", () => { 144 | const graph = new Graph(); 145 | const vertex_a = new Vertex("A"); 146 | const vertex_b = new Vertex("B"); 147 | const edge_a_b = new Edge(vertex_a, vertex_b); 148 | 149 | graph.addVertex(vertex_a); 150 | graph.addVertex(vertex_b); 151 | graph.addEdge(edge_a_b); 152 | 153 | expect(graph.getEdges()).toMatchObject({ 154 | [edge_a_b.getKey()]: edge_a_b, 155 | }); 156 | }); 157 | 158 | it("returns list of vertices", () => { 159 | const graph = new Graph(); 160 | const vertex_a = new Vertex("A"); 161 | graph.addVertex(vertex_a); 162 | 163 | expect(graph.getVertices()).toMatchObject({ 164 | [vertex_a.getKey()]: vertex_a, 165 | }); 166 | }); 167 | 168 | it("prints graph", () => { 169 | const graph = new Graph(); 170 | 171 | expect(typeof graph.printGraph()).toEqual("string"); 172 | }); 173 | 174 | it("casts to string", () => { 175 | const graph = new Graph(); 176 | 177 | expect(typeof graph.toString()).toBe("string"); 178 | }); 179 | }); 180 | 181 | export {}; 182 | -------------------------------------------------------------------------------- /src/algorithms/graph/__tests__/PriorityQueue.test.ts: -------------------------------------------------------------------------------- 1 | import Vertex from "algorithms/graph/Vertex"; 2 | import PriorityQueue from "algorithms/graph/PriorityQueue"; 3 | 4 | describe("PriorityQueue", () => { 5 | it("adds item to queue", () => { 6 | const queue = new PriorityQueue(); 7 | const vertex_a = new Vertex("A"); 8 | const vertex_b = new Vertex("B"); 9 | const vertex_c = new Vertex("C"); 10 | const vertex_d = new Vertex("D"); 11 | 12 | queue.insert(vertex_a, 10); 13 | queue.insert(vertex_b, 5); 14 | queue.insert(vertex_c, 11); 15 | queue.insert(vertex_d, 2); 16 | 17 | expect(queue.queue[0].value.getKey()).toBe("D"); 18 | expect(queue.queue[1].value.getKey()).toBe("B"); 19 | expect(queue.queue[2].value.getKey()).toBe("A"); 20 | expect(queue.queue[3].value.getKey()).toBe("C"); 21 | 22 | expect(queue.size()).toBe(4); 23 | }); 24 | 25 | it("adds only unique items", () => { 26 | const queue = new PriorityQueue(); 27 | const vertex_a = new Vertex("A"); 28 | 29 | expect(queue.insert(vertex_a, 10)).toBe(true); 30 | expect(queue.insert(vertex_a, 12)).toBe(false); 31 | }); 32 | 33 | it("removes item from queue", () => { 34 | const queue = new PriorityQueue(); 35 | const vertex_a = new Vertex("A"); 36 | const vertex_b = new Vertex("B"); 37 | const vertex_c = new Vertex("C"); 38 | const vertex_d = new Vertex("D"); 39 | 40 | queue.insert(vertex_a, 10); 41 | queue.insert(vertex_b, 5); 42 | queue.insert(vertex_c, 11); 43 | queue.insert(vertex_d, 2); 44 | 45 | expect(queue.size()).toBe(4); 46 | 47 | queue.remove(vertex_d); 48 | 49 | expect(queue.size()).toBe(3); 50 | expect(queue.queue[0].value.getKey()).toBe("B"); 51 | }); 52 | 53 | it("changes priority of item", () => { 54 | const queue = new PriorityQueue(); 55 | const vertex_a = new Vertex("A"); 56 | const vertex_b = new Vertex("B"); 57 | const vertex_c = new Vertex("C"); 58 | const vertex_d = new Vertex("D"); 59 | 60 | queue.insert(vertex_a, 10); 61 | queue.insert(vertex_b, 5); 62 | queue.insert(vertex_c, 11); 63 | queue.insert(vertex_d, 2); 64 | 65 | expect(queue.queue[0].value.getKey()).toBe("D"); 66 | 67 | queue.changePriority(vertex_d, 100); 68 | 69 | expect(queue.queue[3].value.getKey()).toBe("D"); 70 | }); 71 | 72 | it("removes and returns element with lowest priority", () => { 73 | const queue = new PriorityQueue(); 74 | const vertex_a = new Vertex("A"); 75 | const vertex_b = new Vertex("B"); 76 | const vertex_c = new Vertex("C"); 77 | const vertex_d = new Vertex("D"); 78 | 79 | queue.insert(vertex_a, 10); 80 | queue.insert(vertex_b, 5); 81 | queue.insert(vertex_c, 11); 82 | queue.insert(vertex_d, 2); 83 | 84 | const min = queue.pop(); 85 | 86 | expect(queue.size()).toBe(3); 87 | 88 | if (min) { 89 | expect(min.value.getKey()).toBe("D"); 90 | } 91 | }); 92 | 93 | it("checks whether queue is empty", () => { 94 | const queue = new PriorityQueue(); 95 | const vertex_a = new Vertex("A"); 96 | 97 | expect(queue.isEmpty()).toBe(true); 98 | 99 | queue.insert(vertex_a, 10); 100 | 101 | expect(queue.isEmpty()).toBe(false); 102 | }); 103 | 104 | it("returns minimum element", () => { 105 | const queue = new PriorityQueue(); 106 | const vertex_a = new Vertex("A"); 107 | const vertex_b = new Vertex("B"); 108 | const vertex_c = new Vertex("C"); 109 | const vertex_d = new Vertex("D"); 110 | 111 | queue.insert(vertex_a, 10); 112 | queue.insert(vertex_b, 5); 113 | queue.insert(vertex_c, 11); 114 | queue.insert(vertex_d, 2); 115 | 116 | const min = queue.minimum(); 117 | expect(queue.size()).toBe(4); 118 | 119 | if (min) { 120 | expect(min.value.getKey()).toBe("D"); 121 | } 122 | }); 123 | 124 | it("returns size of queue", () => { 125 | const queue = new PriorityQueue(); 126 | const vertex_a = new Vertex("A"); 127 | 128 | queue.insert(vertex_a, 10); 129 | 130 | expect(queue.size()).toBe(1); 131 | }); 132 | 133 | it("returns toString", () => { 134 | const queue = new PriorityQueue(); 135 | expect(queue.toString()).toBe("PriorityQueue"); 136 | }); 137 | }); 138 | 139 | export {}; 140 | -------------------------------------------------------------------------------- /src/algorithms/graph/__tests__/Utils.test.ts: -------------------------------------------------------------------------------- 1 | import Vertex from "algorithms/graph/Vertex"; 2 | import Edge from "algorithms/graph/Edge"; 3 | import Graph from "algorithms/graph/Graph"; 4 | import dijkstra from "algorithms/graph/Dijkstra"; 5 | import { getPathFromDijkstra } from "algorithms/graph/Utils"; 6 | 7 | describe("Utils", () => { 8 | it("should return vertices and edges", () => { 9 | const graph = new Graph(); 10 | 11 | const vertex_a = new Vertex("A"); 12 | const vertex_b = new Vertex("B"); 13 | const vertex_c = new Vertex("C"); 14 | const vertex_d = new Vertex("D"); 15 | const vertex_e = new Vertex("E"); 16 | const vertex_f = new Vertex("F"); 17 | const vertex_g = new Vertex("G"); 18 | const vertex_h = new Vertex("H"); 19 | 20 | const edge_a_b = new Edge(vertex_a, vertex_b, 1); 21 | const edge_b_c = new Edge(vertex_b, vertex_c, 2); 22 | const edge_c_d = new Edge(vertex_c, vertex_d, 3); 23 | const edge_d_h = new Edge(vertex_d, vertex_h, 20); 24 | const edge_b_d = new Edge(vertex_b, vertex_d, 1); 25 | const edge_h_g = new Edge(vertex_h, vertex_g, 3); 26 | const edge_g_h = new Edge(vertex_g, vertex_h, 1); 27 | const edge_g_f = new Edge(vertex_g, vertex_f, 4); 28 | const edge_f_g = new Edge(vertex_f, vertex_g, 3); 29 | const edge_e_f = new Edge(vertex_e, vertex_f, 2); 30 | const edge_f_e = new Edge(vertex_f, vertex_e, 3); 31 | const edge_e_b = new Edge(vertex_e, vertex_b, 3); 32 | const edge_b_e = new Edge(vertex_b, vertex_e, 3); 33 | 34 | graph.addVertex(vertex_a); 35 | graph.addVertex(vertex_b); 36 | graph.addVertex(vertex_c); 37 | graph.addVertex(vertex_d); 38 | graph.addVertex(vertex_e); 39 | graph.addVertex(vertex_f); 40 | graph.addVertex(vertex_g); 41 | graph.addVertex(vertex_h); 42 | 43 | graph.addEdge(edge_a_b); 44 | graph.addEdge(edge_b_c); 45 | graph.addEdge(edge_c_d); 46 | graph.addEdge(edge_d_h); 47 | graph.addEdge(edge_b_d); 48 | graph.addEdge(edge_h_g); 49 | graph.addEdge(edge_g_h); 50 | graph.addEdge(edge_g_f); 51 | graph.addEdge(edge_f_g); 52 | graph.addEdge(edge_e_f); 53 | graph.addEdge(edge_f_e); 54 | graph.addEdge(edge_e_b); 55 | graph.addEdge(edge_b_e); 56 | 57 | const startVertex = vertex_a; 58 | const endVertex = vertex_h; 59 | 60 | const { previousVertices } = dijkstra(graph, startVertex); 61 | const { vertices, edges } = getPathFromDijkstra( 62 | graph.edges, 63 | previousVertices, 64 | endVertex 65 | ); 66 | 67 | expect(vertices.length).toBe(6); 68 | expect(vertices[0].getKey()).toBe("A"); 69 | expect(vertices[1].getKey()).toBe("B"); 70 | expect(vertices[2].getKey()).toBe("E"); 71 | expect(vertices[3].getKey()).toBe("F"); 72 | expect(vertices[4].getKey()).toBe("G"); 73 | expect(vertices[5].getKey()).toBe("H"); 74 | 75 | expect(edges.length).toBe(5); 76 | expect(edges[0].getKey()).toBe("A__B"); 77 | expect(edges[1].getKey()).toBe("B__E"); 78 | expect(edges[2].getKey()).toBe("E__F"); 79 | expect(edges[3].getKey()).toBe("F__G"); 80 | expect(edges[4].getKey()).toBe("G__H"); 81 | }); 82 | }); 83 | 84 | export {}; 85 | -------------------------------------------------------------------------------- /src/algorithms/graph/__tests__/Vertex.test.ts: -------------------------------------------------------------------------------- 1 | import Vertex from "algorithms/graph/Vertex"; 2 | 3 | describe("Vertex", () => { 4 | it("returns proper key", () => { 5 | const vertex = new Vertex("A"); 6 | expect(vertex.getKey()).toBe("A"); 7 | }); 8 | }); 9 | 10 | export {}; 11 | -------------------------------------------------------------------------------- /src/components/App/App.module.scss: -------------------------------------------------------------------------------- 1 | @import "styles/themes.scss"; 2 | 3 | .app { 4 | background-color: var(--color-bg); 5 | } 6 | -------------------------------------------------------------------------------- /src/components/App/App.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | 3 | import { initLocalStorageSettings } from "utils/initLocalStorage"; 4 | import { initGraph } from "store/graph/actions"; 5 | import { fetchApiData } from "store/api/actions"; 6 | 7 | import Layout from "containers/Layout"; 8 | 9 | type AppProps = { 10 | storeState: { 11 | theme: string; 12 | lang: string; 13 | }; 14 | initGraph: typeof initGraph; 15 | fetchApiData: typeof fetchApiData; 16 | }; 17 | 18 | function App(props: AppProps) { 19 | const { 20 | storeState: { theme }, 21 | initGraph, 22 | fetchApiData, 23 | } = props; 24 | 25 | useEffect(() => { 26 | document.title = "Pathfinding"; 27 | }, []); 28 | 29 | useEffect(() => { 30 | initLocalStorageSettings(); 31 | initGraph(); 32 | fetchApiData(); 33 | }, [fetchApiData, initGraph]); 34 | 35 | useEffect(() => { 36 | document.body.dataset.theme = theme; 37 | }, [theme]); 38 | 39 | return ( 40 |
41 | 42 |
43 | ); 44 | } 45 | 46 | export default App; 47 | -------------------------------------------------------------------------------- /src/components/App/__tests__/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { render } from "@testing-library/react"; 3 | 4 | import { Provider } from "react-redux"; 5 | import store from "store"; 6 | 7 | import App from "components/App"; 8 | 9 | describe("App.tsx", () => { 10 | it("should render component", () => { 11 | render( 12 | 13 | 14 | 15 | ); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/components/App/index.tsx: -------------------------------------------------------------------------------- 1 | import { compose } from "redux"; 2 | import { connect } from "react-redux"; 3 | 4 | import { initGraph } from "store/graph/actions"; 5 | import { fetchApiData } from "store/api/actions"; 6 | 7 | import { AppState } from "store/rootReducer"; 8 | 9 | import App from "./App"; 10 | 11 | const mapStateToProps = ({ settings }: AppState) => ({ 12 | storeState: settings, 13 | }); 14 | 15 | const mapDispatchToProps = { 16 | initGraph, 17 | fetchApiData, 18 | }; 19 | 20 | const enhancer = compose(connect(mapStateToProps, mapDispatchToProps)); 21 | 22 | export default enhancer(App); 23 | -------------------------------------------------------------------------------- /src/components/FloorMapSvg/FloorMapSvg.module.scss: -------------------------------------------------------------------------------- 1 | .FloorMap { 2 | width: 1150px; 3 | height: auto; 4 | fill: none; 5 | margin-top: 50px; 6 | } 7 | 8 | .Floor { 9 | fill: var(--floor); 10 | } 11 | .Floor-border { 12 | stroke: var(--floor-stroke); 13 | } 14 | 15 | .Vertex { 16 | opacity: 0; 17 | fill: var(--vertex); 18 | cursor: pointer; 19 | position: relative; 20 | } 21 | 22 | .Vertex--active { 23 | opacity: 1; 24 | position: relative; 25 | fill: var(--green); 26 | cursor: default; 27 | } 28 | 29 | .Edge { 30 | fill: var(--green); 31 | opacity: 0; 32 | } 33 | 34 | .Object { 35 | fill: var(--object-fill); 36 | stroke: var(--object-stroke); 37 | transition: 0.1s all; 38 | 39 | &:hover { 40 | cursor: pointer; 41 | fill: var(--object-fill--hover); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/components/FloorMapSvg/__tests__/FloorMapSvg.test.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { render } from "@testing-library/react"; 3 | import fireEvent from "@testing-library/user-event"; 4 | import "@testing-library/jest-dom"; 5 | 6 | import { Provider } from "react-redux"; 7 | import store from "store"; 8 | 9 | import FloorMapSvg from "components/FloorMapSvg"; 10 | 11 | describe("FloorMap.tsx", () => { 12 | it("should render component", () => { 13 | render( 14 | 15 | 16 | 17 | ); 18 | }); 19 | 20 | it("should open modal", () => { 21 | const { getByTestId } = render( 22 | 23 | 24 | 25 | ); 26 | 27 | const test_obj = getByTestId("test_o_43"); 28 | expect(test_obj).toBeInTheDocument(); 29 | 30 | fireEvent.click(test_obj); 31 | const fetchStore = store.getState(); 32 | expect(fetchStore.modals.activeModal).toBe("MODAL_OBJECT_INFO"); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /src/components/FloorMapSvg/index.ts: -------------------------------------------------------------------------------- 1 | import { compose } from "redux"; 2 | import { connect } from "react-redux"; 3 | 4 | import { openModal, closeModal } from "store/modals/actions"; 5 | import { setStartVertex } from "store/graph/actions"; 6 | 7 | import { AppState } from "store/rootReducer"; 8 | 9 | import FloorMapSvg from "./FloorMapSvg"; 10 | 11 | const mapStateToProps = ({ modals, graph }: AppState) => ({ 12 | modals, 13 | graph, 14 | }); 15 | 16 | const mapDispatchToProps = { 17 | openModal, 18 | closeModal, 19 | setStartVertex, 20 | }; 21 | 22 | const enhancer = compose(connect(mapStateToProps, mapDispatchToProps)); 23 | 24 | export default enhancer(FloorMapSvg); 25 | -------------------------------------------------------------------------------- /src/components/Main/Main.module.scss: -------------------------------------------------------------------------------- 1 | @import "styles/themes.scss"; 2 | 3 | .Main { 4 | background: var(--map-bg); 5 | width: 100%; 6 | height: 100%; 7 | position: relative; 8 | 9 | .Controls { 10 | .ControlsUpperLeft { 11 | left: 30px; 12 | position: absolute; 13 | z-index: 2; 14 | top: 30px; 15 | display: flex; 16 | 17 | .PathPreview { 18 | display: flex; 19 | height: 50px; 20 | align-items: center; 21 | justify-content: center; 22 | margin-left: 30px; 23 | background: var(--pathPreview-bg); 24 | color: var(--pathPreview-text); 25 | box-shadow: 0px 10px 25px rgba(0, 0, 0, 0.05); 26 | transition: 0.1s all; 27 | padding-left: 30px; 28 | opacity: 0; 29 | visibility: hidden; 30 | animation: pulse 2s infinite; 31 | border-left: 5px solid var(--green); 32 | 33 | .PathPreview-button { 34 | width: 50px; 35 | height: 50px; 36 | display: flex; 37 | align-items: center; 38 | justify-content: center; 39 | border: 0; 40 | background: var(--pathPreview-button); 41 | color: var(--close-red); 42 | font-size: 1.4rem; 43 | position: relative; 44 | 45 | &::after { 46 | content: ""; 47 | left: 2px; 48 | display: block; 49 | position: absolute; 50 | height: 30px; 51 | width: 1px; 52 | background: var(--input-separator); 53 | } 54 | 55 | &:hover { 56 | cursor: pointer; 57 | } 58 | } 59 | 60 | .PathPreview-info { 61 | padding-right: 100px; 62 | 63 | .PathPreview-title { 64 | font-weight: 600; 65 | font-size: 1.4rem; 66 | } 67 | } 68 | 69 | @-webkit-keyframes pulse { 70 | 0% { 71 | -webkit-box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.1); 72 | } 73 | 70% { 74 | -webkit-box-shadow: 0 0 0 10px rgba(46, 204, 113, 0); 75 | } 76 | 100% { 77 | -webkit-box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); 78 | } 79 | } 80 | 81 | @keyframes pulse { 82 | 0% { 83 | -moz-box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.1); 84 | box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.3); 85 | } 86 | 70% { 87 | -moz-box-shadow: 0 0 0 20px rgba(46, 204, 113, 0); 88 | box-shadow: 0 0 0 20px rgba(46, 204, 113, 0); 89 | } 90 | 100% { 91 | -moz-box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); 92 | box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); 93 | } 94 | } 95 | } 96 | 97 | .PathPreview--active { 98 | opacity: 1; 99 | visibility: visible; 100 | } 101 | 102 | .ControlsSearch { 103 | display: flex; 104 | align-items: center; 105 | 106 | .ControlsSearch-form { 107 | margin-left: 30px; 108 | display: flex; 109 | position: relative; 110 | box-shadow: 0px 10px 25px rgba(0, 0, 0, 0.05); 111 | 112 | .ControlsSearch-icon { 113 | position: relative; 114 | height: 50px; 115 | width: 50px; 116 | display: flex; 117 | align-items: center; 118 | justify-content: center; 119 | border-bottom-left-radius: 5px; 120 | border-top-left-radius: 5px; 121 | background: var(--searchProduct-input); 122 | font-size: 0.8rem; 123 | color: var(--primary); 124 | 125 | &::after { 126 | content: ""; 127 | right: 0; 128 | display: block; 129 | position: absolute; 130 | height: 30px; 131 | width: 1px; 132 | background: var(--input-separator); 133 | } 134 | } 135 | .ControlsSearch-inputGroup { 136 | position: relative; 137 | 138 | .ControlsSearch-input { 139 | height: 50px; 140 | width: 250px; 141 | font-size: 1.4rem; 142 | padding: 0 20px; 143 | background: var(--searchProduct-input); 144 | color: var(--searchProduct-input-color); 145 | 146 | &::placeholder { 147 | color: var(--input-placeholder); 148 | } 149 | } 150 | 151 | .Autocomplete { 152 | position: absolute; 153 | left: 0px; 154 | top: 50px; 155 | font-size: 1.4rem; 156 | background: var(--autocomplete-bg); 157 | width: 250px; 158 | border: 1px solid var(--autocomplete-border); 159 | box-shadow: 0px 10px 25px rgba(0, 0, 0, 0.05); 160 | 161 | .Autocomplete-list { 162 | list-style-position: inside; 163 | list-style-type: none; 164 | max-height: 180px; 165 | overflow-y: scroll; 166 | 167 | .Autocomplete-listItem { 168 | padding: 10px 20px; 169 | color: var(--autocomplete-text); 170 | 171 | &:hover { 172 | background: var(--autocomplete-hover); 173 | cursor: pointer; 174 | } 175 | 176 | &:not(:first-child) { 177 | border-top: 1px solid var(--autocomplete-border); 178 | } 179 | } 180 | 181 | &::-webkit-scrollbar { 182 | width: 5px; 183 | } 184 | 185 | &::-webkit-scrollbar-track { 186 | background-color: var(--scrollbar-track); 187 | border-radius: 10px; 188 | } 189 | 190 | &::-webkit-scrollbar-thumb { 191 | background-color: var(--scrollbar-thumb); 192 | border-radius: 10px; 193 | } 194 | } 195 | 196 | .Autocomplete-loader { 197 | display: flex; 198 | align-items: center; 199 | justify-content: center; 200 | padding: 10px; 201 | } 202 | 203 | .Autocomplete-empty { 204 | text-align: center; 205 | color: var(--autocomplete-text); 206 | padding: 10px; 207 | } 208 | } 209 | } 210 | 211 | .ControlsSearch-submit { 212 | height: 50px; 213 | width: 50px; 214 | color: var(--searchProduct-submit-color); 215 | display: flex; 216 | align-items: center; 217 | justify-content: center; 218 | border-bottom-right-radius: 5px; 219 | border-top-right-radius: 5px; 220 | background: var(--searchProduct-submit-bg); 221 | font-size: 1.8rem; 222 | cursor: pointer; 223 | transition: 0.3s all; 224 | } 225 | 226 | .ControlsSearch-submit--disabled { 227 | background: var(--button-disabled); 228 | 229 | &:hover { 230 | cursor: not-allowed; 231 | } 232 | } 233 | 234 | .ControlsSearch-input, 235 | .ControlsSearch-submit { 236 | border: 0; 237 | } 238 | } 239 | } 240 | } 241 | 242 | .ControlsUpperRight { 243 | right: 30px; 244 | position: absolute; 245 | z-index: 2; 246 | top: 30px; 247 | } 248 | 249 | .ControlsLowerRight { 250 | right: 30px; 251 | position: absolute; 252 | z-index: 2; 253 | bottom: 30px; 254 | 255 | .ControlsButtons { 256 | display: flex; 257 | flex-direction: column; 258 | 259 | &:not(:last-child) { 260 | margin-bottom: 20px; 261 | } 262 | } 263 | } 264 | 265 | .ControlsButton { 266 | width: 50px; 267 | height: 50px; 268 | border: 0; 269 | font-weight: 600; 270 | border-radius: 5px; 271 | box-shadow: 0px 10px 25px rgba(0, 0, 0, 0.05); 272 | font-size: 1.8rem; 273 | display: flex; 274 | align-items: center; 275 | justify-content: center; 276 | cursor: pointer; 277 | position: relative; 278 | transition: 0.1s all; 279 | 280 | &:not(:last-child) { 281 | margin-bottom: 5px; 282 | } 283 | 284 | &[disabled] { 285 | background: var(--button-disabled); 286 | } 287 | 288 | &[disabled]:hover { 289 | cursor: not-allowed; 290 | } 291 | } 292 | 293 | .ControlsButton--tooltip { 294 | &:before { 295 | content: attr(data-text); 296 | position: absolute; 297 | font-size: 1.2rem; 298 | right: 60px; 299 | height: 50px; 300 | top: 0; 301 | border-radius: 5px; 302 | min-width: 100px; 303 | background: var(--button-tooltip-bg); 304 | color: var(--button-tooltip-color); 305 | text-align: center; 306 | display: none; 307 | align-items: center; 308 | justify-content: center; 309 | padding: 0 10px; 310 | } 311 | 312 | &:after { 313 | content: ""; 314 | display: none; 315 | position: absolute; 316 | width: 0; 317 | height: 0; 318 | border-top: 5px solid transparent; 319 | border-bottom: 5px solid transparent; 320 | border-left: 5px solid var(--button-tooltip-bg); 321 | right: 55px; 322 | } 323 | 324 | &:hover:before, 325 | &:hover:after { 326 | display: flex; 327 | } 328 | } 329 | 330 | .ControlsButton--hamburger { 331 | background: var(--primary--light); 332 | color: var(--button-color); 333 | } 334 | 335 | .ControlsButton--hamburgerActive { 336 | background: var(--primary); 337 | color: var(--button-color); 338 | } 339 | 340 | .ControlsButton--zoom { 341 | background: var(--primary--light); 342 | color: var(--button-color); 343 | } 344 | 345 | .ControlsButton--user { 346 | background: var(--primary--light); 347 | color: var(--button-color); 348 | position: relative; 349 | } 350 | .ControlsButton--editMode { 351 | background: var(--button-editMode); 352 | color: var(--button-color); 353 | } 354 | 355 | .ControlsButton--options { 356 | background: var(--primary); 357 | color: var(--button-color); 358 | } 359 | 360 | .ControlsButton--closePreview { 361 | color: var(--close-red); 362 | color: var(--button-color); 363 | background: 0; 364 | border-radius: 50px; 365 | width: 30px; 366 | height: 30px; 367 | } 368 | } 369 | 370 | .Map { 371 | width: 100%; 372 | height: 100%; 373 | position: absolute; 374 | z-index: 1; 375 | } 376 | } 377 | -------------------------------------------------------------------------------- /src/components/Main/Main.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState, useRef } from "react"; 2 | import { 3 | FiMapPin, 4 | FiSettings, 5 | FiMenu, 6 | FiNavigation, 7 | FiCircle, 8 | FiX, 9 | } from "react-icons/fi"; 10 | import classnames from "classnames"; 11 | import Loader from "react-loader-spinner"; 12 | 13 | import { capitalize } from "utils/helpers"; 14 | 15 | import { MODAL_SETTINGS } from "components/Modals/modalTypes"; 16 | 17 | import { IState as SidebarState } from "store/sidebar/reducer"; 18 | import { IState as PathState } from "store/path/reducer"; 19 | import { IState as SearchState } from "store/search/reducer"; 20 | import { IState as GraphState } from "store/graph/reducer"; 21 | import { ProductsApiType } from "store/api/reducer"; 22 | 23 | import { openModal } from "store/modals/actions"; 24 | import { toggleSidebar } from "store/sidebar/actions"; 25 | import { exitPathPreview } from "store/path/actions"; 26 | import { searchProduct } from "store/search/actions"; 27 | import { toggleEditMode } from "store/graph/actions"; 28 | 29 | import Map from "components/Map"; 30 | 31 | import styles from "./Main.module.scss"; 32 | import { fetchProductsAutcompleteApi } from "store/api/api"; 33 | 34 | type AppProps = { 35 | sidebar: SidebarState; 36 | path: PathState; 37 | search: SearchState; 38 | graph: GraphState; 39 | toggleSidebar: typeof toggleSidebar; 40 | openModal: typeof openModal; 41 | exitPathPreview: typeof exitPathPreview; 42 | searchProduct: typeof searchProduct; 43 | toggleEditMode: typeof toggleEditMode; 44 | }; 45 | 46 | function Main(props: AppProps) { 47 | const { 48 | sidebar: { isOpen: isSidebarOpen }, 49 | path: { isPathPreview }, 50 | search: { searchResult }, 51 | graph: { isEditMode }, 52 | toggleSidebar, 53 | openModal, 54 | exitPathPreview, 55 | searchProduct, 56 | toggleEditMode, 57 | } = props; 58 | 59 | const [productPreviewName, setProductPreview] = useState(""); 60 | const [product, setProduct] = useState(""); 61 | 62 | const [isAutocomplete, setIsAutocomplete] = useState(false); 63 | const [isAutocompleteFetching, setIsAutocompleteFetching] = useState(false); 64 | const [searchAutocomplete, setSearchAutocomplete] = useState< 65 | Array 66 | >([]); 67 | 68 | const pathPreviewButton = useRef(null); 69 | const searchInput = useRef(null); 70 | 71 | // TODO - Add a11y keyboard support for autocomplete 72 | 73 | const focusSearchInput = () => { 74 | if (searchInput && searchInput.current) { 75 | searchInput.current.focus(); 76 | } 77 | }; 78 | 79 | const fetchAutocomplete = async (product: string) => { 80 | setIsAutocompleteFetching(true); 81 | const productsData = await fetchProductsAutcompleteApi(product); 82 | setIsAutocompleteFetching(false); 83 | 84 | return productsData; 85 | }; 86 | 87 | const onSearchFocus = (e: React.FocusEvent) => { 88 | e.preventDefault(); 89 | 90 | if (product) { 91 | setIsAutocomplete(true); 92 | } 93 | }; 94 | 95 | const onSearchChange = async (e: React.ChangeEvent) => { 96 | e.preventDefault(); 97 | 98 | const value = e.currentTarget.value; 99 | setProduct(value); 100 | 101 | if (value) { 102 | setIsAutocomplete(true); 103 | const result = await fetchAutocomplete(value); 104 | setSearchAutocomplete(result); 105 | } else { 106 | setIsAutocomplete(false); 107 | } 108 | }; 109 | 110 | const onSearchBlur = (e: React.FocusEvent) => { 111 | e.preventDefault(); 112 | setIsAutocomplete(false); 113 | }; 114 | 115 | const autocompleteInput = (e: React.MouseEvent) => { 116 | const value = e.currentTarget.textContent; 117 | if (searchInput.current && value) { 118 | searchInput.current.value = value; 119 | setProduct(value); 120 | } 121 | }; 122 | 123 | const handleSubmit = (e: React.FormEvent) => { 124 | e.preventDefault(); 125 | 126 | if (isEditMode) { 127 | return false; 128 | } 129 | 130 | searchProduct(product.toLowerCase().trim()); 131 | setIsAutocomplete(false); 132 | 133 | if (pathPreviewButton && pathPreviewButton.current) { 134 | pathPreviewButton.current.focus(); 135 | } 136 | 137 | if (searchInput && searchInput.current) { 138 | searchInput.current.value = ""; 139 | setProduct(""); 140 | } 141 | 142 | return true; 143 | }; 144 | 145 | const toggleEdit = (e: React.MouseEvent) => { 146 | e.preventDefault(); 147 | 148 | if (!isPathPreview) { 149 | toggleEditMode(); 150 | } 151 | }; 152 | 153 | useEffect(() => { 154 | if (searchResult && searchResult.name) { 155 | setProductPreview(capitalize(searchResult.name.toLowerCase())); 156 | } else { 157 | setProductPreview(""); 158 | } 159 | }, [searchResult]); 160 | 161 | return ( 162 |
163 |
164 |
165 |
166 | 176 |
177 |
178 |
182 |
183 | 184 |
185 |
186 | 197 | {isAutocomplete ? ( 198 |
199 | {isAutocompleteFetching ? ( 200 |
201 | 207 |
208 | ) : searchAutocomplete.length ? ( 209 |
    210 | {searchAutocomplete.map((item: ProductsApiType) => ( 211 |
  • 216 | {item.name} 217 |
  • 218 | ))} 219 |
220 | ) : ( 221 |

222 | Brak rezultatów 223 |

224 | )} 225 |
226 | ) : null} 227 |
228 | 238 |
239 |
245 |
246 |

247 | {productPreviewName} 248 |

249 |
250 | 264 |
265 |
266 |
267 |
268 |
269 |
270 | 284 | 297 |
298 |
299 |
300 |
301 | 302 |
303 |
304 | ); 305 | } 306 | 307 | export default Main; 308 | -------------------------------------------------------------------------------- /src/components/Main/__tests__/Main.test.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { render } from "@testing-library/react"; 3 | 4 | import { Provider } from "react-redux"; 5 | import store from "store"; 6 | 7 | import Main from "components/Main"; 8 | 9 | describe("Main.tsx", () => { 10 | it("should render component", () => { 11 | render( 12 | 13 |
14 | 15 | ); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/components/Main/index.ts: -------------------------------------------------------------------------------- 1 | import { compose } from "redux"; 2 | import { connect } from "react-redux"; 3 | 4 | import { toggleSidebar } from "store/sidebar/actions"; 5 | import { openModal } from "store/modals/actions"; 6 | import { exitPathPreview } from "store/path/actions"; 7 | import { searchProduct } from "store/search/actions"; 8 | import { toggleEditMode } from "store/graph/actions"; 9 | 10 | import { AppState } from "store/rootReducer"; 11 | 12 | import Main from "./Main"; 13 | 14 | const mapStateToProps = ({ sidebar, path, search, graph }: AppState) => ({ 15 | sidebar, 16 | path, 17 | search, 18 | graph, 19 | }); 20 | 21 | const mapDispatchToProps = { 22 | toggleSidebar, 23 | openModal, 24 | exitPathPreview, 25 | searchProduct, 26 | toggleEditMode, 27 | }; 28 | 29 | const enhancer = compose(connect(mapStateToProps, mapDispatchToProps)); 30 | 31 | export default enhancer(Main); 32 | -------------------------------------------------------------------------------- /src/components/Map/Map.module.scss: -------------------------------------------------------------------------------- 1 | @import "styles/themes.scss"; 2 | 3 | .Map { 4 | width: 100%; 5 | height: 100%; 6 | display: flex; 7 | align-items: center; 8 | justify-content: center; 9 | } 10 | -------------------------------------------------------------------------------- /src/components/Map/Map.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import { gsap } from "gsap"; 3 | import Loader from "react-loader-spinner"; 4 | 5 | import FloorMapSvg from "components/FloorMapSvg"; 6 | import { IState as GraphState } from "store/graph/reducer"; 7 | import { IState as PathState } from "store/path/reducer"; 8 | import { IState as SearchState } from "store/search/reducer"; 9 | import { getPath } from "store/path/actions"; 10 | 11 | import Edge from "algorithms/graph/Edge"; 12 | 13 | import styles from "./Map.module.scss"; 14 | 15 | type AppProps = { 16 | graph: GraphState; 17 | path: PathState; 18 | search: SearchState; 19 | getPath: typeof getPath; 20 | }; 21 | 22 | function Map(props: AppProps) { 23 | const { 24 | graph: { isGenerating: isGraphGenerating, isEditMode, startVertex }, 25 | path: { 26 | isGenerating: isPathGenerating, 27 | pathTimeline, 28 | dijkstra: { vertices: pathVertices, edges: pathEdges }, 29 | }, 30 | } = props; 31 | 32 | const verticesRefs = React.useRef<{ [key: string]: SVGElement }>({}); 33 | const edgesRefs = React.useRef<{ [key: string]: SVGElement }>({}); 34 | const objectsRefs = React.useRef<{ [key: string]: SVGElement }>({}); 35 | 36 | useEffect(() => { 37 | if (pathTimeline && pathEdges && pathEdges.length) { 38 | pathEdges.forEach((edge: Edge) => { 39 | let key: string; 40 | 41 | if (edge.getKey() in edgesRefs.current) { 42 | key = edge.getKey(); 43 | } else { 44 | key = edge.getReverseKey(); 45 | } 46 | 47 | pathTimeline.to(edgesRefs.current[key], { 48 | opacity: 1, 49 | duration: 0.03, 50 | }); 51 | }); 52 | 53 | const lastVertex = pathVertices[pathVertices.length - 1]; 54 | 55 | // Adding 56 | if (objectsRefs && lastVertex.options && lastVertex.options.objectId) { 57 | const mapObject = objectsRefs.current[lastVertex.options.objectId]; 58 | 59 | pathTimeline.to(mapObject, { 60 | duration: 0.03, 61 | onComplete: () => { 62 | mapObject.classList.add("Object--active"); 63 | }, 64 | }); 65 | } 66 | 67 | pathTimeline.resume(); 68 | } 69 | }, [pathEdges, pathVertices, pathTimeline]); 70 | 71 | useEffect(() => { 72 | if (isEditMode) { 73 | Object.keys(verticesRefs.current).forEach((key) => { 74 | if (key !== startVertex) { 75 | gsap.to(verticesRefs.current[key], { opacity: 1, cursor: "pointer" }); 76 | } 77 | }); 78 | } else { 79 | Object.keys(verticesRefs.current).forEach((key) => { 80 | if (key !== startVertex) { 81 | gsap.to(verticesRefs.current[key], { opacity: 0 }); 82 | } 83 | }); 84 | } 85 | }, [isEditMode, startVertex]); 86 | 87 | const vertexRefCallback = (el: SVGElement | null) => { 88 | if (el && el.dataset.vertexKey) { 89 | let key = el.dataset.vertexKey.trim().toLowerCase(); 90 | verticesRefs.current[key] = el; 91 | } 92 | }; 93 | 94 | const objectRefCallback = (el: SVGElement | null) => { 95 | if (el && el.dataset.objectKey) { 96 | let key = el.dataset.objectKey.trim().toLowerCase(); 97 | objectsRefs.current[key] = el; 98 | } 99 | }; 100 | 101 | const edgeRefCallback = (el: SVGElement | null) => { 102 | if (el && el.dataset.edgeKey) { 103 | let key = el.dataset.edgeKey.trim().toLowerCase(); 104 | edgesRefs.current[key] = el; 105 | } 106 | }; 107 | 108 | return isGraphGenerating || isPathGenerating ? ( 109 |
110 | 111 |
112 | ) : ( 113 |
114 | 119 |
120 | ); 121 | } 122 | 123 | export default Map; 124 | -------------------------------------------------------------------------------- /src/components/Map/__tests__/Map.test.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { render } from "@testing-library/react"; 3 | 4 | import { Provider } from "react-redux"; 5 | import store from "store"; 6 | 7 | import Map from "components/Map"; 8 | 9 | describe("Map.tsx", () => { 10 | it("should render component", () => { 11 | render( 12 | 13 | 14 | 15 | ); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/components/Map/index.ts: -------------------------------------------------------------------------------- 1 | import { compose } from "redux"; 2 | import { connect } from "react-redux"; 3 | 4 | import { getPath } from "store/path/actions"; 5 | 6 | import { AppState } from "store/rootReducer"; 7 | 8 | import Map from "./Map"; 9 | 10 | const mapStateToProps = ({ graph, path, search }: AppState) => ({ 11 | graph, 12 | path, 13 | search, 14 | }); 15 | 16 | const mapDispatchToProps = { 17 | getPath, 18 | }; 19 | 20 | const enhancer = compose(connect(mapStateToProps, mapDispatchToProps)); 21 | 22 | export default enhancer(Map); 23 | -------------------------------------------------------------------------------- /src/components/Map/mapData.ts: -------------------------------------------------------------------------------- 1 | export type vertexData = { 2 | key: string; 3 | options: { 4 | ref?: string | null; 5 | objectId?: string; 6 | }; 7 | }; 8 | 9 | export type edgeData = { 10 | key: string; 11 | weight: number; 12 | }; 13 | 14 | export type objectData = { 15 | key: string; 16 | ref: string; 17 | }; 18 | 19 | export type mapData = { 20 | v: { [key: string]: vertexData }; 21 | e: { [key: string]: edgeData }; 22 | o: { [key: string]: objectData }; 23 | }; 24 | 25 | export const mapData = { 26 | v: { 27 | v_1: { 28 | key: "v_1", 29 | options: { 30 | ref: null, 31 | }, 32 | }, 33 | v_2: { 34 | key: "v_2", 35 | options: { 36 | ref: null, 37 | objectId: "o_17", 38 | }, 39 | }, 40 | v_3: { 41 | key: "v_3", 42 | options: { 43 | ref: null, 44 | objectId: "o_29", 45 | }, 46 | }, 47 | v_4: { 48 | key: "v_4", 49 | options: { 50 | ref: null, 51 | }, 52 | }, 53 | v_5: { 54 | key: "v_5", 55 | options: { 56 | ref: null, 57 | }, 58 | }, 59 | v_6: { 60 | key: "v_6", 61 | options: { 62 | ref: null, 63 | objectId: "o_7", 64 | }, 65 | }, 66 | v_7: { 67 | key: "v_7", 68 | options: { 69 | ref: null, 70 | }, 71 | }, 72 | v_8: { 73 | key: "v_8", 74 | options: { 75 | ref: null, 76 | }, 77 | }, 78 | v_9: { 79 | key: "v_9", 80 | options: { 81 | ref: null, 82 | objectId: "o_8", 83 | }, 84 | }, 85 | v_10: { 86 | key: "v_10", 87 | options: { 88 | ref: null, 89 | objectId: "o_2", 90 | }, 91 | }, 92 | v_11: { 93 | key: "v_11", 94 | options: { 95 | ref: null, 96 | }, 97 | }, 98 | v_12: { 99 | key: "v_12", 100 | options: { 101 | ref: null, 102 | objectId: "o_22", 103 | }, 104 | }, 105 | v_13: { 106 | key: "v_13", 107 | options: { 108 | ref: null, 109 | }, 110 | }, 111 | v_14: { 112 | key: "v_14", 113 | options: { 114 | ref: null, 115 | objectId: "o_4", 116 | }, 117 | }, 118 | v_15: { 119 | key: "v_15", 120 | options: { 121 | ref: null, 122 | }, 123 | }, 124 | v_16: { 125 | key: "v_16", 126 | options: { 127 | ref: null, 128 | objectId: "o_31", 129 | }, 130 | }, 131 | v_17: { 132 | key: "v_17", 133 | options: { 134 | ref: null, 135 | }, 136 | }, 137 | v_18: { 138 | key: "v_18", 139 | options: { 140 | ref: null, 141 | objectId: "o_23", 142 | }, 143 | }, 144 | v_19: { 145 | key: "v_19", 146 | options: { 147 | ref: null, 148 | }, 149 | }, 150 | v_20: { 151 | key: "v_20", 152 | options: { 153 | ref: null, 154 | }, 155 | }, 156 | v_21: { 157 | key: "v_21", 158 | options: { 159 | ref: null, 160 | }, 161 | }, 162 | v_22: { 163 | key: "v_22", 164 | options: { 165 | ref: null, 166 | objectId: "o_39", 167 | }, 168 | }, 169 | v_23: { 170 | key: "v_23", 171 | options: { 172 | ref: null, 173 | objectId: "o_13", 174 | }, 175 | }, 176 | v_24: { 177 | key: "v_24", 178 | options: { 179 | ref: null, 180 | }, 181 | }, 182 | v_25: { 183 | key: "v_25", 184 | options: { 185 | ref: null, 186 | objectId: "o_32", 187 | }, 188 | }, 189 | v_26: { 190 | key: "v_26", 191 | options: { 192 | ref: null, 193 | }, 194 | }, 195 | v_27: { 196 | key: "v_27", 197 | options: { 198 | ref: null, 199 | objectId: "o_15", 200 | }, 201 | }, 202 | v_28: { 203 | key: "v_28", 204 | options: { 205 | ref: null, 206 | objectId: "o_16", 207 | }, 208 | }, 209 | v_29: { 210 | key: "v_29", 211 | options: { 212 | ref: null, 213 | }, 214 | }, 215 | v_30: { 216 | key: "v_30", 217 | options: { 218 | ref: null, 219 | }, 220 | }, 221 | v_31: { 222 | key: "v_31", 223 | options: { 224 | ref: null, 225 | }, 226 | }, 227 | v_32: { 228 | key: "v_32", 229 | options: { 230 | ref: null, 231 | objectId: "o_18", 232 | }, 233 | }, 234 | v_33: { 235 | key: "v_33", 236 | options: { 237 | ref: null, 238 | }, 239 | }, 240 | v_34: { 241 | key: "v_34", 242 | options: { 243 | ref: null, 244 | }, 245 | }, 246 | v_35: { 247 | key: "v_35", 248 | options: { 249 | ref: null, 250 | objectId: "o_41", 251 | }, 252 | }, 253 | v_36: { 254 | key: "v_36", 255 | options: { 256 | ref: null, 257 | }, 258 | }, 259 | v_37: { 260 | key: "v_37", 261 | options: { 262 | ref: null, 263 | objectId: "o_20", 264 | }, 265 | }, 266 | v_38: { 267 | key: "v_38", 268 | options: { 269 | ref: null, 270 | }, 271 | }, 272 | v_39: { 273 | key: "v_39", 274 | options: { 275 | ref: null, 276 | objectId: "o_21", 277 | }, 278 | }, 279 | v_40: { 280 | key: "v_40", 281 | options: { 282 | ref: null, 283 | objectId: "o_19", 284 | }, 285 | }, 286 | v_41: { 287 | key: "v_41", 288 | options: { 289 | ref: null, 290 | }, 291 | }, 292 | v_42: { 293 | key: "v_42", 294 | options: { 295 | ref: null, 296 | }, 297 | }, 298 | v_43: { 299 | key: "v_43", 300 | options: { 301 | ref: null, 302 | }, 303 | }, 304 | v_44: { 305 | key: "v_44", 306 | options: { 307 | ref: null, 308 | }, 309 | }, 310 | v_45: { 311 | key: "v_45", 312 | options: { 313 | ref: null, 314 | }, 315 | }, 316 | v_46: { 317 | key: "v_46", 318 | options: { 319 | ref: null, 320 | objectId: "o_28", 321 | }, 322 | }, 323 | v_47: { 324 | key: "v_47", 325 | options: { 326 | ref: null, 327 | }, 328 | }, 329 | v_48: { 330 | key: "v_48", 331 | options: { 332 | ref: null, 333 | objectId: "o_33", 334 | }, 335 | }, 336 | v_49: { 337 | key: "v_49", 338 | options: { 339 | ref: null, 340 | objectId: "o_34", 341 | }, 342 | }, 343 | v_50: { 344 | key: "v_50", 345 | options: { 346 | ref: null, 347 | objectId: "o_30", 348 | }, 349 | }, 350 | v_51: { 351 | key: "v_51", 352 | options: { 353 | ref: null, 354 | }, 355 | }, 356 | v_52: { 357 | key: "v_52", 358 | options: { 359 | ref: null, 360 | }, 361 | }, 362 | v_53: { 363 | key: "v_53", 364 | options: { 365 | ref: null, 366 | }, 367 | }, 368 | v_54: { 369 | key: "v_54", 370 | options: { 371 | ref: null, 372 | objectId: "o_26", 373 | }, 374 | }, 375 | v_55: { 376 | key: "v_55", 377 | options: { 378 | ref: null, 379 | }, 380 | }, 381 | v_56: { 382 | key: "v_56", 383 | options: { 384 | ref: null, 385 | }, 386 | }, 387 | v_57: { 388 | key: "v_57", 389 | options: { 390 | ref: null, 391 | objectId: "o_25", 392 | }, 393 | }, 394 | v_58: { 395 | key: "v_58", 396 | options: { 397 | ref: null, 398 | }, 399 | }, 400 | v_59: { 401 | key: "v_59", 402 | options: { 403 | ref: null, 404 | objectId: "o_36", 405 | }, 406 | }, 407 | v_60: { 408 | key: "v_60", 409 | options: { 410 | ref: null, 411 | objectId: "o_27", 412 | }, 413 | }, 414 | v_61: { 415 | key: "v_61", 416 | options: { 417 | ref: null, 418 | }, 419 | }, 420 | v_62: { 421 | key: "v_62", 422 | options: { 423 | ref: null, 424 | }, 425 | }, 426 | v_63: { 427 | key: "v_63", 428 | options: { 429 | ref: null, 430 | objectId: "o_38", 431 | }, 432 | }, 433 | v_64: { 434 | key: "v_64", 435 | options: { 436 | ref: null, 437 | }, 438 | }, 439 | v_65: { 440 | key: "v_65", 441 | options: { 442 | ref: null, 443 | }, 444 | }, 445 | v_66: { 446 | key: "v_66", 447 | options: { 448 | ref: null, 449 | }, 450 | }, 451 | v_67: { 452 | key: "v_67", 453 | options: { 454 | ref: null, 455 | }, 456 | }, 457 | v_68: { 458 | key: "v_68", 459 | options: { 460 | ref: null, 461 | objectId: "o_6", 462 | }, 463 | }, 464 | v_69: { 465 | key: "v_69", 466 | options: { 467 | ref: null, 468 | }, 469 | }, 470 | v_70: { 471 | key: "v_70", 472 | options: { 473 | ref: null, 474 | objectId: "o_14", 475 | }, 476 | }, 477 | v_71: { 478 | key: "v_71", 479 | options: { 480 | ref: null, 481 | objectId: "o_24", 482 | }, 483 | }, 484 | v_72: { 485 | key: "v_72", 486 | options: { 487 | ref: null, 488 | }, 489 | }, 490 | v_73: { 491 | key: "v_73", 492 | options: { 493 | ref: null, 494 | objectId: "o_9", 495 | }, 496 | }, 497 | v_74: { 498 | key: "v_74", 499 | options: { 500 | ref: null, 501 | }, 502 | }, 503 | v_75: { 504 | key: "v_75", 505 | options: { 506 | ref: null, 507 | }, 508 | }, 509 | v_76: { 510 | key: "v_76", 511 | options: { 512 | ref: null, 513 | objectId: "o_3", 514 | }, 515 | }, 516 | v_77: { 517 | key: "v_77", 518 | options: { 519 | ref: null, 520 | objectId: "o_10", 521 | }, 522 | }, 523 | v_78: { 524 | key: "v_78", 525 | options: { 526 | ref: null, 527 | objectId: "o_40", 528 | }, 529 | }, 530 | v_79: { 531 | key: "v_79", 532 | options: { 533 | ref: null, 534 | }, 535 | }, 536 | v_80: { 537 | key: "v_80", 538 | options: { 539 | ref: "o_42", 540 | }, 541 | }, 542 | v_81: { 543 | key: "v_81", 544 | options: { 545 | ref: null, 546 | }, 547 | }, 548 | v_82: { 549 | key: "v_82", 550 | options: { 551 | ref: null, 552 | }, 553 | }, 554 | v_83: { 555 | key: "v_83", 556 | options: { 557 | ref: null, 558 | objectId: "o_35", 559 | }, 560 | }, 561 | v_84: { 562 | key: "v_84", 563 | options: { 564 | ref: null, 565 | }, 566 | }, 567 | v_85: { 568 | key: "v_85", 569 | options: { 570 | ref: null, 571 | objectId: "o_37", 572 | }, 573 | }, 574 | v_86: { 575 | key: "v_86", 576 | options: { 577 | ref: null, 578 | }, 579 | }, 580 | v_87: { 581 | key: "v_87", 582 | options: { 583 | ref: null, 584 | objectId: "o_11", 585 | }, 586 | }, 587 | v_88: { 588 | key: "v_88", 589 | options: { 590 | ref: null, 591 | objectId: "o_5", 592 | }, 593 | }, 594 | v_89: { 595 | key: "v_89", 596 | options: { 597 | ref: null, 598 | }, 599 | }, 600 | v_90: { 601 | key: "v_90", 602 | options: { 603 | ref: null, 604 | objectId: "o_1", 605 | }, 606 | }, 607 | v_91: { 608 | key: "v_91", 609 | options: { 610 | ref: null, 611 | }, 612 | }, 613 | v_92: { 614 | key: "v_92", 615 | options: { 616 | ref: null, 617 | objectId: "o_43", 618 | }, 619 | }, 620 | v_93: { 621 | key: "v_93", 622 | options: { 623 | ref: null, 624 | objectId: "o_12", 625 | }, 626 | }, 627 | v_94: { 628 | key: "v_94", 629 | options: { 630 | ref: null, 631 | }, 632 | }, 633 | v_95: { 634 | key: "v_95", 635 | options: { 636 | ref: null, 637 | }, 638 | }, 639 | v_96: { 640 | key: "v_96", 641 | options: { 642 | ref: null, 643 | }, 644 | }, 645 | }, 646 | 647 | e: { 648 | v_96__v_79: { 649 | key: "v_96__v_79", 650 | weight: 1, 651 | }, 652 | v_79__v_75: { 653 | key: "v_79__v_75", 654 | weight: 1, 655 | }, 656 | v_69__v_67: { 657 | key: "v_69__v_67", 658 | weight: 1, 659 | }, 660 | v_72__v_71: { 661 | key: "v_72__v_71", 662 | weight: 1, 663 | }, 664 | v_29__v_28: { 665 | key: "v_29__v_28", 666 | weight: 1, 667 | }, 668 | v_26__v_27: { 669 | key: "v_26__v_27", 670 | weight: 1, 671 | }, 672 | v_26__v_25: { 673 | key: "v_26__v_25", 674 | weight: 1, 675 | }, 676 | v_74__v_70: { 677 | key: "v_74__v_70", 678 | weight: 1, 679 | }, 680 | v_74__v_73: { 681 | key: "v_74__v_73", 682 | weight: 1, 683 | }, 684 | v_15__v_14: { 685 | key: "v_15__v_14", 686 | weight: 1, 687 | }, 688 | v_19__v_18: { 689 | key: "v_19__v_18", 690 | weight: 1, 691 | }, 692 | v_17__v_16: { 693 | key: "v_17__v_16", 694 | weight: 1, 695 | }, 696 | v_4__v_3: { 697 | key: "v_4__v_3", 698 | weight: 1, 699 | }, 700 | v_4__v_2: { 701 | key: "v_4__v_2", 702 | weight: 1, 703 | }, 704 | v_13__v_12: { 705 | key: "v_13__v_12", 706 | weight: 1, 707 | }, 708 | v_69__v_68: { 709 | key: "v_69__v_68", 710 | weight: 1, 711 | }, 712 | v_24__v_21: { 713 | key: "v_24__v_21", 714 | weight: 1, 715 | }, 716 | v_45__v_24: { 717 | key: "v_45__v_24", 718 | weight: 1, 719 | }, 720 | v_44__v_45: { 721 | key: "v_44__v_45", 722 | weight: 1, 723 | }, 724 | v_44__v_53: { 725 | key: "v_44__v_53", 726 | weight: 1, 727 | }, 728 | v_81__v_53: { 729 | key: "v_81__v_53", 730 | weight: 1, 731 | }, 732 | v_82__v_81: { 733 | key: "v_82__v_81", 734 | weight: 1, 735 | }, 736 | v_36__v_34: { 737 | key: "v_36__v_34", 738 | weight: 1, 739 | }, 740 | v_42__v_36: { 741 | key: "v_42__v_36", 742 | weight: 1, 743 | }, 744 | v_33__v_32: { 745 | key: "v_33__v_32", 746 | weight: 1, 747 | }, 748 | v_41__v_40: { 749 | key: "v_41__v_40", 750 | weight: 1, 751 | }, 752 | v_41__v_39: { 753 | key: "v_41__v_39", 754 | weight: 1, 755 | }, 756 | v_38__v_37: { 757 | key: "v_38__v_37", 758 | weight: 1, 759 | }, 760 | v_42__v_43: { 761 | key: "v_42__v_43", 762 | weight: 1, 763 | }, 764 | v_43__v_1: { 765 | key: "v_43__v_1", 766 | weight: 1, 767 | }, 768 | v_20__v_1: { 769 | key: "v_20__v_1", 770 | weight: 1, 771 | }, 772 | v_8__v_5: { 773 | key: "v_8__v_5", 774 | weight: 1, 775 | }, 776 | v_5__v_7: { 777 | key: "v_5__v_7", 778 | weight: 1, 779 | }, 780 | v_7__v_31: { 781 | key: "v_7__v_31", 782 | weight: 1, 783 | }, 784 | v_20__v_15: { 785 | key: "v_20__v_15", 786 | weight: 1, 787 | }, 788 | v_11__v_8: { 789 | key: "v_11__v_8", 790 | weight: 1, 791 | }, 792 | v_67__v_66: { 793 | key: "v_67__v_66", 794 | weight: 1, 795 | }, 796 | v_51__v_50: { 797 | key: "v_51__v_50", 798 | weight: 1, 799 | }, 800 | v_47__v_46: { 801 | key: "v_47__v_46", 802 | weight: 1, 803 | }, 804 | v_55__v_54: { 805 | key: "v_55__v_54", 806 | weight: 1, 807 | }, 808 | v_30__v_48: { 809 | key: "v_30__v_48", 810 | weight: 1, 811 | }, 812 | v_52__v_49: { 813 | key: "v_52__v_49", 814 | weight: 1, 815 | }, 816 | v_65__v_66: { 817 | key: "v_65__v_66", 818 | weight: 1, 819 | }, 820 | v_65__v_56: { 821 | key: "v_65__v_56", 822 | weight: 1, 823 | }, 824 | v_56__v_64: { 825 | key: "v_56__v_64", 826 | weight: 1, 827 | }, 828 | v_62__v_64: { 829 | key: "v_62__v_64", 830 | weight: 1, 831 | }, 832 | v_89__v_62: { 833 | key: "v_89__v_62", 834 | weight: 1, 835 | }, 836 | v_89__v_88: { 837 | key: "v_89__v_88", 838 | weight: 1, 839 | }, 840 | v_86__v_85: { 841 | key: "v_86__v_85", 842 | weight: 1, 843 | }, 844 | v_83__v_84: { 845 | key: "v_83__v_84", 846 | weight: 1, 847 | }, 848 | v_84__v_87: { 849 | key: "v_84__v_87", 850 | weight: 1, 851 | }, 852 | v_61__v_59: { 853 | key: "v_61__v_59", 854 | weight: 1, 855 | }, 856 | v_58__v_57: { 857 | key: "v_58__v_57", 858 | weight: 1, 859 | }, 860 | v_61__v_60: { 861 | key: "v_61__v_60", 862 | weight: 1, 863 | }, 864 | v_91__v_94: { 865 | key: "v_91__v_94", 866 | weight: 1, 867 | }, 868 | v_91__v_90: { 869 | key: "v_91__v_90", 870 | weight: 1, 871 | }, 872 | v_96__v_94: { 873 | key: "v_96__v_94", 874 | weight: 1, 875 | }, 876 | v_75__v_69: { 877 | key: "v_75__v_69", 878 | weight: 1, 879 | }, 880 | v_75__v_76: { 881 | key: "v_75__v_76", 882 | weight: 1, 883 | }, 884 | v_96__v_65: { 885 | key: "v_96__v_65", 886 | weight: 1, 887 | }, 888 | v_64__v_63: { 889 | key: "v_64__v_63", 890 | weight: 1, 891 | }, 892 | v_92__v_94: { 893 | key: "v_92__v_94", 894 | weight: 1, 895 | }, 896 | v_94__v_93: { 897 | key: "v_94__v_93", 898 | weight: 1, 899 | }, 900 | v_95__v_96: { 901 | key: "v_95__v_96", 902 | weight: 1, 903 | }, 904 | v_52__v_66: { 905 | key: "v_52__v_66", 906 | weight: 1, 907 | }, 908 | v_30__v_67: { 909 | key: "v_30__v_67", 910 | weight: 1, 911 | }, 912 | v_79__v_78: { 913 | key: "v_79__v_78", 914 | weight: 1, 915 | }, 916 | v_79__v_77: { 917 | key: "v_79__v_77", 918 | weight: 1, 919 | }, 920 | v_29__v_30: { 921 | key: "v_29__v_30", 922 | weight: 1, 923 | }, 924 | v_26__v_29: { 925 | key: "v_26__v_29", 926 | weight: 1, 927 | }, 928 | v_24__v_26: { 929 | key: "v_24__v_26", 930 | weight: 1, 931 | }, 932 | v_24__v_23: { 933 | key: "v_24__v_23", 934 | weight: 1, 935 | }, 936 | v_20__v_22: { 937 | key: "v_20__v_22", 938 | weight: 1, 939 | }, 940 | v_51__v_52: { 941 | key: "v_51__v_52", 942 | weight: 1, 943 | }, 944 | v_47__v_51: { 945 | key: "v_47__v_51", 946 | weight: 1, 947 | }, 948 | v_45__v_47: { 949 | key: "v_45__v_47", 950 | weight: 1, 951 | }, 952 | v_55__v_53: { 953 | key: "v_55__v_53", 954 | weight: 1, 955 | }, 956 | v_81__v_58: { 957 | key: "v_81__v_58", 958 | weight: 1, 959 | }, 960 | v_81__v_80: { 961 | key: "v_81__v_80", 962 | weight: 1, 963 | }, 964 | v_58__v_61: { 965 | key: "v_58__v_61", 966 | weight: 1, 967 | }, 968 | v_61__v_62: { 969 | key: "v_61__v_62", 970 | weight: 1, 971 | }, 972 | v_86__v_89: { 973 | key: "v_86__v_89", 974 | weight: 1, 975 | }, 976 | v_84__v_86: { 977 | key: "v_84__v_86", 978 | weight: 1, 979 | }, 980 | v_82__v_84: { 981 | key: "v_82__v_84", 982 | weight: 1, 983 | }, 984 | v_34__v_82: { 985 | key: "v_34__v_82", 986 | weight: 1, 987 | }, 988 | v_89__v_91: { 989 | key: "v_89__v_91", 990 | weight: 1, 991 | }, 992 | v_56__v_55: { 993 | key: "v_56__v_55", 994 | weight: 1, 995 | }, 996 | v_69__v_72: { 997 | key: "v_69__v_72", 998 | weight: 1, 999 | }, 1000 | v_72__v_74: { 1001 | key: "v_72__v_74", 1002 | weight: 1, 1003 | }, 1004 | v_74__v_21: { 1005 | key: "v_74__v_21", 1006 | weight: 1, 1007 | }, 1008 | v_21__v_15: { 1009 | key: "v_21__v_15", 1010 | weight: 1, 1011 | }, 1012 | v_19__v_20: { 1013 | key: "v_19__v_20", 1014 | weight: 1, 1015 | }, 1016 | v_17__v_19: { 1017 | key: "v_17__v_19", 1018 | weight: 1, 1019 | }, 1020 | v_8__v_17: { 1021 | key: "v_8__v_17", 1022 | weight: 1, 1023 | }, 1024 | v_4__v_5: { 1025 | key: "v_4__v_5", 1026 | weight: 1, 1027 | }, 1028 | v_7__v_6: { 1029 | key: "v_7__v_6", 1030 | weight: 1, 1031 | }, 1032 | v_1__v_4: { 1033 | key: "v_1__v_4", 1034 | weight: 1, 1035 | }, 1036 | v_41__v_42: { 1037 | key: "v_41__v_42", 1038 | weight: 1, 1039 | }, 1040 | v_36__v_33: { 1041 | key: "v_36__v_33", 1042 | weight: 1, 1043 | }, 1044 | v_36__v_35: { 1045 | key: "v_36__v_35", 1046 | weight: 1, 1047 | }, 1048 | v_38__v_41: { 1049 | key: "v_38__v_41", 1050 | weight: 1, 1051 | }, 1052 | v_31__v_38: { 1053 | key: "v_31__v_38", 1054 | weight: 1, 1055 | }, 1056 | v_43__v_44: { 1057 | key: "v_43__v_44", 1058 | weight: 1, 1059 | }, 1060 | v_15__v_13: { 1061 | key: "v_15__v_13", 1062 | weight: 1, 1063 | }, 1064 | v_13__v_11: { 1065 | key: "v_13__v_11", 1066 | weight: 1, 1067 | }, 1068 | v_11__v_10: { 1069 | key: "v_11__v_10", 1070 | weight: 1, 1071 | }, 1072 | v_8__v_9: { 1073 | key: "v_8__v_9", 1074 | weight: 1, 1075 | }, 1076 | }, 1077 | 1078 | o: { 1079 | o_1: { 1080 | key: "o_1", 1081 | ref: "v_90", 1082 | }, 1083 | o_2: { 1084 | key: "o_2", 1085 | ref: "v_10", 1086 | }, 1087 | o_3: { 1088 | key: "o_3", 1089 | ref: "v_76", 1090 | }, 1091 | o_4: { 1092 | key: "o_4", 1093 | ref: "v_14", 1094 | }, 1095 | o_5: { 1096 | key: "o_5", 1097 | ref: "v_88", 1098 | }, 1099 | o_6: { 1100 | key: "o_6", 1101 | ref: "v_68", 1102 | }, 1103 | o_7: { 1104 | key: "o_7", 1105 | ref: "v_6", 1106 | }, 1107 | o_8: { 1108 | key: "o_8", 1109 | ref: "v_9", 1110 | }, 1111 | o_9: { 1112 | key: "o_9", 1113 | ref: "v_73", 1114 | }, 1115 | o_10: { 1116 | key: "o_10", 1117 | ref: "v_77", 1118 | }, 1119 | o_11: { 1120 | key: "o_11", 1121 | ref: "v_87", 1122 | }, 1123 | o_12: { 1124 | key: "o_12", 1125 | ref: "v_93", 1126 | }, 1127 | o_13: { 1128 | key: "o_13", 1129 | ref: "v_23", 1130 | }, 1131 | o_14: { 1132 | key: "o_14", 1133 | ref: "v_70", 1134 | }, 1135 | o_15: { 1136 | key: "o_15", 1137 | ref: "v_27", 1138 | }, 1139 | o_16: { 1140 | key: "o_16", 1141 | ref: "v_28", 1142 | }, 1143 | o_17: { 1144 | key: "o_17", 1145 | ref: "v_2", 1146 | }, 1147 | o_18: { 1148 | key: "o_18", 1149 | ref: "v_32", 1150 | }, 1151 | o_19: { 1152 | key: "o_19", 1153 | ref: "v_40", 1154 | }, 1155 | o_20: { 1156 | key: "o_20", 1157 | ref: "v_37", 1158 | }, 1159 | o_21: { 1160 | key: "o_21", 1161 | ref: "v_39", 1162 | }, 1163 | o_22: { 1164 | key: "o_22", 1165 | ref: "v_12", 1166 | }, 1167 | o_23: { 1168 | key: "o_23", 1169 | ref: "v_18", 1170 | }, 1171 | o_24: { 1172 | key: "o_24", 1173 | ref: "v_71", 1174 | }, 1175 | o_25: { 1176 | key: "o_25", 1177 | ref: "v_57", 1178 | }, 1179 | o_26: { 1180 | key: "o_26", 1181 | ref: "v_54", 1182 | }, 1183 | o_27: { 1184 | key: "o_27", 1185 | ref: "v_60", 1186 | }, 1187 | o_28: { 1188 | key: "o_28", 1189 | ref: "v_46", 1190 | }, 1191 | o_29: { 1192 | key: "o_29", 1193 | ref: "v_3", 1194 | }, 1195 | o_30: { 1196 | key: "o_30", 1197 | ref: "v_50", 1198 | }, 1199 | o_31: { 1200 | key: "o_31", 1201 | ref: "v_16", 1202 | }, 1203 | o_32: { 1204 | key: "o_32", 1205 | ref: "v_25", 1206 | }, 1207 | o_33: { 1208 | key: "o_33", 1209 | ref: "v_48", 1210 | }, 1211 | o_34: { 1212 | key: "o_34", 1213 | ref: "v_49", 1214 | }, 1215 | o_35: { 1216 | key: "o_35", 1217 | ref: "v_83", 1218 | }, 1219 | o_36: { 1220 | key: "o_36", 1221 | ref: "v_59", 1222 | }, 1223 | o_37: { 1224 | key: "o_37", 1225 | ref: "v_85", 1226 | }, 1227 | o_38: { 1228 | key: "o_38", 1229 | ref: "v_63", 1230 | }, 1231 | o_39: { 1232 | key: "o_39", 1233 | ref: "v_22", 1234 | }, 1235 | o_40: { 1236 | key: "o_40", 1237 | ref: "v_78", 1238 | }, 1239 | o_41: { 1240 | key: "o_41", 1241 | ref: "v_35", 1242 | }, 1243 | o_42: { 1244 | key: "o_42", 1245 | ref: "v_80", 1246 | }, 1247 | o_43: { 1248 | key: "o_43", 1249 | ref: "v_92", 1250 | }, 1251 | }, 1252 | }; 1253 | -------------------------------------------------------------------------------- /src/components/Modals/ModalObjectInfo/ModalObjectInfo.module.scss: -------------------------------------------------------------------------------- 1 | @import "styles/themes.scss"; 2 | 3 | .Modal--objectInfo { 4 | width: 400px; 5 | max-height: 500px; 6 | padding: 30px 30px; 7 | border-radius: 7px; 8 | background: var(--modal-bg); 9 | outline: 0; 10 | overflow: hidden; 11 | } 12 | 13 | .ModalLoader { 14 | display: flex; 15 | align-items: center; 16 | justify-content: center; 17 | } 18 | 19 | .ObjectHeader { 20 | .ObjectHeader-title { 21 | font-weight: 600; 22 | font-size: 2rem; 23 | text-transform: capitalize; 24 | text-align: center; 25 | color: var(--modal-text); 26 | 27 | &:after { 28 | content: ""; 29 | display: block; 30 | width: 50px; 31 | height: 2px; 32 | background: var(--primary); 33 | margin: 20px auto 0px; 34 | } 35 | } 36 | } 37 | 38 | .ObjectBody { 39 | .Object-emptyList { 40 | text-align: center; 41 | font-size: 1.2rem; 42 | padding-top: 20px; 43 | color: var(--modal-text-light); 44 | } 45 | 46 | .ObjectList { 47 | list-style-position: inside; 48 | overflow-y: scroll; 49 | max-height: 400px; 50 | padding-right: 20px; 51 | list-style-type: none; 52 | 53 | .ObjectList-item { 54 | padding: 20px 0; 55 | display: flex; 56 | align-items: center; 57 | justify-content: space-between; 58 | 59 | .ObjectList-itemInfo { 60 | color: var(--modal-text); 61 | 62 | .ObjectList-itemTitle { 63 | padding-bottom: 5px; 64 | color: var(--modal-text); 65 | } 66 | 67 | .ObjectList-itemDesc { 68 | font-size: 1.2rem; 69 | color: var(--modal-text-light); 70 | } 71 | } 72 | 73 | .ObjectList-itemPrice { 74 | color: var(--modal-text); 75 | } 76 | 77 | &:not(:last-child) { 78 | border-bottom: 1px solid var(--modal-border); 79 | } 80 | } 81 | 82 | &::-webkit-scrollbar { 83 | width: 5px; 84 | } 85 | 86 | &::-webkit-scrollbar-track { 87 | background-color: var(--scrollbar-track); 88 | border-radius: 10px; 89 | } 90 | 91 | &::-webkit-scrollbar-thumb { 92 | background-color: var(--scrollbar-thumb); 93 | border-radius: 10px; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/components/Modals/ModalObjectInfo/ModalObjectInfo.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import Modal from "react-modal"; 3 | import classnames from "classnames"; 4 | import Loader from "react-loader-spinner"; 5 | 6 | import { apiArrayToObject, capitalize } from "utils/helpers"; 7 | import { MODAL_OBJECT_INFO } from "components/Modals/modalTypes"; 8 | import { IState as ModalsState } from "store/modals/reducer"; 9 | import { 10 | ProductsApiType, 11 | CategoriesApiType 12 | } from "store/api/reducer"; 13 | import { closeModal } from "store/modals/actions"; 14 | 15 | import styles from "./ModalObjectInfo.module.scss"; 16 | import { fetchCategoryIdFromCategories, fetchObjectIdFromObjectCategories, fetchProductsByObjectId } from "store/api/api"; 17 | 18 | type AppProps = { 19 | modals: ModalsState; 20 | closeModal: typeof closeModal; 21 | }; 22 | 23 | function ModalObjectInfo(props: AppProps) { 24 | const { 25 | modals: { isOpen: isModalOpen, activeModal, data }, 26 | closeModal, 27 | } = props; 28 | 29 | const [isOpen, setIsModalOpen] = useState(false); 30 | 31 | const [isFetching, setIsFetching] = useState(false); 32 | 33 | const [category, setCategoriesData] = useState(Object()); 34 | const [products, setProductsData] = useState>([]); 35 | 36 | useEffect(() => { 37 | if (activeModal === MODAL_OBJECT_INFO) { 38 | setIsModalOpen(true); 39 | } 40 | }, [activeModal]); 41 | 42 | useEffect(() => { 43 | if (!isModalOpen) { 44 | setIsModalOpen(false); 45 | } 46 | }, [isModalOpen]); 47 | 48 | useEffect(() => { 49 | const fetchData = async () => { 50 | setIsFetching(true); 51 | 52 | const objectToCategoryFetch = await fetchObjectIdFromObjectCategories(data) 53 | const objectToCategoryData = apiArrayToObject(objectToCategoryFetch); 54 | 55 | const categoriesFetch = await fetchCategoryIdFromCategories(objectToCategoryData.categoryId); 56 | const categoriesData = apiArrayToObject(categoriesFetch); 57 | setCategoriesData(categoriesData); 58 | 59 | const productsData = await fetchProductsByObjectId(objectToCategoryData.objectId); 60 | setProductsData(productsData); 61 | 62 | setIsFetching(false); 63 | }; 64 | 65 | if (data) { 66 | fetchData(); 67 | } 68 | }, [data]); 69 | 70 | return ( 71 | 79 | {isFetching ? ( 80 |
81 | 82 |
83 | ) : category && products ? ( 84 | <> 85 |
86 |

{category.name}

87 |
88 |
89 | {!products.length ? ( 90 |

Brak produktów

91 | ) : ( 92 |
    93 | {products.map((product: ProductsApiType) => ( 94 |
  • 95 |
    96 |

    97 | {capitalize(product.name)} 98 |

    99 |

    100 | {capitalize(product.desc)} 101 |

    102 |
    103 |

    104 | {product.price} zł 105 |

    106 |
  • 107 | ))} 108 |
109 | )} 110 |
111 | 112 | ) : null} 113 |
114 | ); 115 | } 116 | 117 | export default ModalObjectInfo; 118 | -------------------------------------------------------------------------------- /src/components/Modals/ModalObjectInfo/__tests__/ModalObjectInfo.test.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { render } from "@testing-library/react"; 3 | 4 | import { Provider } from "react-redux"; 5 | import store from "store"; 6 | 7 | import ModalObjectInfo from "components/Modals/ModalObjectInfo"; 8 | 9 | describe("ModalObjectInfo.tsx", () => { 10 | it("should render component", () => { 11 | render( 12 | 13 | 14 | 15 | ); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/components/Modals/ModalObjectInfo/index.ts: -------------------------------------------------------------------------------- 1 | import { compose } from "redux"; 2 | import { connect } from "react-redux"; 3 | 4 | import { AppState } from "store/rootReducer"; 5 | 6 | import { closeModal } from "store/modals/actions"; 7 | 8 | import ModalObjectInfo from "./ModalObjectInfo"; 9 | 10 | const mapStateToProps = ({ modals }: AppState) => ({ 11 | modals, 12 | }); 13 | 14 | const mapDispatchToProps = { 15 | closeModal, 16 | }; 17 | 18 | const enhancer = compose(connect(mapStateToProps, mapDispatchToProps)); 19 | 20 | export default enhancer(ModalObjectInfo); 21 | -------------------------------------------------------------------------------- /src/components/Modals/ModalSettings/ModalSettings.module.scss: -------------------------------------------------------------------------------- 1 | @import "styles/themes.scss"; 2 | 3 | .Modal--settings { 4 | width: 550px; 5 | padding: 30px 30px; 6 | border-radius: 7px; 7 | background: var(--modal-bg); 8 | outline: 0; 9 | 10 | .Settings { 11 | .Settings-title { 12 | font-size: 2.6rem; 13 | font-weight: 400; 14 | margin-bottom: 30px; 15 | color: var(--modal-text); 16 | 17 | &::after { 18 | content: ""; 19 | display: block; 20 | margin-top: 10px; 21 | width: 100%; 22 | height: 1px; 23 | background: var(--modal-settings-titleUnderline); 24 | } 25 | } 26 | 27 | .SettingsItem { 28 | display: flex; 29 | align-items: center; 30 | justify-content: space-between; 31 | 32 | .SettingsItem-info { 33 | .SettingsItem-title { 34 | font-weight: 600; 35 | color: var(--modal-text); 36 | } 37 | 38 | .SettingsItem-text { 39 | color: var(--modal-text-light); 40 | font-size: 1.4rem; 41 | } 42 | } 43 | 44 | .SettingsItem-input { 45 | display: flex; 46 | align-items: center; 47 | } 48 | 49 | .SelectLang { 50 | border: 1px solid var(--modal-settings-langBorder); 51 | background: var(--modal-settings-langBg); 52 | color: var(--modal-settings-langColor); 53 | padding: 10px; 54 | border-radius: 5px; 55 | 56 | &[disabled]:hover { 57 | cursor: not-allowed; 58 | } 59 | } 60 | 61 | .Switch { 62 | .Switch-input { 63 | &:checked + .Switch-label { 64 | background: var(--primary); 65 | } 66 | 67 | &:checked + .Switch-label:after { 68 | left: calc(100% - 5px); 69 | transform: translateX(-100%); 70 | } 71 | 72 | &:focus + .Switch-label { 73 | outline: var(--modal-switch-outline) solid 2px; 74 | } 75 | } 76 | 77 | .Switch-label { 78 | cursor: pointer; 79 | width: 60px; 80 | height: 30px; 81 | background: var(--modal-switch-bg); 82 | display: block; 83 | border-radius: 100px; 84 | position: relative; 85 | 86 | &:after { 87 | content: ""; 88 | position: absolute; 89 | top: 5px; 90 | left: 5px; 91 | width: 20px; 92 | height: 20px; 93 | background: var(--modal-switch-dot); 94 | border-radius: 90px; 95 | transition: 0.3s; 96 | } 97 | } 98 | } 99 | 100 | &:not(:last-child) { 101 | margin-bottom: 30px; 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/components/Modals/ModalSettings/ModalSettings.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import Modal from "react-modal"; 3 | import classnames from "classnames"; 4 | 5 | import { MODAL_SETTINGS } from "components/Modals/modalTypes"; 6 | 7 | import { IState as SettingsState } from "store/settings/reducer"; 8 | import { IState as ModalsState } from "store/modals/reducer"; 9 | import { switchLang, switchTheme } from "store/settings/actions"; 10 | import { closeModal } from "store/modals/actions"; 11 | 12 | import styles from "./ModalSettings.module.scss"; 13 | 14 | type AppProps = { 15 | settings: SettingsState; 16 | modals: ModalsState; 17 | switchTheme: typeof switchTheme; 18 | switchLang: typeof switchLang; 19 | closeModal: typeof closeModal; 20 | }; 21 | 22 | function ModalSettings(props: AppProps) { 23 | // Helper functions for this component 24 | const themeToBoolean = (theme: string) => (theme === "dark" ? true : false); 25 | const booleanToTheme = (bool: boolean) => (bool ? "dark" : "light"); 26 | 27 | const { 28 | settings: { lang, theme }, 29 | modals: { isOpen: isModalOpen, activeModal }, 30 | switchTheme, 31 | switchLang, 32 | closeModal, 33 | } = props; 34 | 35 | const [isOpen, setIsModalOpen] = React.useState(false); 36 | const [isThemeSwitchOn, setTheme] = React.useState(themeToBoolean(theme)); 37 | const [siteLang, setSiteLang] = React.useState(lang); 38 | 39 | useEffect(() => { 40 | if (activeModal === MODAL_SETTINGS) { 41 | setIsModalOpen(true); 42 | } 43 | }, [activeModal]); 44 | 45 | useEffect(() => { 46 | if (!isModalOpen) { 47 | setIsModalOpen(false); 48 | } 49 | }, [isModalOpen]); 50 | 51 | const handleThemeSwitch = () => { 52 | const newValue = !isThemeSwitchOn; 53 | 54 | setTheme(newValue); 55 | switchTheme(booleanToTheme(newValue)); 56 | }; 57 | 58 | const handleLangSwitch = (event: React.FormEvent) => { 59 | const newLang = event.currentTarget.value; 60 | 61 | setSiteLang(newLang); 62 | switchLang(newLang); 63 | }; 64 | 65 | return ( 66 | 74 |
75 |

Settings

76 |
77 |
78 |

Dark Theme

79 |

80 | Switch between dark and light theme. 81 |

82 |
83 |
89 | 96 | 101 |
102 |
103 |
104 |
105 |

Language

106 |

107 | Change site language 108 |

109 |
110 |
111 | 120 |
121 |
122 |
123 |
124 | ); 125 | } 126 | 127 | export default ModalSettings; 128 | -------------------------------------------------------------------------------- /src/components/Modals/ModalSettings/__tests__/ModalSettings.test.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { render } from "@testing-library/react"; 3 | 4 | import { Provider } from "react-redux"; 5 | import store from "store"; 6 | 7 | import ModalSettings from "components/Modals/ModalSettings"; 8 | 9 | describe("ModalSettings.tsx", () => { 10 | it("should render component", () => { 11 | render( 12 | 13 | 14 | 15 | ); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/components/Modals/ModalSettings/index.ts: -------------------------------------------------------------------------------- 1 | import { compose } from "redux"; 2 | import { connect } from "react-redux"; 3 | 4 | import { AppState } from "store/rootReducer"; 5 | 6 | import { switchLang, switchTheme } from "store/settings/actions"; 7 | import { closeModal } from "store/modals/actions"; 8 | 9 | import ModalSettings from "./ModalSettings"; 10 | 11 | const mapStateToProps = ({ settings, modals }: AppState) => ({ 12 | settings, 13 | modals, 14 | }); 15 | 16 | const mapDispatchToProps = { 17 | closeModal, 18 | switchLang, 19 | switchTheme, 20 | }; 21 | 22 | const enhancer = compose(connect(mapStateToProps, mapDispatchToProps)); 23 | 24 | export default enhancer(ModalSettings); 25 | -------------------------------------------------------------------------------- /src/components/Modals/modalTypes.ts: -------------------------------------------------------------------------------- 1 | export const MODAL_SETTINGS = "MODAL_SETTINGS"; 2 | export const MODAL_OBJECT_INFO = "MODAL_OBJECT_INFO"; 3 | -------------------------------------------------------------------------------- /src/components/Sidebar/Sidebar.module.scss: -------------------------------------------------------------------------------- 1 | @import "styles/themes.scss"; 2 | 3 | .Sidebar { 4 | width: 0; 5 | background: var(--sidebar-bg); 6 | min-height: 100vh; 7 | flex-shrink: 0; 8 | display: flex; 9 | box-shadow: 0px 0px 50px rgba(0, 0, 0, 0.05); 10 | flex-direction: column; 11 | z-index: 1; 12 | overflow: hidden; 13 | white-space: nowrap; 14 | transition: all 0.2s; 15 | position: relative; 16 | 17 | .Header { 18 | padding-bottom: 40px; 19 | 20 | .Header-title { 21 | font-size: 2.8rem; 22 | font-weight: 400; 23 | color: var(--sidebar-headerTitle); 24 | } 25 | 26 | .Header-text { 27 | font-size: 1.2rem; 28 | color: var(--sidebar-headerText); 29 | } 30 | } 31 | 32 | .Buttons { 33 | display: flex; 34 | padding-bottom: 40px; 35 | 36 | .Button { 37 | height: 50px; 38 | width: 100%; 39 | background: var(--sidebar-buttonSecond-bg); 40 | color: var(--sidebar-buttonSecond-text); 41 | border: 0; 42 | font-weight: 700; 43 | font-size: 1.4rem; 44 | border-radius: 5px; 45 | transition: 0.1s; 46 | 47 | &:hover { 48 | cursor: pointer; 49 | background: var(--sidebar-buttonSecond-bg--hover); 50 | } 51 | 52 | &:nth-child(odd) { 53 | margin-right: 10px; 54 | } 55 | 56 | &:nth-child(even) { 57 | margin-left: 10px; 58 | } 59 | } 60 | 61 | .Button--active { 62 | background: var(--sidebar-buttonMain-bg); 63 | color: var(--sidebar-buttonMain-text); 64 | 65 | &:hover { 66 | background: var(--sidebar-buttonMain-bg--hover); 67 | } 68 | } 69 | } 70 | 71 | .Categories { 72 | flex-grow: 1; 73 | margin-bottom: 40px; 74 | overflow-y: scroll; 75 | padding-right: 20px; 76 | display: none; 77 | 78 | .CategoryHeader { 79 | padding-bottom: 10px; 80 | 81 | .CategoryHeader-title { 82 | font-weight: 700; 83 | font-size: 2.4rem; 84 | text-transform: uppercase; 85 | color: var(--sidebar-category-letter); 86 | 87 | .CategoryHeader-results { 88 | font-weight: 400; 89 | font-size: 1.6rem; 90 | padding-left: 8px; 91 | text-transform: lowercase; 92 | color: var(--sidebar-category-results); 93 | } 94 | } 95 | } 96 | 97 | .Categories-loader { 98 | height: 100%; 99 | display: flex; 100 | align-items: center; 101 | justify-content: center; 102 | } 103 | 104 | .Category { 105 | margin-bottom: 20px; 106 | 107 | .CategoryGroup { 108 | .CategoryItem { 109 | background: var(--sidebar-categoryItem-bg); 110 | border-radius: 5px; 111 | height: 70px; 112 | margin-bottom: 10px; 113 | display: flex; 114 | padding: 5px; 115 | 116 | .CategoryItem-photo { 117 | width: 60px; 118 | height: 60px; 119 | border-radius: 5px; 120 | background: var(--sidebar-categoryItem-photo); 121 | } 122 | 123 | .CategoryItem-text { 124 | display: flex; 125 | flex-direction: column; 126 | justify-content: center; 127 | padding-left: 15px; 128 | text-transform: capitalize; 129 | 130 | .CategoryItem-title { 131 | font-size: 1.6rem; 132 | color: var(--sidebar-categoryItem-title); 133 | } 134 | .CategoryItem-subTitle { 135 | font-size: 1.2rem; 136 | color: var(--sidebar-categoryItem-text); 137 | } 138 | } 139 | 140 | .CategoryItem-link { 141 | margin-left: auto; 142 | display: flex; 143 | flex-direction: column; 144 | justify-content: center; 145 | padding: 0 10px; 146 | color: var(--sidebar-categoryItem-itemLink); 147 | font-size: 3rem; 148 | } 149 | 150 | &:last-child { 151 | margin-bottom: 0; 152 | } 153 | 154 | &:hover { 155 | cursor: pointer; 156 | } 157 | } 158 | } 159 | 160 | .CategoriesList { 161 | list-style-position: inside; 162 | list-style-type: none; 163 | 164 | .CategoriesList-item { 165 | background: var(--sidebar-categoryItem-bg); 166 | color: var(--sidebar-categoryItem-title); 167 | border-radius: 5px; 168 | padding: 15px 20px; 169 | text-transform: capitalize; 170 | text-align: center; 171 | font-weight: 600; 172 | 173 | &:not(:last-child) { 174 | margin-bottom: 10px; 175 | } 176 | } 177 | } 178 | 179 | &:last-child { 180 | margin-bottom: 0; 181 | } 182 | } 183 | 184 | &::-webkit-scrollbar { 185 | width: 5px; 186 | } 187 | 188 | &::-webkit-scrollbar-track { 189 | background-color: var(--scrollbar-track); 190 | border-radius: 10px; 191 | } 192 | 193 | &::-webkit-scrollbar-thumb { 194 | background-color: var(--scrollbar-thumb); 195 | border-radius: 10px; 196 | } 197 | } 198 | 199 | .Categories--active { 200 | display: block; 201 | } 202 | 203 | .Footer { 204 | .Footer-text { 205 | text-align: center; 206 | font-size: 1.4rem; 207 | color: var(--sidebar-footer); 208 | display: flex; 209 | align-items: center; 210 | justify-content: center; 211 | 212 | .Footer-icon { 213 | font-size: 1.8rem; 214 | margin-right: 5px; 215 | color: #61dafb; 216 | } 217 | 218 | .Footer-link { 219 | color: black; 220 | text-decoration: none; 221 | 222 | &:hover { 223 | text-decoration: underline; 224 | } 225 | 226 | &:visited { 227 | color: black; 228 | } 229 | } 230 | } 231 | } 232 | 233 | .Header, 234 | .Search, 235 | .Buttons, 236 | .Footer { 237 | padding-left: 30px; 238 | padding-right: 30px; 239 | } 240 | 241 | .Header { 242 | padding-top: 40px; 243 | } 244 | 245 | .Categories { 246 | margin-left: 30px; 247 | margin-right: 30px; 248 | } 249 | 250 | .Footer { 251 | padding-bottom: 40px; 252 | } 253 | } 254 | 255 | .Sidebar--active { 256 | width: 450px; 257 | } 258 | -------------------------------------------------------------------------------- /src/components/Sidebar/Sidebar.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { FiChevronRight } from "react-icons/fi"; 3 | import { DiReact } from "react-icons/di"; 4 | import classnames from "classnames"; 5 | import Loader from "react-loader-spinner"; 6 | 7 | import { IState as SidebarState } from "store/sidebar/reducer"; 8 | import { IState as ApiState } from "store/api/reducer"; 9 | import { ProductsApiType } from "store/api/reducer"; 10 | 11 | import { searchProduct } from "store/search/actions"; 12 | 13 | import styles from "./Sidebar.module.scss"; 14 | 15 | type AppProps = { 16 | sidebar: SidebarState; 17 | api: ApiState; 18 | searchProduct: typeof searchProduct; 19 | }; 20 | 21 | type ParsedProducts = { 22 | [key: string]: { 23 | len: number; 24 | results: Array; 25 | }; 26 | }; 27 | 28 | const tabCategories = { 29 | az: "a-z", 30 | categories: "categories", 31 | }; 32 | 33 | function Sidebar(props: AppProps) { 34 | const { 35 | sidebar: { isOpen }, 36 | api: { products, categories, objectToCategory, isFetching }, 37 | searchProduct, 38 | } = props; 39 | 40 | const [activeTab, setActiveTab] = useState(tabCategories.az); 41 | const [parsedProducts, setParsedProducts] = useState({}); 42 | 43 | useEffect(() => { 44 | const parseProductsAZ = () => { 45 | if (products) { 46 | const data: ParsedProducts = {}; 47 | 48 | products.forEach((product: ProductsApiType) => { 49 | let firstLetter = product.name[0]; 50 | 51 | if (!data[firstLetter]) { 52 | data[firstLetter] = { 53 | len: 0, 54 | results: [], 55 | }; 56 | } 57 | 58 | data[firstLetter].results.push(product); 59 | data[firstLetter].len = data[firstLetter].len + 1; 60 | }); 61 | 62 | setParsedProducts(data); 63 | } 64 | }; 65 | 66 | if (!isFetching) { 67 | if (activeTab === tabCategories.az) { 68 | parseProductsAZ(); 69 | } 70 | } 71 | }, [activeTab, isFetching, categories, products, objectToCategory]); 72 | 73 | const navigateToProduct = (e: React.MouseEvent) => { 74 | e.preventDefault(); 75 | const product = e.currentTarget.dataset.product; 76 | if (product) { 77 | searchProduct(product); 78 | } 79 | }; 80 | 81 | return ( 82 |
88 |
89 |

90 | Map of Groceries 91 |

92 |

Dijkstra pathfinding example.

93 |
94 |
95 | 104 | 113 |
114 |
120 | {isFetching ? ( 121 |
122 | 123 |
124 | ) : ( 125 | <> 126 | {Object.keys(parsedProducts).map( 127 | (letter: string, index: number) => ( 128 |
129 |
130 |

131 | {letter} 132 | 133 | - {parsedProducts[letter].len} results 134 | 135 |

136 |
137 |
138 | {parsedProducts[letter].results.map( 139 | (item: ProductsApiType) => ( 140 |
146 |
147 |
148 |

149 | {item.name} 150 |

151 |

152 | {item.desc} 153 |

154 |
155 |
156 | 157 |
158 |
159 | ) 160 | )} 161 |
162 |
163 | ) 164 | )} 165 | 166 | )} 167 |
168 |
174 |
175 |
    176 | {categories.map((category) => ( 177 |
  • 178 | {category.name} 179 |
  • 180 | ))} 181 |
182 |
183 |
184 |
185 |

186 | 187 | 188 | Made by Maciej Biel 189 | 190 |

191 |
192 |
193 | ); 194 | } 195 | 196 | export default Sidebar; 197 | -------------------------------------------------------------------------------- /src/components/Sidebar/__tests__/Sidebar.test.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { render } from "@testing-library/react"; 3 | 4 | import { Provider } from "react-redux"; 5 | import store from "store"; 6 | 7 | import Sidebar from "components/Sidebar"; 8 | 9 | describe("Sidebar.tsx", () => { 10 | it("should render component", () => { 11 | render( 12 | 13 | 14 | 15 | ); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/components/Sidebar/index.ts: -------------------------------------------------------------------------------- 1 | import { compose } from "redux"; 2 | import { connect } from "react-redux"; 3 | 4 | import { toggleSidebar } from "store/sidebar/actions"; 5 | import { searchProduct } from "store/search/actions"; 6 | 7 | import { AppState } from "store/rootReducer"; 8 | 9 | import Sidebar from "./Sidebar"; 10 | 11 | const mapStateToProps = ({ sidebar, api }: AppState) => ({ 12 | sidebar, 13 | api, 14 | }); 15 | 16 | const mapDispatchToProps = { 17 | toggleSidebar, 18 | searchProduct, 19 | }; 20 | 21 | const enhancer = compose(connect(mapStateToProps, mapDispatchToProps)); 22 | 23 | export default enhancer(Sidebar); 24 | -------------------------------------------------------------------------------- /src/containers/Layout/Layout.module.scss: -------------------------------------------------------------------------------- 1 | @import "styles/themes.scss"; 2 | 3 | .Layout { 4 | display: flex; 5 | width: 100%; 6 | height: 100%; 7 | position: relative; 8 | } 9 | 10 | .SkipLink { 11 | background: var(--primary); 12 | height: 30px; 13 | display: flex; 14 | align-items: center; 15 | justify-content: center; 16 | left: 50%; 17 | padding: 10px 20px; 18 | position: absolute; 19 | transform: translateY(-100%); 20 | transition: transform 0.3s; 21 | text-align: center; 22 | z-index: 1000; 23 | font-weight: 400; 24 | font-size: 1.4rem; 25 | color: var(--skiplink-text); 26 | } 27 | 28 | .SkipLink:focus { 29 | transform: translateY(0%); 30 | } 31 | -------------------------------------------------------------------------------- /src/containers/Layout/Layout.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import Sidebar from "components/Sidebar"; 4 | import Main from "components/Main"; 5 | 6 | import ModalSettings from "components/Modals/ModalSettings"; 7 | import ModalObjectInfo from "components/Modals/ModalObjectInfo"; 8 | 9 | import styles from "./Layout.module.scss"; 10 | 11 | function Layout() { 12 | return ( 13 |
14 | {/* Skip links */} 15 | 23 | 24 | {/* Page layout */} 25 | 26 |
27 | 28 | {/* List of modals on page */} 29 | 30 | 31 |
32 | ); 33 | } 34 | 35 | export default Layout; 36 | -------------------------------------------------------------------------------- /src/containers/Layout/__tests__/Layout.test.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { render } from "@testing-library/react"; 3 | 4 | import { Provider } from "react-redux"; 5 | import store from "store"; 6 | 7 | import Layout from "containers/Layout"; 8 | 9 | describe("Layout.tsx", () => { 10 | it("should render component", () => { 11 | render( 12 | 13 | 14 | 15 | ); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/containers/Layout/index.ts: -------------------------------------------------------------------------------- 1 | import { compose } from "redux"; 2 | import { connect } from "react-redux"; 3 | 4 | import Layout from "./Layout"; 5 | 6 | const mapStateToProps = null; 7 | const mapDispatchToProps = null; 8 | 9 | const enhancer = compose(connect(mapStateToProps, mapDispatchToProps)); 10 | 11 | export default enhancer(Layout); 12 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import * as serviceWorker from "utils/serviceWorker"; 4 | import Modal from "react-modal"; 5 | 6 | import { Provider } from "react-redux"; 7 | import store from "store"; 8 | import WebFont from "webfontloader"; 9 | import "utils/i18n"; 10 | 11 | import "normalize.css"; 12 | import "styles/index.scss"; 13 | 14 | import App from "components/App"; 15 | 16 | WebFont.load({ 17 | google: { 18 | families: ["Montserrat:400,600,700"], 19 | }, 20 | }); 21 | 22 | Modal.setAppElement("#root"); 23 | 24 | ReactDOM.render( 25 | 26 | 27 | 28 | 29 | , 30 | document.getElementById("root") 31 | ); 32 | 33 | serviceWorker.unregister(); 34 | -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /src/store/actions.ts: -------------------------------------------------------------------------------- 1 | export type Action

= { 2 | type: string; 3 | payload?: P; 4 | }; 5 | 6 | export const createAction =

( 7 | type: string, 8 | payload?: P 9 | ): Action => ({ 10 | type, 11 | payload, 12 | }); 13 | -------------------------------------------------------------------------------- /src/store/api/actions.ts: -------------------------------------------------------------------------------- 1 | import { createAction } from "store/actions"; 2 | import { FETCH_API_REQUEST } from "./constants"; 3 | 4 | export const fetchApiData = () => { 5 | return createAction(FETCH_API_REQUEST); 6 | }; 7 | -------------------------------------------------------------------------------- /src/store/api/api.ts: -------------------------------------------------------------------------------- 1 | import db from "./db"; 2 | import { 3 | CategoriesApiType, 4 | ObjectToCategoryApiType, 5 | ProductsApiType, 6 | } from "./reducer"; 7 | 8 | export const fetchProductApi = () => { 9 | return new Promise>((resolve) => { 10 | // ... ORDER BY name ASC 11 | const arr = [...db["products"]]; 12 | arr.sort((a, b) => (a.name > b.name ? 1 : b.name > a.name ? -1 : 0)); 13 | resolve(arr); 14 | }); 15 | }; 16 | 17 | export const fetchProductsAutcompleteApi = (name: string) => { 18 | return new Promise>((resolve) => { 19 | const arr = [...db["products"]]; 20 | 21 | let query = name.toLowerCase(); 22 | const results = arr.filter((item) => { 23 | return item.name.toLowerCase().indexOf(query) > -1; 24 | }); 25 | 26 | resolve(results); 27 | }); 28 | }; 29 | 30 | export const fetchProductsByObjectId = (objectId: string) => { 31 | return new Promise>((resolve) => { 32 | const arr = [...db["products"]]; 33 | 34 | const results = arr.filter((item) => { 35 | return item.objectId === objectId; 36 | }); 37 | 38 | resolve(results); 39 | }); 40 | }; 41 | 42 | export const fetchObjectIdFromObjectCategories = (objectId: string) => { 43 | return new Promise>((resolve) => { 44 | const arr = [...db["object-to-category"]]; 45 | 46 | const results = arr.filter((item) => { 47 | return item.objectId === objectId; 48 | }); 49 | 50 | resolve(results); 51 | }); 52 | }; 53 | 54 | export const fetchCategoriesApi = () => { 55 | return new Promise>((resolve) => { 56 | resolve(db["categories"]); 57 | }); 58 | }; 59 | 60 | export const fetchCategoryIdFromCategories = (categoryId: number) => { 61 | return new Promise>((resolve) => { 62 | const arr = [...db["categories"]]; 63 | 64 | const results = arr.filter((item) => { 65 | return item.id === categoryId; 66 | }); 67 | 68 | resolve(results); 69 | }); 70 | }; 71 | 72 | export const fetchObjectToCategoryApi = () => { 73 | return new Promise>((resolve) => { 74 | resolve(db["object-to-category"]); 75 | }); 76 | }; 77 | -------------------------------------------------------------------------------- /src/store/api/constants.ts: -------------------------------------------------------------------------------- 1 | export const FETCH_API_REQUEST = "FETCH_API_REQUEST"; 2 | export const FETCH_API_SUCCESS = "FETCH_API_SUCCESS"; 3 | export const FETCH_API_FAILED = "FETCH_API_FAILED"; 4 | -------------------------------------------------------------------------------- /src/store/api/db.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | categories: [ 3 | { 4 | id: 1, 5 | name: "alcohol", 6 | }, 7 | { 8 | id: 2, 9 | name: "bakery products", 10 | }, 11 | { 12 | id: 3, 13 | name: "groceries", 14 | }, 15 | { 16 | id: 4, 17 | name: "teas and coffees", 18 | }, 19 | { 20 | id: 5, 21 | name: "sweets", 22 | }, 23 | { 24 | id: 6, 25 | name: "mineral water", 26 | }, 27 | { 28 | id: 7, 29 | name: "beverages and juices", 30 | }, 31 | { 32 | id: 8, 33 | name: "meat and cold cuts", 34 | }, 35 | { 36 | id: 9, 37 | name: "cheeses", 38 | }, 39 | { 40 | id: 10, 41 | name: "frozen foods", 42 | }, 43 | { 44 | id: 11, 45 | name: "savoury snacks", 46 | }, 47 | { 48 | id: 12, 49 | name: "fishes", 50 | }, 51 | { 52 | id: 13, 53 | name: "honey and dried fruits", 54 | }, 55 | { 56 | id: 14, 57 | name: "eggs", 58 | }, 59 | { 60 | id: 15, 61 | name: "delicatessen", 62 | }, 63 | { 64 | id: 16, 65 | name: "spices", 66 | }, 67 | { 68 | id: 17, 69 | name: "preserves", 70 | }, 71 | { 72 | id: 18, 73 | name: "ready meals", 74 | }, 75 | { 76 | id: 19, 77 | name: "cleaning products", 78 | }, 79 | { 80 | id: 20, 81 | name: "animal world", 82 | }, 83 | { 84 | id: 21, 85 | name: "ice creams", 86 | }, 87 | { 88 | id: 22, 89 | name: "dairy products", 90 | }, 91 | { 92 | id: 23, 93 | name: "deals", 94 | }, 95 | { 96 | id: 24, 97 | name: "checkout", 98 | }, 99 | { 100 | id: 25, 101 | name: "fruits and vegetables", 102 | }, 103 | ], 104 | products: [ 105 | { 106 | id: 1, 107 | name: "Guinness Draught", 108 | desc: "-", 109 | price: "2.50", 110 | objectId: "o_5", 111 | }, 112 | { 113 | id: 2, 114 | name: "Orange juice", 115 | desc: "-", 116 | price: "2.50", 117 | objectId: "o_10", 118 | }, 119 | { 120 | id: 3, 121 | name: "Milk", 122 | desc: "-", 123 | price: "2.50", 124 | objectId: "o_8", 125 | }, 126 | { 127 | id: 4, 128 | name: "Chocolate", 129 | desc: "-", 130 | price: "2.50", 131 | objectId: "o_25", 132 | }, 133 | { 134 | id: 5, 135 | name: "Salmon", 136 | desc: "-", 137 | price: "2.50", 138 | objectId: "o_21", 139 | }, 140 | { 141 | id: 6, 142 | name: "Pasta", 143 | desc: "-", 144 | price: "2.50", 145 | objectId: "o_35", 146 | }, 147 | { 148 | id: 7, 149 | name: "Eggs", 150 | desc: "-", 151 | price: "2.50", 152 | objectId: "o_18", 153 | }, 154 | { 155 | id: 8, 156 | name: "Heineken", 157 | desc: "-", 158 | price: "2.50", 159 | objectId: "o_11", 160 | }, 161 | { 162 | id: 9, 163 | name: "Corona Extra", 164 | desc: "-", 165 | price: "2.50", 166 | objectId: "o_11", 167 | }, 168 | { 169 | id: 10, 170 | name: "Punk IPA", 171 | desc: "-", 172 | price: "2.50", 173 | objectId: "o_1", 174 | }, 175 | { 176 | id: 11, 177 | name: "Bud Light", 178 | desc: "-", 179 | price: "2.50", 180 | objectId: "o_5", 181 | }, 182 | { 183 | id: 12, 184 | name: "Traditional Lager", 185 | desc: "-", 186 | price: "2.50", 187 | objectId: "o_5", 188 | }, 189 | { 190 | id: 13, 191 | name: "Lay's salted", 192 | desc: "-", 193 | price: "5.99", 194 | objectId: "o_28", 195 | }, 196 | { 197 | id: 14, 198 | name: "Pepper", 199 | desc: "-", 200 | price: "2.00", 201 | objectId: "o_15", 202 | }, 203 | { 204 | id: 15, 205 | name: "Pierogi", 206 | desc: "True Polish OG food", 207 | price: "9.99", 208 | objectId: "o_24", 209 | }, 210 | { 211 | id: 16, 212 | name: "Instant soup", 213 | desc: "-", 214 | price: "2.50", 215 | objectId: "o_14", 216 | }, 217 | { 218 | id: 17, 219 | name: "Salt", 220 | desc: "-", 221 | price: "1.00", 222 | objectId: "o_16", 223 | }, 224 | { 225 | id: 18, 226 | name: "Coffee", 227 | desc: "-", 228 | price: "15.00", 229 | objectId: "o_33", 230 | }, 231 | { 232 | id: 19, 233 | name: "Black tea", 234 | desc: "-", 235 | price: "1.00", 236 | objectId: "o_32", 237 | }, 238 | { 239 | id: 20, 240 | name: "Green tea", 241 | desc: "-", 242 | price: "1.00", 243 | objectId: "o_32", 244 | }, 245 | { 246 | id: 21, 247 | name: "Tomatoes", 248 | desc: "-", 249 | price: "2.00", 250 | objectId: "o_34", 251 | }, 252 | { 253 | id: 22, 254 | name: "Bananas", 255 | desc: "-", 256 | price: "4.99", 257 | objectId: "o_30", 258 | }, 259 | { 260 | id: 23, 261 | name: "Apples", 262 | desc: "-", 263 | price: "3.99", 264 | objectId: "o_30", 265 | }, 266 | { 267 | id: 24, 268 | name: "Salty sticks", 269 | desc: "-", 270 | price: "3.99", 271 | objectId: "o_28", 272 | }, 273 | { 274 | id: 25, 275 | name: "Cream tubes", 276 | desc: "-", 277 | price: "4.50", 278 | objectId: "o_26", 279 | }, 280 | { 281 | id: 26, 282 | name: "Waffles", 283 | desc: "-", 284 | price: "4.50", 285 | objectId: "o_27", 286 | }, 287 | { 288 | id: 27, 289 | name: "American cookies", 290 | desc: "-", 291 | price: "4.39", 292 | objectId: "o_25", 293 | }, 294 | { 295 | id: 28, 296 | name: "Bread", 297 | desc: "-", 298 | price: "3.00", 299 | objectId: "o_38", 300 | }, 301 | { 302 | id: 29, 303 | name: "Roll", 304 | desc: "-", 305 | price: "3.29", 306 | objectId: "o_43", 307 | }, 308 | { 309 | id: 30, 310 | name: "Corn", 311 | desc: "-", 312 | price: "2.40", 313 | objectId: "o_36", 314 | }, 315 | { 316 | id: 31, 317 | name: "Tomato sauce", 318 | desc: "-", 319 | price: "5.19", 320 | objectId: "o_37", 321 | }, 322 | { 323 | id: 32, 324 | name: "Gouda cheese", 325 | desc: "-", 326 | price: "5.19", 327 | objectId: "o_13", 328 | }, 329 | { 330 | id: 33, 331 | name: "Blue cheese", 332 | desc: "-", 333 | price: "6.00", 334 | objectId: "o_39", 335 | }, 336 | { 337 | id: 34, 338 | name: "Ham", 339 | desc: "-", 340 | price: "5.00", 341 | objectId: "o_42", 342 | }, 343 | { 344 | id: 35, 345 | name: "Salami", 346 | desc: "-", 347 | price: "3.00", 348 | objectId: "o_41", 349 | }, 350 | { 351 | id: 36, 352 | name: "Peanuts", 353 | desc: "-", 354 | price: "6.00", 355 | objectId: "o_22", 356 | }, 357 | { 358 | id: 37, 359 | name: "Honey", 360 | desc: "-", 361 | price: "20.00", 362 | objectId: "o_22", 363 | }, 364 | { 365 | id: 38, 366 | name: "Jam", 367 | desc: "-", 368 | price: "7.00", 369 | objectId: "o_23", 370 | }, 371 | { 372 | id: 39, 373 | name: "Detergent", 374 | desc: "-", 375 | price: "25.00", 376 | objectId: "o_31", 377 | }, 378 | { 379 | id: 40, 380 | name: "karma dla psa", 381 | desc: "-", 382 | price: "30.00", 383 | objectId: "o_29", 384 | }, 385 | { 386 | id: 41, 387 | name: "Ice cream", 388 | desc: "-", 389 | price: "2.89", 390 | objectId: "o_20", 391 | }, 392 | { 393 | id: 42, 394 | name: "Frozen vegetables", 395 | desc: "-", 396 | price: "12.00", 397 | objectId: "o_17", 398 | }, 399 | { 400 | id: 43, 401 | name: "Candy box", 402 | desc: "-", 403 | price: "5.00", 404 | objectId: "o_19", 405 | }, 406 | { 407 | id: 44, 408 | name: "Natural yogurt", 409 | desc: "-", 410 | price: "3.00", 411 | objectId: "o_7", 412 | }, 413 | { 414 | id: 45, 415 | name: "Cottage cheese", 416 | desc: "-", 417 | price: "3.00", 418 | objectId: "o_2", 419 | }, 420 | { 421 | id: 46, 422 | name: "Sparkling water", 423 | desc: "-", 424 | price: "1.79", 425 | objectId: "o_4", 426 | }, 427 | { 428 | id: 47, 429 | name: "Mineral water", 430 | desc: "-", 431 | price: "2.79", 432 | objectId: "o_9", 433 | }, 434 | { 435 | id: 48, 436 | name: "Cola", 437 | desc: "-", 438 | price: "4.79", 439 | objectId: "o_6", 440 | }, 441 | { 442 | id: 49, 443 | name: "Orange soda", 444 | desc: "-", 445 | price: "4.79", 446 | objectId: "o_3", 447 | }, 448 | { 449 | id: 50, 450 | name: "Vodka", 451 | desc: "-", 452 | price: "25.00", 453 | objectId: "o_12", 454 | }, 455 | { 456 | id: 51, 457 | name: "Chewing gums", 458 | desc: "-", 459 | price: "3.00", 460 | objectId: "o_40", 461 | }, 462 | ], 463 | "object-to-category": [ 464 | { 465 | id: 1, 466 | categoryId: 1, 467 | objectId: "o_1", 468 | }, 469 | { 470 | id: 2, 471 | categoryId: 22, 472 | objectId: "o_2", 473 | }, 474 | { 475 | id: 3, 476 | categoryId: 7, 477 | objectId: "o_3", 478 | }, 479 | { 480 | id: 4, 481 | categoryId: 6, 482 | objectId: "o_4", 483 | }, 484 | { 485 | id: 5, 486 | categoryId: 1, 487 | objectId: "o_5", 488 | }, 489 | { 490 | id: 6, 491 | categoryId: 7, 492 | objectId: "o_6", 493 | }, 494 | { 495 | id: 7, 496 | categoryId: 22, 497 | objectId: "o_7", 498 | }, 499 | { 500 | id: 8, 501 | categoryId: 22, 502 | objectId: "o_8", 503 | }, 504 | { 505 | id: 9, 506 | categoryId: 6, 507 | objectId: "o_9", 508 | }, 509 | { 510 | id: 10, 511 | categoryId: 7, 512 | objectId: "o_10", 513 | }, 514 | { 515 | id: 11, 516 | categoryId: 1, 517 | objectId: "o_11", 518 | }, 519 | { 520 | id: 12, 521 | categoryId: 1, 522 | objectId: "o_12", 523 | }, 524 | { 525 | id: 13, 526 | categoryId: 9, 527 | objectId: "o_13", 528 | }, 529 | { 530 | id: 14, 531 | categoryId: 18, 532 | objectId: "o_14", 533 | }, 534 | { 535 | id: 15, 536 | categoryId: 16, 537 | objectId: "o_15", 538 | }, 539 | { 540 | id: 16, 541 | categoryId: 16, 542 | objectId: "o_16", 543 | }, 544 | { 545 | id: 17, 546 | categoryId: 10, 547 | objectId: "o_17", 548 | }, 549 | { 550 | id: 18, 551 | categoryId: 14, 552 | objectId: "o_18", 553 | }, 554 | { 555 | id: 19, 556 | categoryId: 23, 557 | objectId: "o_19", 558 | }, 559 | { 560 | id: 20, 561 | categoryId: 21, 562 | objectId: "o_20", 563 | }, 564 | { 565 | id: 21, 566 | categoryId: 12, 567 | objectId: "o_21", 568 | }, 569 | { 570 | id: 22, 571 | categoryId: 13, 572 | objectId: "o_22", 573 | }, 574 | { 575 | id: 23, 576 | categoryId: 17, 577 | objectId: "o_23", 578 | }, 579 | { 580 | id: 24, 581 | categoryId: 15, 582 | objectId: "o_24", 583 | }, 584 | { 585 | id: 25, 586 | categoryId: 5, 587 | objectId: "o_25", 588 | }, 589 | { 590 | id: 26, 591 | categoryId: 5, 592 | objectId: "o_26", 593 | }, 594 | { 595 | id: 27, 596 | categoryId: 5, 597 | objectId: "o_27", 598 | }, 599 | { 600 | id: 28, 601 | categoryId: 11, 602 | objectId: "o_28", 603 | }, 604 | { 605 | id: 29, 606 | categoryId: 20, 607 | objectId: "o_29", 608 | }, 609 | { 610 | id: 30, 611 | categoryId: 25, 612 | objectId: "o_30", 613 | }, 614 | { 615 | id: 31, 616 | categoryId: 19, 617 | objectId: "o_31", 618 | }, 619 | { 620 | id: 32, 621 | categoryId: 4, 622 | objectId: "o_32", 623 | }, 624 | { 625 | id: 33, 626 | categoryId: 4, 627 | objectId: "o_33", 628 | }, 629 | { 630 | id: 34, 631 | categoryId: 25, 632 | objectId: "o_34", 633 | }, 634 | { 635 | id: 35, 636 | categoryId: 3, 637 | objectId: "o_35", 638 | }, 639 | { 640 | id: 36, 641 | categoryId: 3, 642 | objectId: "o_36", 643 | }, 644 | { 645 | id: 37, 646 | categoryId: 3, 647 | objectId: "o_37", 648 | }, 649 | { 650 | id: 38, 651 | categoryId: 2, 652 | objectId: "o_38", 653 | }, 654 | { 655 | id: 39, 656 | categoryId: 9, 657 | objectId: "o_39", 658 | }, 659 | { 660 | id: 40, 661 | categoryId: 24, 662 | objectId: "o_40", 663 | }, 664 | { 665 | id: 41, 666 | categoryId: 8, 667 | objectId: "o_41", 668 | }, 669 | { 670 | id: 42, 671 | categoryId: 8, 672 | objectId: "o_42", 673 | }, 674 | { 675 | id: 43, 676 | categoryId: 2, 677 | objectId: "o_43", 678 | }, 679 | ], 680 | }; 681 | -------------------------------------------------------------------------------- /src/store/api/reducer.ts: -------------------------------------------------------------------------------- 1 | import { Reducer } from "redux"; 2 | import { Action } from "store/actions"; 3 | 4 | import { 5 | FETCH_API_REQUEST, 6 | FETCH_API_SUCCESS, 7 | FETCH_API_FAILED, 8 | } from "./constants"; 9 | 10 | export type ProductsApiType = { 11 | id: number; 12 | name: string; 13 | price: string; 14 | desc: string; 15 | objectId: string; 16 | }; 17 | 18 | export type CategoriesApiType = { 19 | id: number; 20 | name: string; 21 | }; 22 | 23 | export type ObjectToCategoryApiType = { 24 | id: number; 25 | categoryId: number; 26 | objectId: string; 27 | }; 28 | 29 | export type IState = { 30 | readonly products: Array; 31 | readonly categories: Array; 32 | readonly objectToCategory: Array; 33 | readonly error: Error | null; 34 | readonly isFetching: boolean; 35 | }; 36 | 37 | export const initialState: IState = { 38 | products: [], 39 | categories: [], 40 | objectToCategory: [], 41 | isFetching: false, 42 | error: null, 43 | }; 44 | 45 | export const api: Reducer = ( 46 | state = initialState, 47 | action: Action 48 | ) => { 49 | switch (action.type) { 50 | case FETCH_API_REQUEST: 51 | return { 52 | ...state, 53 | isFetching: true, 54 | error: null, 55 | }; 56 | case FETCH_API_SUCCESS: 57 | return { 58 | ...state, 59 | isFetching: false, 60 | products: action.payload.products, 61 | categories: action.payload.categories, 62 | objectToCategory: action.payload.objectToCategory, 63 | }; 64 | case FETCH_API_FAILED: 65 | return { 66 | ...state, 67 | isFetching: false, 68 | error: action.payload, 69 | }; 70 | default: 71 | return state; 72 | } 73 | }; 74 | -------------------------------------------------------------------------------- /src/store/api/sagas.ts: -------------------------------------------------------------------------------- 1 | import { takeLatest, call, all, put } from "redux-saga/effects"; 2 | 3 | import { 4 | ProductsApiType, 5 | CategoriesApiType, 6 | ObjectToCategoryApiType, 7 | } from "./reducer"; 8 | 9 | import { 10 | fetchCategoriesApi, 11 | fetchObjectToCategoryApi, 12 | fetchProductApi, 13 | } from "./api"; 14 | 15 | import { 16 | FETCH_API_REQUEST, 17 | FETCH_API_FAILED, 18 | FETCH_API_SUCCESS, 19 | } from "./constants"; 20 | 21 | function* fetchData() { 22 | try { 23 | const productsData: Array = yield call(fetchProductApi); 24 | const categoriesData: Array = yield call( 25 | fetchCategoriesApi 26 | ); 27 | const objectToCategoryData: Array = yield call( 28 | fetchObjectToCategoryApi 29 | ); 30 | 31 | const payload = { 32 | products: productsData, 33 | categories: categoriesData, 34 | objectToCategory: objectToCategoryData, 35 | }; 36 | 37 | yield put({ 38 | type: FETCH_API_SUCCESS, 39 | payload, 40 | }); 41 | } catch (error) { 42 | yield put({ type: FETCH_API_FAILED, payload: error }); 43 | } 44 | } 45 | 46 | export function* apiRootSaga() { 47 | yield all([takeLatest(FETCH_API_REQUEST, fetchData)]); 48 | } 49 | -------------------------------------------------------------------------------- /src/store/graph/actions.ts: -------------------------------------------------------------------------------- 1 | import { createAction } from "store/actions"; 2 | import { 3 | INIT_GRAPH_REQUEST, 4 | SET_START_VERTEX, 5 | EDIT_START_VERTEX_TOGGLE, 6 | } from "./constants"; 7 | 8 | export type Route = { 9 | startVertexKey: string; 10 | endVertexKey: string; 11 | }; 12 | 13 | export const initGraph = () => { 14 | return createAction(INIT_GRAPH_REQUEST); 15 | }; 16 | 17 | export const setStartVertex = (startVertex: string) => { 18 | return createAction(SET_START_VERTEX, startVertex); 19 | }; 20 | 21 | export const toggleEditMode = () => { 22 | return createAction(EDIT_START_VERTEX_TOGGLE); 23 | }; 24 | -------------------------------------------------------------------------------- /src/store/graph/constants.ts: -------------------------------------------------------------------------------- 1 | export const INIT_GRAPH_REQUEST = "INIT_GRAPH_REQUEST"; 2 | export const INIT_GRAPH_SUCCESS = "INIT_GRAPH_SUCCESS"; 3 | export const INIT_GRAPH_FAILED = "INIT_GRAPH_FAILED"; 4 | 5 | export const SET_START_VERTEX = "SET_START_VERTEX"; 6 | 7 | export const EDIT_START_VERTEX_TOGGLE = "EDIT_START_VERTEX_TOGGLE"; 8 | export const EDIT_START_VERTEX_SUCCESS = "EDIT_START_VERTEX_SUCCESS"; 9 | -------------------------------------------------------------------------------- /src/store/graph/reducer.ts: -------------------------------------------------------------------------------- 1 | import { Reducer } from "redux"; 2 | import { Action } from "store/actions"; 3 | 4 | import Graph from "algorithms/graph/Graph"; 5 | 6 | import { 7 | INIT_GRAPH_REQUEST, 8 | INIT_GRAPH_SUCCESS, 9 | INIT_GRAPH_FAILED, 10 | SET_START_VERTEX, 11 | EDIT_START_VERTEX_TOGGLE, 12 | } from "./constants"; 13 | 14 | export type IState = { 15 | readonly graph: Graph | null; 16 | readonly isGenerating: boolean; 17 | readonly startVertex: string; 18 | readonly isEditMode: boolean; 19 | }; 20 | 21 | export const initialState: IState = { 22 | graph: null, 23 | isGenerating: false, 24 | isEditMode: false, 25 | startVertex: "v_95", 26 | }; 27 | 28 | export const graph: Reducer = ( 29 | state = initialState, 30 | action: Action 31 | ) => { 32 | switch (action.type) { 33 | case INIT_GRAPH_REQUEST: 34 | return { 35 | ...state, 36 | isGenerating: true, 37 | }; 38 | case INIT_GRAPH_SUCCESS: 39 | return { 40 | ...state, 41 | isGenerating: false, 42 | graph: action.payload, 43 | }; 44 | case INIT_GRAPH_FAILED: 45 | return { 46 | ...state, 47 | isGenerating: false, 48 | }; 49 | case SET_START_VERTEX: 50 | return { 51 | ...state, 52 | startVertex: action.payload, 53 | isEditMode: false, 54 | }; 55 | case EDIT_START_VERTEX_TOGGLE: 56 | return { 57 | ...state, 58 | isEditMode: !state.isEditMode, 59 | }; 60 | default: 61 | return state; 62 | } 63 | }; 64 | -------------------------------------------------------------------------------- /src/store/graph/sagas.ts: -------------------------------------------------------------------------------- 1 | import { takeLatest, put, all } from "redux-saga/effects"; 2 | 3 | import { mapData } from "components/Map/mapData"; 4 | import { getGraphFromJSON } from "algorithms/graph/Utils"; 5 | 6 | import { 7 | INIT_GRAPH_REQUEST, 8 | INIT_GRAPH_SUCCESS, 9 | INIT_GRAPH_FAILED, 10 | } from "./constants"; 11 | 12 | export function* buildGraph() { 13 | try { 14 | const graph = getGraphFromJSON(mapData); 15 | 16 | yield put({ 17 | type: INIT_GRAPH_SUCCESS, 18 | payload: graph, 19 | }); 20 | } catch (error) { 21 | yield put({ 22 | type: INIT_GRAPH_FAILED, 23 | }); 24 | } 25 | } 26 | 27 | export function* graphRootSaga() { 28 | yield all([takeLatest(INIT_GRAPH_REQUEST, buildGraph)]); 29 | } 30 | -------------------------------------------------------------------------------- /src/store/index.ts: -------------------------------------------------------------------------------- 1 | import { createStore, applyMiddleware } from "redux"; 2 | import createSagaMiddleware from "redux-saga"; 3 | import { composeWithDevTools } from "redux-devtools-extension/developmentOnly"; 4 | import { createBrowserHistory } from "history"; 5 | import rootReducer from "./rootReducer"; 6 | import rootSaga from "./rootSaga"; 7 | 8 | export const history = createBrowserHistory(); 9 | 10 | const configureStore = () => { 11 | const initialState = {}; 12 | const sagaMiddleware = createSagaMiddleware(); 13 | const middleware = [sagaMiddleware]; 14 | 15 | const store = createStore( 16 | rootReducer(history), 17 | initialState, 18 | composeWithDevTools(applyMiddleware(...middleware)) 19 | ); 20 | 21 | sagaMiddleware.run(rootSaga); 22 | return store; 23 | }; 24 | 25 | const store = configureStore(); 26 | 27 | // Auto-update values after state changes to persist them 28 | store.subscribe(() => { 29 | const { settings } = store.getState(); 30 | 31 | localStorage.setItem("lang", settings.lang); 32 | localStorage.setItem("theme", settings.theme); 33 | }); 34 | 35 | export default store; 36 | -------------------------------------------------------------------------------- /src/store/modals/actions.ts: -------------------------------------------------------------------------------- 1 | import { createAction } from "store/actions"; 2 | import { OPEN_MODAL, CLOSE_MODAL } from "./constants"; 3 | 4 | export type ModalPayload = { 5 | modalName: string; 6 | data?: T; 7 | }; 8 | 9 | export const openModal = (data: ModalPayload) => { 10 | return createAction(OPEN_MODAL, data); 11 | }; 12 | 13 | export const closeModal = () => { 14 | return createAction(CLOSE_MODAL); 15 | }; 16 | -------------------------------------------------------------------------------- /src/store/modals/constants.ts: -------------------------------------------------------------------------------- 1 | export const MODAL_SETTINGS = "MODAL_SETTINGS"; 2 | 3 | export const OPEN_MODAL = "OPEN_MODAL"; 4 | export const CLOSE_MODAL = "CLOSE_MODAL"; 5 | -------------------------------------------------------------------------------- /src/store/modals/reducer.ts: -------------------------------------------------------------------------------- 1 | import { Reducer } from "redux"; 2 | import { OPEN_MODAL, CLOSE_MODAL } from "./constants"; 3 | import { Action } from "store/actions"; 4 | 5 | export type IState = { 6 | readonly activeModal: string; 7 | readonly isOpen: boolean; 8 | readonly data: any; 9 | }; 10 | 11 | export const initialState: IState = { 12 | activeModal: "", 13 | isOpen: false, 14 | data: null, 15 | }; 16 | 17 | export const modals: Reducer = ( 18 | state = initialState, 19 | action: Action 20 | ) => { 21 | switch (action.type) { 22 | case OPEN_MODAL: 23 | return { 24 | ...state, 25 | activeModal: action.payload.modalName, 26 | data: action.payload.data, 27 | isOpen: true, 28 | }; 29 | case CLOSE_MODAL: 30 | return { 31 | ...state, 32 | activeModal: "", 33 | data: null, 34 | isOpen: false, 35 | }; 36 | default: 37 | return state; 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /src/store/path/actions.ts: -------------------------------------------------------------------------------- 1 | import { createAction } from "store/actions"; 2 | import { GET_PATH_REQUEST, EXIT_PATH_PREVIEW_REQUEST } from "./constants"; 3 | 4 | export type Route = { 5 | endVertexKey: string; 6 | }; 7 | 8 | export const getPath = (payload: Route) => { 9 | return createAction(GET_PATH_REQUEST, payload); 10 | }; 11 | 12 | export const exitPathPreview = () => { 13 | return createAction(EXIT_PATH_PREVIEW_REQUEST); 14 | }; 15 | -------------------------------------------------------------------------------- /src/store/path/constants.ts: -------------------------------------------------------------------------------- 1 | export const GET_PATH_REQUEST = "GET_PATH_REQUEST"; 2 | export const GET_PATH_SUCCESS = "GET_PATH_SUCCESS"; 3 | export const GET_PATH_FAILED = "GET_PATH_FAILED"; 4 | 5 | export const EXIT_PATH_PREVIEW_REQUEST = "EXIT_PATH_PREVIEW_REQUEST"; 6 | export const EXIT_PATH_PREVIEW_SUCCESS = "EXIT_PATH_PREVIEW_SUCCESS"; 7 | -------------------------------------------------------------------------------- /src/store/path/reducer.ts: -------------------------------------------------------------------------------- 1 | import { Reducer } from "redux"; 2 | import { Action } from "store/actions"; 3 | 4 | import Vertex from "algorithms/graph/Vertex"; 5 | import Edge from "algorithms/graph/Edge"; 6 | 7 | import { 8 | GET_PATH_REQUEST, 9 | GET_PATH_SUCCESS, 10 | GET_PATH_FAILED, 11 | EXIT_PATH_PREVIEW_SUCCESS, 12 | } from "./constants"; 13 | 14 | export type IState = { 15 | readonly isGenerating: boolean; 16 | readonly isPathPreview: boolean; 17 | readonly pathTimeline: GSAPTimeline | null; 18 | readonly dijkstra: { 19 | readonly vertices: Vertex[]; 20 | readonly edges: Edge[]; 21 | }; 22 | }; 23 | 24 | export const initialState: IState = { 25 | isGenerating: false, 26 | isPathPreview: false, 27 | pathTimeline: null, 28 | dijkstra: { 29 | vertices: [], 30 | edges: [], 31 | }, 32 | }; 33 | 34 | export const path: Reducer = ( 35 | state = initialState, 36 | action: Action 37 | ) => { 38 | switch (action.type) { 39 | case GET_PATH_REQUEST: 40 | return { 41 | ...state, 42 | isGenerating: true, 43 | }; 44 | case GET_PATH_SUCCESS: 45 | return { 46 | ...state, 47 | isGenerating: false, 48 | isPathPreview: true, 49 | pathTimeline: action.payload.timeline, 50 | dijkstra: { 51 | vertices: action.payload.vertices, 52 | edges: action.payload.edges, 53 | }, 54 | }; 55 | case GET_PATH_FAILED: 56 | return { 57 | ...state, 58 | isGenerating: false, 59 | }; 60 | case EXIT_PATH_PREVIEW_SUCCESS: 61 | return { 62 | ...state, 63 | isPathPreview: false, 64 | pathTimeline: null, 65 | dijkstra: { 66 | vertices: [], 67 | edges: [], 68 | }, 69 | }; 70 | default: 71 | return state; 72 | } 73 | }; 74 | -------------------------------------------------------------------------------- /src/store/path/sagas.ts: -------------------------------------------------------------------------------- 1 | import { takeLatest, put, all, select } from "redux-saga/effects"; 2 | 3 | import { AppState } from "store/rootReducer"; 4 | import { Action } from "store/actions"; 5 | import { Route } from "store/graph/actions"; 6 | 7 | import { gsap } from "gsap"; 8 | import { getPathFromDijkstra } from "algorithms/graph/Utils"; 9 | import dijkstra from "algorithms/graph/Dijkstra"; 10 | 11 | import { 12 | GET_PATH_REQUEST, 13 | GET_PATH_SUCCESS, 14 | GET_PATH_FAILED, 15 | EXIT_PATH_PREVIEW_REQUEST, 16 | EXIT_PATH_PREVIEW_SUCCESS, 17 | } from "./constants"; 18 | import Vertex from "algorithms/graph/Vertex"; 19 | 20 | export function* getPath(action: Action) { 21 | try { 22 | if (action.payload) { 23 | const { graph, startVertex: startVertexKey } = yield select( 24 | (state: AppState) => state.graph 25 | ); 26 | const { endVertexKey } = action.payload; 27 | 28 | const startVertex: Vertex = graph.getVertices()[startVertexKey]; 29 | const endVertex: Vertex = graph.getVertices()[endVertexKey]; 30 | 31 | const { previousVertices } = dijkstra(graph, startVertex); 32 | const { vertices, edges } = getPathFromDijkstra( 33 | graph.getEdges(), 34 | previousVertices, 35 | endVertex 36 | ); 37 | 38 | const timeline = gsap.timeline({ 39 | paused: true, 40 | }); 41 | 42 | yield put({ 43 | type: GET_PATH_SUCCESS, 44 | payload: { 45 | vertices, 46 | edges, 47 | timeline, 48 | }, 49 | }); 50 | } 51 | } catch (error) { 52 | yield put({ 53 | type: GET_PATH_FAILED, 54 | }); 55 | } 56 | } 57 | export function* resetPath() { 58 | try { 59 | const { pathTimeline } = yield select((state: AppState) => state.path); 60 | pathTimeline.reverse(); 61 | 62 | // GSAP isn't removing inline styles after reversing, 63 | // so i have to manually add and remove this class, 64 | // to allow theme switching. 65 | pathTimeline._last._targets[0].classList.remove("Object--active"); 66 | 67 | yield put({ 68 | type: EXIT_PATH_PREVIEW_SUCCESS, 69 | }); 70 | } catch (error) { 71 | } 72 | } 73 | 74 | export function* pathRootSaga() { 75 | yield all([takeLatest(GET_PATH_REQUEST, getPath)]); 76 | yield all([takeLatest(EXIT_PATH_PREVIEW_REQUEST, resetPath)]); 77 | } 78 | -------------------------------------------------------------------------------- /src/store/rootReducer.ts: -------------------------------------------------------------------------------- 1 | import { combineReducers } from "redux"; 2 | import { History } from "history"; 3 | 4 | import { settings, IState as SettingsState } from "./settings/reducer"; 5 | import { sidebar, IState as SidebarState } from "./sidebar/reducer"; 6 | import { modals, IState as ModalState } from "./modals/reducer"; 7 | import { graph, IState as GraphState } from "./graph/reducer"; 8 | import { path, IState as PathState } from "./path/reducer"; 9 | import { search, IState as SearchState } from "./search/reducer"; 10 | import { api, IState as ApiState } from "./api/reducer"; 11 | 12 | export interface AppState { 13 | settings: SettingsState; 14 | sidebar: SidebarState; 15 | modals: ModalState; 16 | graph: GraphState; 17 | path: PathState; 18 | search: SearchState; 19 | api: ApiState; 20 | } 21 | 22 | const rootReducer = combineReducers({ 23 | settings, 24 | sidebar, 25 | modals, 26 | graph, 27 | path, 28 | search, 29 | api, 30 | }); 31 | 32 | export type RootState = ReturnType; 33 | 34 | export default (history: History) => rootReducer; 35 | -------------------------------------------------------------------------------- /src/store/rootSaga.ts: -------------------------------------------------------------------------------- 1 | import { all, fork } from "redux-saga/effects"; 2 | 3 | import { graphRootSaga } from "store/graph/sagas"; 4 | import { pathRootSaga } from "store/path/sagas"; 5 | import { searchRootSaga } from "store/search/sagas"; 6 | import { apiRootSaga } from "store/api/sagas"; 7 | 8 | const sagas = [graphRootSaga, pathRootSaga, searchRootSaga, apiRootSaga]; 9 | 10 | export default function* rootSaga() { 11 | yield all(sagas.map((saga) => fork(saga))); 12 | } 13 | -------------------------------------------------------------------------------- /src/store/search/actions.ts: -------------------------------------------------------------------------------- 1 | import { createAction } from "store/actions"; 2 | import { SEARCH_PRODUCT_REQUEST } from "./constants"; 3 | 4 | export const searchProduct = (productName: string) => { 5 | return createAction(SEARCH_PRODUCT_REQUEST, productName); 6 | }; 7 | -------------------------------------------------------------------------------- /src/store/search/api.ts: -------------------------------------------------------------------------------- 1 | import { ProductsApiType } from "store/api/reducer"; 2 | import db from "store/api/db"; 3 | 4 | export const searchProductApi = (productName: string) => { 5 | return new Promise>((resolve) => { 6 | const arr = [...db["products"]]; 7 | 8 | const results = arr.filter((item) => { 9 | return item.name === productName; 10 | }); 11 | 12 | resolve(results); 13 | }); 14 | }; 15 | -------------------------------------------------------------------------------- /src/store/search/constants.ts: -------------------------------------------------------------------------------- 1 | export const SEARCH_PRODUCT_REQUEST = "SEARCH_PRODUCT_REQUEST"; 2 | export const SEARCH_PRODUCT_SUCCESS = "SEARCH_PRODUCT_SUCCESS"; 3 | export const SEARCH_PRODUCT_FAILED = "SEARCH_PRODUCT_FAILED"; 4 | -------------------------------------------------------------------------------- /src/store/search/reducer.ts: -------------------------------------------------------------------------------- 1 | import { Reducer } from "redux"; 2 | import { Action } from "store/actions"; 3 | 4 | import { 5 | SEARCH_PRODUCT_FAILED, 6 | SEARCH_PRODUCT_REQUEST, 7 | SEARCH_PRODUCT_SUCCESS, 8 | } from "./constants"; 9 | 10 | type ProductType = { 11 | id: number; 12 | name: string; 13 | desc: string; 14 | objectId: string; 15 | }; 16 | 17 | export type IState = { 18 | readonly isPending: boolean; 19 | readonly searchResult: ProductType | null; 20 | }; 21 | 22 | export const initialState: IState = { 23 | isPending: false, 24 | searchResult: null, 25 | }; 26 | 27 | export const search: Reducer = ( 28 | state = initialState, 29 | action: Action 30 | ) => { 31 | switch (action.type) { 32 | case SEARCH_PRODUCT_REQUEST: 33 | return { 34 | ...state, 35 | isPending: true, 36 | }; 37 | case SEARCH_PRODUCT_SUCCESS: 38 | return { 39 | ...state, 40 | isPending: false, 41 | searchResult: action.payload, 42 | }; 43 | case SEARCH_PRODUCT_FAILED: 44 | return { 45 | ...state, 46 | isPending: false, 47 | searchResult: {}, 48 | }; 49 | default: 50 | return state; 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /src/store/search/sagas.ts: -------------------------------------------------------------------------------- 1 | import { takeLatest, call, all, put } from "redux-saga/effects"; 2 | import { Action } from "store/actions"; 3 | import { apiArrayToObject } from "utils/helpers"; 4 | import { objectToVertexKey } from "algorithms/graph/Utils"; 5 | import { ProductsApiType } from "store/api/reducer"; 6 | 7 | import { 8 | SEARCH_PRODUCT_FAILED, 9 | SEARCH_PRODUCT_REQUEST, 10 | SEARCH_PRODUCT_SUCCESS, 11 | } from "./constants"; 12 | 13 | import { GET_PATH_REQUEST } from "store/path/constants"; 14 | 15 | import { searchProductApi } from "./api"; 16 | 17 | function* searchProduct(action: Action) { 18 | try { 19 | if (action.payload) { 20 | const productName = action.payload; 21 | const response: Array = yield call( 22 | searchProductApi, 23 | productName 24 | ); 25 | 26 | // Shitty workaround for json-server because when product is not found 27 | // it still returns 200 so I have to check it manually. 28 | if (response && response.length) { 29 | // Also I'm fetching single product but json-server returns it 30 | // as single element array instead of object... 31 | const product: ProductsApiType = apiArrayToObject(response); 32 | yield put({ type: SEARCH_PRODUCT_SUCCESS, payload: product }); 33 | 34 | const endVertex = objectToVertexKey(product.objectId); 35 | 36 | if (endVertex) { 37 | yield put({ 38 | type: GET_PATH_REQUEST, 39 | payload: { 40 | endVertexKey: endVertex, 41 | }, 42 | }); 43 | } 44 | } else { 45 | throw new Error(); 46 | } 47 | } 48 | } catch (error) { 49 | yield put({ type: SEARCH_PRODUCT_FAILED }); 50 | } 51 | } 52 | 53 | export function* searchRootSaga() { 54 | yield all([takeLatest(SEARCH_PRODUCT_REQUEST, searchProduct)]); 55 | } 56 | -------------------------------------------------------------------------------- /src/store/settings/actions.ts: -------------------------------------------------------------------------------- 1 | import { createAction } from "store/actions"; 2 | import { SWITCH_LANG, SWITCH_THEME } from "./constants"; 3 | 4 | export const switchTheme = (theme: string) => { 5 | return createAction(SWITCH_THEME, theme); 6 | }; 7 | 8 | export const switchLang = (lang: string) => { 9 | return createAction(SWITCH_LANG, lang); 10 | }; 11 | -------------------------------------------------------------------------------- /src/store/settings/constants.ts: -------------------------------------------------------------------------------- 1 | export const SWITCH_LANG = "SWITCH_LANG"; 2 | export const SWITCH_THEME = "SWITCH_THEME"; 3 | -------------------------------------------------------------------------------- /src/store/settings/reducer.ts: -------------------------------------------------------------------------------- 1 | import { Reducer } from "redux"; 2 | import { SWITCH_LANG, SWITCH_THEME } from "./constants"; 3 | import { Action } from "store/actions"; 4 | 5 | export type IState = { 6 | readonly theme: string; 7 | readonly lang: string; 8 | }; 9 | 10 | export const initialState: IState = { 11 | theme: localStorage.getItem("theme") || "light", 12 | lang: localStorage.getItem("lang") || "pl", 13 | }; 14 | 15 | export const settings: Reducer = ( 16 | state = initialState, 17 | action: Action 18 | ) => { 19 | switch (action.type) { 20 | case SWITCH_THEME: 21 | return { 22 | ...state, 23 | theme: action.payload, 24 | }; 25 | case SWITCH_LANG: 26 | return { 27 | ...state, 28 | lang: action.payload, 29 | }; 30 | default: 31 | return state; 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /src/store/sidebar/actions.ts: -------------------------------------------------------------------------------- 1 | import { createAction } from "store/actions"; 2 | import { TOGGLE_SIDEBAR } from "./constants"; 3 | 4 | export const toggleSidebar = () => createAction(TOGGLE_SIDEBAR); 5 | -------------------------------------------------------------------------------- /src/store/sidebar/constants.ts: -------------------------------------------------------------------------------- 1 | export const TOGGLE_SIDEBAR = "TOGGLE_SIDEBAR"; 2 | -------------------------------------------------------------------------------- /src/store/sidebar/reducer.ts: -------------------------------------------------------------------------------- 1 | import { Reducer } from "redux"; 2 | import { TOGGLE_SIDEBAR } from "./constants"; 3 | import { Action } from "store/actions"; 4 | 5 | export type IState = { 6 | readonly isOpen: boolean; 7 | }; 8 | 9 | export const initialState: IState = { 10 | isOpen: true, 11 | }; 12 | 13 | export const sidebar: Reducer = ( 14 | state = initialState, 15 | action: Action 16 | ) => { 17 | switch (action.type) { 18 | case TOGGLE_SIDEBAR: 19 | return { 20 | ...state, 21 | isOpen: !state.isOpen, 22 | }; 23 | default: 24 | return state; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /src/styles/index.scss: -------------------------------------------------------------------------------- 1 | @import "styles/themes.scss"; 2 | 3 | *, 4 | h1, 5 | h2, 6 | h3, 7 | h4, 8 | h5, 9 | h6, 10 | p { 11 | margin: 0; 12 | padding: 0; 13 | box-sizing: border-box; 14 | } 15 | 16 | html, 17 | body, 18 | #root, 19 | #app { 20 | height: 100%; 21 | } 22 | 23 | html { 24 | font-size: 62.5%; 25 | } 26 | 27 | body { 28 | font-family: "Montserrat"; 29 | font-size: 1.6rem; 30 | } 31 | 32 | // Override for my theme 33 | .react-transform-component, 34 | .react-transform-element { 35 | width: 100% !important; 36 | height: 100% !important; 37 | } 38 | 39 | .ReactModal__Overlay { 40 | opacity: 0; 41 | } 42 | 43 | .ReactModal__Overlay--after-open { 44 | opacity: 1; 45 | } 46 | 47 | .ReactModal__Overlay--before-close { 48 | opacity: 0; 49 | } 50 | 51 | .ModalOverlay { 52 | display: flex; 53 | align-items: center; 54 | justify-content: center; 55 | position: fixed; 56 | top: 0px; 57 | left: 0px; 58 | right: 0px; 59 | bottom: 0px; 60 | overflow: hidden; 61 | transition: opacity 200ms ease-in-out; 62 | background: rgba(0, 0, 0, 0.6) !important; 63 | z-index: 10; 64 | } 65 | 66 | .sr-only { 67 | position: absolute; 68 | width: 1px; 69 | height: 1px; 70 | padding: 0; 71 | margin: -1px; 72 | overflow: hidden; 73 | clip: rect(0, 0, 0, 0); 74 | white-space: nowrap; /* added line */ 75 | border: 0; 76 | } 77 | 78 | // GSAP isn't removing inline styles after reversing, 79 | // so i have to manually add and remove this class, 80 | // to allow theme switching. 81 | .Object--active { 82 | fill: var(--object-fill--active) !important; 83 | stroke: var(--object-stroke--active) !important; 84 | } 85 | -------------------------------------------------------------------------------- /src/styles/themes.scss: -------------------------------------------------------------------------------- 1 | @import "styles/variables.scss"; 2 | 3 | // Default colors 4 | :root { 5 | --primary-white: #ffffff; 6 | --green: #2ecc71; 7 | 8 | --primary: #1b78d0; 9 | --primary--light: #54a8f8; 10 | --primary--dark: #000000; 11 | 12 | --floor: #ffffff; 13 | --floor-stroke: #f8f8f8; 14 | 15 | --vertex: #e4e4e4; 16 | --object-fill: #d6ebff; 17 | --object-fill--hover: #b2d5f6; 18 | --object-stroke: #87b6e2; 19 | 20 | --map-bg: #f3f7fa; 21 | 22 | --close-red: #db3b3b; 23 | 24 | --input-bg: #ffffff; 25 | --input-separator: #f1f1f1; 26 | --input-placeholder: #afafaf; 27 | 28 | --searchProduct-icon: #ffffff; 29 | --searchProduct-input: #ffffff; 30 | --searchProduct-input-color: #000000; 31 | --searchProduct-input-placeholder: #ffffff; 32 | --searchProduct-submit-color: #ffffff; 33 | --searchProduct-submit-bg: #1b78d0; 34 | 35 | --autocomplete-bg: #ffffff; 36 | --autocomplete-text: #6c6c6c; 37 | --autocomplete-hover: #f7fbff; 38 | --autocomplete-borderTop: #e1ecee; 39 | --autocomplete-border: #e1ecee; 40 | 41 | --pathPreview-bg: #ffffff; 42 | --pathPreview-text: #000000; 43 | 44 | --button-disabled: #dadada; 45 | --button-editMode: #2ecc71; 46 | --button-color: #ffffff; 47 | --button-tooltip-bg: #000000; 48 | --button-tooltip-color: #ffffff; 49 | 50 | --object-fill--active: #c7ffcc; 51 | --object-stroke--active: #4fba5a; 52 | 53 | --scrollbar-track: #e7e7e7; 54 | --scrollbar-thumb: #1b78d0; 55 | --scrollbar-thumb--sidebar: #a9a9a9; 56 | 57 | --modal-bg: #ffffff; 58 | --modal-text: #000000; 59 | --modal-text-light: #6c6c6c; 60 | --modal-border: #e1e2e2; 61 | 62 | --modal-settings-titleUnderline: #e1e2e2; 63 | --modal-settings-text: #2e2e2e; 64 | --modal-settings-langBorder: #4e4e4e; 65 | --modal-settings-langBg: 0; 66 | --modal-settings-langColor: #000000; 67 | 68 | --modal-switch-bg: #e1e2e2; 69 | --modal-switch-dot: #ffffff; 70 | --modal-switch-outline: #5d9dd5; 71 | 72 | --modal-settings-langBorder: #e1e2e2; 73 | 74 | --sidebar-bg: #ffffff; 75 | --sidebar-headerTitle: #000000; 76 | --sidebar-headerText: #6c6c6c; 77 | 78 | --sidebar-buttonMain-bg: #1b78d0; 79 | --sidebar-buttonMain-bg--hover: #166bbb; 80 | --sidebar-buttonMain-text: #ffffff; 81 | 82 | --sidebar-category-letter: #000000; 83 | --sidebar-category-results: #000000; 84 | 85 | --sidebar-buttonSecond-bg: #daebff; 86 | --sidebar-buttonSecond-bg--hover: #cadff6; 87 | --sidebar-buttonSecond-text: #2668a6; 88 | 89 | --sidebar-categoryItem-bg: #f4faff; 90 | --sidebar-categoryItem-photo: #d4e8ff; 91 | --sidebar-categoryItem-title: #000000; 92 | --sidebar-categoryItem-text: #000000; 93 | --sidebar-categoryItem-itemLink: #daebff; 94 | 95 | --sidebar-footer: #000000; 96 | 97 | --skiplink-text: #ffffff; 98 | } 99 | 100 | // Dark theme colors 101 | [data-theme="dark"] { 102 | --primary-white: #ffffff; 103 | --green: #2ecc71; 104 | 105 | --primary: #1b78d0; 106 | --primary--light: #54a8f8; 107 | --primary--dark: #000000; 108 | 109 | --floor: #343947; 110 | --floor-stroke: #414757; 111 | 112 | --vertex: #4c5f6e; 113 | --object-fill: #355877; 114 | --object-fill--hover: #477eaf; 115 | --object-stroke: #7ec1ff; 116 | 117 | --map-bg: #1a1f27; 118 | 119 | --close-red: #db3b3b; 120 | 121 | --input-bg: #282a30; 122 | --input-separator: #4e4e4e; 123 | --input-placeholder: #afafaf; 124 | 125 | --searchProduct-icon: #282a30; 126 | --searchProduct-input: #282a30; 127 | --searchProduct-input-color: #ffffff; 128 | --searchProduct-input-placeholder: #6c6c6c; 129 | --searchProduct-submit-color: #ffffff; 130 | --searchProduct-submit-bg: #1b78d0; 131 | 132 | --autocomplete-bg: #282a30; 133 | --autocomplete-text: #afafaf; 134 | --autocomplete-hover: #0b0b0c; 135 | --autocomplete-border: #4e4e4e; 136 | 137 | --pathPreview-bg: #282a30; 138 | --pathPreview-text: #ffffff; 139 | 140 | --button-disabled: #3b3f49; 141 | --button-editMode: #2ecc71; 142 | --button-color: #ffffff; 143 | --button-tooltip-bg: #3b3f49; 144 | --button-tooltip-color: #ffffff; 145 | 146 | --object-fill--active: #4fba5a; 147 | --object-stroke--active: #2ecc71; 148 | 149 | --scrollbar-track: #4e4e4e; 150 | --scrollbar-thumb: #1b78d0; 151 | --scrollbar-thumb--sidebar: #4e4e4e; 152 | 153 | --modal-bg: #32343b; 154 | --modal-text: #ffffff; 155 | --modal-text-light: #bdbdbd; 156 | --modal-border: #4e4e4e; 157 | 158 | --modal-settings-titleUnderline: #4e4e4e; 159 | --modal-settings-text: #2e2e2e; 160 | --modal-settings-langBorder: #4e4e4e; 161 | --modal-settings-langBg: #ffffff; 162 | --modal-settings-langColor: #000000; 163 | 164 | --modal-switch-bg: #e1e2e2; 165 | --modal-switch-dot: #ffffff; 166 | --modal-switch-outline: #5d9dd5; 167 | 168 | --modal-settings-langBorder: #e1e2e2; 169 | 170 | --sidebar-bg: #282a30; 171 | --sidebar-headerTitle: #ffffff; 172 | --sidebar-headerText: #c1c1c1; 173 | 174 | --sidebar-buttonMain-bg: #1b78d0; 175 | --sidebar-buttonMain-bg--hover: #166bbb; 176 | --sidebar-buttonMain-text: #ffffff; 177 | 178 | --sidebar-buttonSecond-bg: #3f4862; 179 | --sidebar-buttonSecond-bg--hover: #333b53; 180 | --sidebar-buttonSecond-text: #ffffff; 181 | 182 | --sidebar-category-letter: #ffffff; 183 | --sidebar-category-results: #c1c1c1; 184 | 185 | --sidebar-categoryItem-bg: #363941; 186 | --sidebar-categoryItem-photo: #282a30; 187 | --sidebar-categoryItem-title: #ffffff; 188 | --sidebar-categoryItem-text: #c1c1c1; 189 | --sidebar-categoryItem-itemLink: #99caf8; 190 | 191 | --sidebar-footer: #ffffff; 192 | 193 | --skiplink-text: #ffffff; 194 | } 195 | -------------------------------------------------------------------------------- /src/styles/variables.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejb2k/pathfinding_app/40b3880586173b0f55dbcf496cc07228c143f455/src/styles/variables.scss -------------------------------------------------------------------------------- /src/utils/__tests__/helpers.test.ts: -------------------------------------------------------------------------------- 1 | import { apiArrayToObject, capitalize } from "utils/helpers"; 2 | 3 | describe("helpers.ts", () => { 4 | it("should return first element from array", () => { 5 | const arr = ["john", "doe"]; 6 | 7 | expect(apiArrayToObject(arr)).toBe(arr[0]); 8 | }); 9 | 10 | it("should capitalize first letter in string", () => { 11 | const letter = "t"; 12 | const capitalized = capitalize(letter); 13 | 14 | expect(capitalized).toBe(letter.toUpperCase()); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/utils/__tests__/initLocalStorage.test.ts: -------------------------------------------------------------------------------- 1 | import { apiArrayToObject, capitalize } from "utils/helpers"; 2 | 3 | describe("initLocalStorage.ts", () => { 4 | it("should return first element from array", () => { 5 | const arr = ["john", "doe"]; 6 | 7 | expect(apiArrayToObject(arr)).toBe(arr[0]); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /src/utils/helpers.ts: -------------------------------------------------------------------------------- 1 | export const apiArrayToObject = (arr: Array) => { 2 | return arr[0]; 3 | }; 4 | 5 | export const capitalize = (text: string) => { 6 | return text.charAt(0).toUpperCase() + text.slice(1); 7 | }; 8 | -------------------------------------------------------------------------------- /src/utils/i18n/index.ts: -------------------------------------------------------------------------------- 1 | import i18n from "i18next"; 2 | import { initReactI18next } from "react-i18next"; 3 | 4 | import translation_pl from "./translations/pl.json"; 5 | import translation_en from "./translations/en.json"; 6 | 7 | const resources = { 8 | pl: { 9 | translation: translation_pl, 10 | }, 11 | en: { 12 | translation: translation_en, 13 | }, 14 | }; 15 | 16 | i18n.use(initReactI18next).init({ 17 | resources, 18 | lng: "pl", 19 | keySeparator: false, 20 | interpolation: { 21 | escapeValue: false, 22 | }, 23 | }); 24 | 25 | export default i18n; 26 | -------------------------------------------------------------------------------- /src/utils/i18n/translations/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "hello": "Welcome to React and react-i18next" 3 | } 4 | -------------------------------------------------------------------------------- /src/utils/i18n/translations/pl.json: -------------------------------------------------------------------------------- 1 | { 2 | "hello": "Witaj w React i react-i18next" 3 | } 4 | -------------------------------------------------------------------------------- /src/utils/initLocalStorage.ts: -------------------------------------------------------------------------------- 1 | export const initLocalStorageSettings = () => { 2 | if (!localStorage.getItem("lang")) { 3 | localStorage.setItem("lang", "pl"); 4 | } 5 | if (!localStorage.getItem("theme")) { 6 | localStorage.setItem("theme", "light"); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /src/utils/serviceWorker.ts: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | type Config = { 24 | onSuccess?: (registration: ServiceWorkerRegistration) => void; 25 | onUpdate?: (registration: ServiceWorkerRegistration) => void; 26 | }; 27 | 28 | export function register(config?: Config) { 29 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 30 | // The URL constructor is available in all browsers that support SW. 31 | const publicUrl = new URL( 32 | process.env.PUBLIC_URL, 33 | window.location.href 34 | ); 35 | if (publicUrl.origin !== window.location.origin) { 36 | // Our service worker won't work if PUBLIC_URL is on a different origin 37 | // from what our page is served on. This might happen if a CDN is used to 38 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 39 | return; 40 | } 41 | 42 | window.addEventListener('load', () => { 43 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 44 | 45 | if (isLocalhost) { 46 | // This is running on localhost. Let's check if a service worker still exists or not. 47 | checkValidServiceWorker(swUrl, config); 48 | 49 | // Add some additional logging to localhost, pointing developers to the 50 | // service worker/PWA documentation. 51 | navigator.serviceWorker.ready.then(() => { 52 | console.log( 53 | 'This web app is being served cache-first by a service ' + 54 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 55 | ); 56 | }); 57 | } else { 58 | // Is not localhost. Just register service worker 59 | registerValidSW(swUrl, config); 60 | } 61 | }); 62 | } 63 | } 64 | 65 | function registerValidSW(swUrl: string, config?: Config) { 66 | navigator.serviceWorker 67 | .register(swUrl) 68 | .then(registration => { 69 | registration.onupdatefound = () => { 70 | const installingWorker = registration.installing; 71 | if (installingWorker == null) { 72 | return; 73 | } 74 | installingWorker.onstatechange = () => { 75 | if (installingWorker.state === 'installed') { 76 | if (navigator.serviceWorker.controller) { 77 | // At this point, the updated precached content has been fetched, 78 | // but the previous service worker will still serve the older 79 | // content until all client tabs are closed. 80 | console.log( 81 | 'New content is available and will be used when all ' + 82 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 83 | ); 84 | 85 | // Execute callback 86 | if (config && config.onUpdate) { 87 | config.onUpdate(registration); 88 | } 89 | } else { 90 | // At this point, everything has been precached. 91 | // It's the perfect time to display a 92 | // "Content is cached for offline use." message. 93 | console.log('Content is cached for offline use.'); 94 | 95 | // Execute callback 96 | if (config && config.onSuccess) { 97 | config.onSuccess(registration); 98 | } 99 | } 100 | } 101 | }; 102 | }; 103 | }) 104 | .catch(error => { 105 | console.error('Error during service worker registration:', error); 106 | }); 107 | } 108 | 109 | function checkValidServiceWorker(swUrl: string, config?: Config) { 110 | // Check if the service worker can be found. If it can't reload the page. 111 | fetch(swUrl, { 112 | headers: { 'Service-Worker': 'script' } 113 | }) 114 | .then(response => { 115 | // Ensure service worker exists, and that we really are getting a JS file. 116 | const contentType = response.headers.get('content-type'); 117 | if ( 118 | response.status === 404 || 119 | (contentType != null && contentType.indexOf('javascript') === -1) 120 | ) { 121 | // No service worker found. Probably a different app. Reload the page. 122 | navigator.serviceWorker.ready.then(registration => { 123 | registration.unregister().then(() => { 124 | window.location.reload(); 125 | }); 126 | }); 127 | } else { 128 | // Service worker found. Proceed as normal. 129 | registerValidSW(swUrl, config); 130 | } 131 | }) 132 | .catch(() => { 133 | console.log( 134 | 'No internet connection found. App is running in offline mode.' 135 | ); 136 | }); 137 | } 138 | 139 | export function unregister() { 140 | if ('serviceWorker' in navigator) { 141 | navigator.serviceWorker.ready 142 | .then(registration => { 143 | registration.unregister(); 144 | }) 145 | .catch(error => { 146 | console.error(error.message); 147 | }); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/utils/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import "@testing-library/jest-dom/extend-expect"; 6 | import "@testing-library/jest-dom"; 7 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "esModuleInterop": true, 8 | "allowSyntheticDefaultImports": true, 9 | "strict": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "noEmit": true, 16 | "jsx": "react", 17 | "baseUrl": "src", 18 | "downlevelIteration": true 19 | }, 20 | "include": ["src"] 21 | } 22 | --------------------------------------------------------------------------------