Skip to content

Commit

Permalink
fix fast
Browse files Browse the repository at this point in the history
  • Loading branch information
trant755 committed Oct 17, 2022
1 parent 86d0fd2 commit 79417b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
45 changes: 25 additions & 20 deletions src/js/dark-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,39 @@ const SWITCHER_POSITION = 'switcherPosition';
// initChangeOfThemeOnMain();

export function initChangeOfThemeOnMain() {
refs.switcherMain.addEventListener('click', onSwitcherClick);
getSiteTheme();
if (!localStorage.getItem(THEME_KEY)) return;
refs.switcherMain.addEventListener('click', onSwitcherClick);
getSiteTheme();
}

export function initChangeOfThemeOnLib() {
refs.switcher.addEventListener('click', onSwitcherClick);
getSiteTheme();
if (!localStorage.getItem(THEME_KEY)) return;

refs.switcher.addEventListener('click', onSwitcherClick);
getSiteTheme();
}

function onSwitcherClick() {
// refs.roller.classList.toggle('switcher-roller--light');
refs.roller.classList.toggle('switcher-roller--dark');
// refs.body.classList.toggle('light-theme');
refs.body.classList.toggle('dark-theme');
let currentSiteTheme = refs.body.classList.value;
let currentSwitcherPosition = refs.roller.classList.value;

saveSiteTheme(currentSiteTheme, currentSwitcherPosition);
// refs.roller.classList.toggle('switcher-roller--light');
refs.roller.classList.toggle('switcher-roller--dark');
// refs.body.classList.toggle('light-theme');
refs.body.classList.toggle('dark-theme');
let currentSiteTheme = refs.body.classList.value;
let currentSwitcherPosition = refs.roller.classList.value;

saveSiteTheme(currentSiteTheme, currentSwitcherPosition);
}

function saveSiteTheme(data, position) {
localStorage.setItem(THEME_KEY, JSON.stringify(data));
localStorage.setItem(SWITCHER_POSITION, JSON.stringify(position));
function saveSiteTheme(data, position) {
localStorage.setItem(THEME_KEY, JSON.stringify(data));
localStorage.setItem(SWITCHER_POSITION, JSON.stringify(position));
}

function getSiteTheme() {
newCurrentSiteTheme = JSON.parse(localStorage.getItem(THEME_KEY));
newCurrentSwitcherPosition = JSON.parse(localStorage.getItem(SWITCHER_POSITION));
refs.body.classList.value = newCurrentSiteTheme;
refs.roller.classList.value = newCurrentSwitcherPosition;
}
newCurrentSiteTheme = JSON.parse(localStorage.getItem(THEME_KEY));
newCurrentSwitcherPosition = JSON.parse(
localStorage.getItem(SWITCHER_POSITION)
);
refs.body.classList.value = newCurrentSiteTheme;
refs.roller.classList.value = newCurrentSwitcherPosition;
}
4 changes: 2 additions & 2 deletions src/js/generateTrandingCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import localStorageAPI from './local-storage-api/local-storage-api';
import { onMarkupCards } from './onMarkupCards';
import Pagination from 'tui-pagination';
import { options } from './options-of-pagination';
import {initChangeOfThemeOnMain} from './dark-theme';
import { initChangeOfThemeOnMain } from './dark-theme';
// import openModal from'./modalWindow';

const API = new MovieApiService();
Expand All @@ -18,8 +18,8 @@ const pagination = new Pagination(refs.paginationContainer, options);

refs.loader.classList.remove('is-hidden');

initChangeOfThemeOnMain();
generateHomePage();
initChangeOfThemeOnMain();

function generateHomePage() {
if (!LS_API.getGeneresLS()) {
Expand Down

0 comments on commit 79417b2

Please sign in to comment.