Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Store mode and theme information using Storage #200

Open
github-actions bot opened this issue Mar 9, 2021 · 0 comments
Open

Store mode and theme information using Storage #200

github-actions bot opened this issue Mar 9, 2021 · 0 comments
Labels

Comments

@github-actions
Copy link

github-actions bot commented Mar 9, 2021

Store mode and theme information using Storage

// TODO: Store mode and theme information using Storage

import { Mode } from 'src/app/enums/mode.enum';
import { Theme } from 'src/app/enums/theme.enum';

@Injectable({
  providedIn: 'root'
})
export class ThemeService {
  // TODO: Store mode and theme information using Storage

  constructor() {
    this.setMode(this.getMode());
    this.setTheme(this.getTheme());
  }

  // Modes
  public setMode(mode: Mode | string): void {
    document.cookie = `mode=${mode}; path=/`;

    // Remove old modes
    Object.keys(Mode).map(key => document.body.classList.remove(Mode[key]));

    // Add new mode
    document.body.classList.add(mode);
  }
  public getMode(): string {
    const cookie = document.cookie.split(';').map(x => x.split('=')).find(x => x[0].trim() === 'mode');
    return cookie ? cookie[1] : Mode.DEFAULT;
  }

  // Themes
  public setTheme(theme: Theme | string): void {
    document.cookie = `theme=${theme}; path=/`;

    // Remove old themes
    Object.keys(Theme).map(key => document.body.classList.remove(Theme[key]));

    // Add new theme
    document.body.classList.add(theme);
  }
  public getTheme(): string {
    const cookie = document.cookie.split(';').map(x => x.split('=')).find(x => x[0].trim() === 'theme');
    return cookie ? cookie[1] : Theme.DEFAULT;
  }
}
ndex 9e7fd1c3..73c710f8 100644
++ b/src/app/services/user/user.service.spec.ts

1bbb4e14d91b5835130ec6af2370547c1ba33eec

@github-actions github-actions bot added the todo label Mar 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

0 participants