You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
728 B

  1. import { OptionRepository } from '../../domain/models/option/optionRepository'
  2. import { OptionItem } from '~/domain/models/option/option'
  3. export class LocalStorageOptionRepository implements OptionRepository {
  4. findById(projectId: string): OptionItem {
  5. const checkpoint = this.loadCheckpoint()
  6. return OptionItem.valueOf(checkpoint[projectId] ? checkpoint[projectId] : { page: 1 })
  7. }
  8. save(projectId: string, option: OptionItem): void {
  9. const checkpoint = this.loadCheckpoint()
  10. checkpoint[projectId] = option.toObject()
  11. localStorage.setItem('checkpoint', JSON.stringify(checkpoint))
  12. }
  13. loadCheckpoint() {
  14. const item = localStorage.getItem('checkpoint') || '{}'
  15. return JSON.parse(item)
  16. }
  17. }