All files AppState.js

98.9% Statements 180/182
100% Branches 24/24
95.45% Functions 21/22
98.9% Lines 180/182

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 2051x   1x 1x 1x 1x 1x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x   1x 1x 1x 1x 1x 4x 4x   1x 1x 1x 1x 1x 4x 4x   1x 1x 1x 1x 1x 3x 3x   1x 1x 1x 1x 1x 4x 4x   1x 1x 1x 1x 1x 2x 2x   1x 1x 1x 1x 1x 3x 3x   1x 1x 1x 1x 1x 2x 2x   1x 1x 1x 1x 1x 3x 3x   1x 1x 1x 1x 1x 2x 2x   1x 1x 1x 1x 1x 3x 3x   1x 1x 1x 1x 1x 2x 2x   1x 1x 1x 1x 1x 3x 3x   1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 3x 3x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 22x 22x 22x 22x 22x   1x 1x 1x 1x 1x 5x 3x 3x 3x 3x 2x 5x   1x 1x 1x 1x 1x 9x 9x   1x 1x 1x 1x 1x 2x 2x   1x 1x 1x 1x 1x 5x 5x   1x 1x 1x 1x 1x 6x 6x 1x   1x
const path = require('path');
 
/**
 * AppState - Manages application state
 */
class AppState {
  constructor() {
    this.currentDirectory = null;
    this.currentFiles = [];
    this.currentShow = null;
    this.currentSeasons = [];
    this.currentEpisodes = [];
    this.selectedSeasonEpisodeCount = 0;
    this.isUpdatingEpisodeNumbers = false;
    
    // Navigation stack for folder navigation
    this.navigationStack = [];
    this.currentDepth = 0;
  }
 
  /**
   * Set the current directory
   * @param {string} directory - Directory path
   */
  setCurrentDirectory(directory) {
    this.currentDirectory = directory;
  }
 
  /**
   * Get the current directory
   * @returns {string|null} Current directory path
   */
  getCurrentDirectory() {
    return this.currentDirectory;
  }
 
  /**
   * Set current files
   * @param {Array} files - Array of file objects
   */
  setCurrentFiles(files) {
    this.currentFiles = files;
  }
 
  /**
   * Get current files
   * @returns {Array} Array of file objects
   */
  getCurrentFiles() {
    return this.currentFiles;
  }
 
  /**
   * Set current show
   * @param {Object} show - Show object
   */
  setCurrentShow(show) {
    this.currentShow = show;
  }
 
  /**
   * Get current show
   * @returns {Object|null} Current show object
   */
  getCurrentShow() {
    return this.currentShow;
  }
 
  /**
   * Set current seasons
   * @param {Array} seasons - Array of season objects
   */
  setCurrentSeasons(seasons) {
    this.currentSeasons = seasons;
  }
 
  /**
   * Get current seasons
   * @returns {Array} Array of season objects
   */
  getCurrentSeasons() {
    return this.currentSeasons;
  }
 
  /**
   * Set current episodes
   * @param {Array} episodes - Array of episode objects
   */
  setCurrentEpisodes(episodes) {
    this.currentEpisodes = episodes;
  }
 
  /**
   * Get current episodes
   * @returns {Array} Array of episode objects
   */
  getCurrentEpisodes() {
    return this.currentEpisodes;
  }
 
  /**
   * Set selected season episode count
   * @param {number} count - Episode count
   */
  setSelectedSeasonEpisodeCount(count) {
    this.selectedSeasonEpisodeCount = count;
  }
 
  /**
   * Get selected season episode count
   * @returns {number} Episode count
   */
  getSelectedSeasonEpisodeCount() {
    return this.selectedSeasonEpisodeCount;
  }
 
  /**
   * Check if episode numbers are currently updating
   * @returns {boolean} True if updating
   */
  isUpdatingEpisodeNumbers() {
    return this.isUpdatingEpisodeNumbers;
  }
 
  /**
   * Set episode numbers updating flag
   * @param {boolean} updating - Updating state
   */
  setUpdatingEpisodeNumbers(updating) {
    this.isUpdatingEpisodeNumbers = updating;
  }
 
  /**
   * Reset state to initial values
   */
  reset() {
    this.currentDirectory = null;
    this.currentFiles = [];
    this.currentShow = null;
    this.currentSeasons = [];
    this.currentEpisodes = [];
    this.selectedSeasonEpisodeCount = 0;
    this.isUpdatingEpisodeNumbers = false;
    this.navigationStack = [];
    this.currentDepth = 0;
  }
 
  /**
   * Add directory to navigation stack
   * @param {string} directory - Directory path to add
   */
  addToNavigationStack(directory) {
    // Remove any forward history if navigating from middle of stack
    this.navigationStack = this.navigationStack.slice(0, this.currentDepth + 1);
    this.navigationStack.push(directory);
    this.currentDepth = this.navigationStack.length - 1;
  }
 
  /**
   * Go back to previous directory in navigation stack
   * @returns {string|null} Previous directory path or null if at root
   */
  goBack() {
    if (this.canGoBack()) {
      this.navigationStack.pop();
      this.currentDepth--;
      return this.navigationStack[this.currentDepth];
    }
    return null;
  }
 
  /**
   * Check if can go back in navigation history
   * @returns {boolean} True if can go back
   */
  canGoBack() {
    return this.currentDepth > 0;
  }
 
  /**
   * Get current directory from navigation stack
   * @returns {string|null} Current directory path
   */
  getCurrentDirectoryFromStack() {
    return this.navigationStack[this.currentDepth] || null;
  }
 
  /**
   * Get navigation depth
   * @returns {number} Current navigation depth
   */
  getNavigationDepth() {
    return this.currentDepth;
  }
 
  /**
   * Get navigation stack
   * @returns {Array} Array of visited directories
   */
  getNavigationStack() {
    return this.navigationStack;
  }
}
 
module.exports = AppState;