Advertisement
ptownhero

Is this clean code?

Mar 18th, 2022
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { captureDOM } from '../index.js';
  2.  
  3. // Global Functions
  4. const stopPropagation = (event) => {
  5.     event.stopPropagation();
  6. }
  7.  
  8. // Modules
  9. const manageList = (function () {
  10.     // Initializing important variables
  11.     // Used in createList for the bulletinBoard array
  12.     let idCounter = 1;
  13.     let bulletinBoard = [];
  14.  
  15.     // Creating a Checklist Factory Function
  16.     const listFactory = (
  17.         id, title, description, creationDate,
  18.         dueDate, priority, list,
  19.     ) => {
  20.         return {
  21.             id, title, description, creationDate,
  22.             dueDate, priority, list,
  23.         };
  24.     };
  25.  
  26.     // This counter is used to add IDs to the new listList objects
  27.  
  28.     const createList = (event) => {
  29.         // Preventing the page from reloading
  30.         event.preventDefault();
  31.  
  32.         // Puling form data
  33.         let fd = new FormData(captureDOM.form);
  34.  
  35.         // WITH DATE FNS ADD THE CURRENT DATE TODAY, FOR THE CREATION DATE
  36.         // Creating a placeholder list to carry all of our information
  37.         let newList = listFactory();
  38.         newList['id'] = idCounter;
  39.         newList['list'] = [];
  40.         // This is placeholder
  41.         newList['creationDate'] = 'Today';
  42.         let key;
  43.         for (key of fd.keys(key)) {
  44.             newList[key] = fd.get(key);
  45.         }
  46.  
  47.         // Resetting form values
  48.         captureDOM.form.reset();
  49.  
  50.         // now that we are done creating the list, we add the list to
  51.         // our bulletinBoard, then increment our idCounter
  52.         bulletinBoard[idCounter] = newList;
  53.         idCounter++;
  54.  
  55.  
  56.     };
  57.  
  58.     // This will delete a todo list from the bulletinBoard array
  59.     // when the trashcan with the corresponding ID is clicked
  60.     const deleteList = () => {
  61.  
  62.     }
  63.  
  64.     return {
  65.         bulletinBoard: bulletinBoard,
  66.         createList: createList,
  67.     };
  68. })();
  69.  
  70. // This module will hold all functions related to creating the DOM
  71. const createPage = (function () {
  72.  
  73.     // Initializing Variables
  74.     // Used in bulletinBoard as a counter
  75.     let i = 0;
  76.  
  77.     // Creating Functions
  78.     // This function toggles the display property of the form
  79.     const toggleForm = (configuration, x) => {
  80.         switch (configuration){
  81.         case 'toggle' :
  82.             if(x.classList.contains('hidden') == true) {
  83.                 x.classList.remove('hidden');
  84.             }
  85.             else {
  86.                 x.classList += ' hidden';
  87.             }
  88.             break;
  89.            
  90.         case 'add' :
  91.             x.classList += ' hidden';
  92.             break;
  93.  
  94.         case 'remove' :
  95.             x.classList.remove('hidden');
  96.             break;
  97.  
  98.     }  
  99. }
  100.  
  101.     // Function to create our lists, either through a loop or single increments
  102.     // This feature is dependent on the configuration setting used
  103.     // The two settings are "add" or "loop"
  104.     const bulletinBoard = (configuration) => {
  105.        
  106.         // Function to add list to the DOM
  107.         const bulletinBoardSetup = (i) => {
  108.             if (i === 0) {
  109.                 i++;
  110.                 return;
  111.             }
  112.  
  113.             // Creating Elements
  114.             const list = document.createElement('section');
  115.             const title = document.createElement('h2');
  116.             const description = document.createElement('p');
  117.             const dueDate = document.createElement('p');
  118.             const deleteButton = document.createElement('img');
  119.  
  120.             // Manipulating Elements
  121.             // List Section
  122.             list.dataset.id = manageList.bulletinBoard[i]['id'];
  123.             list.className = 'list-section';
  124.  
  125.             // List Title
  126.             title.className = 'list-title';
  127.             title.textContent = manageList.bulletinBoard[i]['title'];
  128.  
  129.             // List Description
  130.             description.className = 'list-description';
  131.             description.textContent = manageList.bulletinBoard[i]['description'];
  132.  
  133.             // List Due Date
  134.             dueDate.className = 'list-due-date';
  135.             dueDate.textContent = manageList.bulletinBoard[i]['dueDate'];
  136.            
  137.             // List Delete Button
  138.             deleteButton.dataset.id = manageList.bulletinBoard[i]['id'];
  139.             deleteButton.className = 'list-delete-button';
  140.            
  141.             // Appending Elements
  142.             captureDOM.content.appendChild(list);
  143.             list.append(title, description, dueDate, deleteButton);
  144.         }
  145.        
  146.         // This is used to render all stored lists
  147.         if (configuration === 'loop') {
  148.        
  149.             for(let i = 0; i < manageList.bulletinBoard.length; i++){
  150.                 bulletinBoardSetup(i);
  151.             }
  152.         }
  153.  
  154.         if (configuration === 'add') {
  155.             bulletinBoardSetup(i);
  156.         }
  157.         i++;
  158.  
  159.         // This will create each list's specific page
  160.         const list = () => {
  161.            
  162.         }
  163.  
  164.     }
  165.  
  166.  
  167.     return {
  168.         bulletinBoard: bulletinBoard,
  169.         toggleForm: toggleForm,
  170.     }
  171. })();
  172.  
  173.  
  174.  
  175. export { manageList, createPage, stopPropagation };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement