store.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { createStore, applyMiddleware, compose } from "redux"
  2. import { persistStore, persistReducer } from 'redux-persist'
  3. import storage from 'redux-persist/lib/storage'
  4. import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2'
  5. import thunk from 'redux-thunk'
  6. import appReducer from './reducers'
  7. import { WELCOME, SONG_LIST } from './constants/views'
  8. import { SONGS } from './constants/sections'
  9. import { RESET_APP } from './actions/types'
  10. const initialState = {
  11. mods: {
  12. mods: [],
  13. modDetails: {},
  14. installedMods: [],
  15. pendingInstall: [],
  16. updates: 0,
  17. scanning: false,
  18. patching: false
  19. },
  20. queue: {
  21. items: []
  22. },
  23. songs: {
  24. songs: [],
  25. downloadingCount: 0,
  26. waitingToDownload: [],
  27. downloadedSongs: []
  28. },
  29. search: {
  30. searchResults: {
  31. beatSaver: [],
  32. library: []
  33. }
  34. },
  35. settings: {
  36. installationDirectory: "Please Choose a Folder...",
  37. installationType: "choose",
  38. gameVersion: "choose",
  39. autoLoadMore: true,
  40. offlineMode: false,
  41. theme: 'light',
  42. themeImagePath: '',
  43. folderStructure: 'keySongNameArtistName',
  44. updateChannel: 'latest',
  45. latestReleaseNotes: '0.0.0'
  46. },
  47. sidebar: {
  48. isOpen: true,
  49. section: SONGS
  50. },
  51. view: {
  52. previousView: SONG_LIST,
  53. view: WELCOME,
  54. subView: 'list'
  55. },
  56. warnings: [],
  57. window: {
  58. isMaximized: false,
  59. isTranslucent: true
  60. }
  61. }
  62. const persistConfig = {
  63. key: 'root',
  64. storage: storage,
  65. stateReconciler: autoMergeLevel2
  66. };
  67. const rootReducer = (state, action) => {
  68. if(action.type === RESET_APP) return initialState
  69. return appReducer(state, action)
  70. }
  71. const pReducer = persistReducer(persistConfig, rootReducer);
  72. const middleware = [thunk]
  73. const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
  74. export const store = createStore(pReducer, initialState, composeEnhancers(applyMiddleware(...middleware)))
  75. export const persistor = persistStore(store)