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

Store mode and theme information using Storage #200

@github-actions

Description

@github-actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions