Skip to content
Snippets Groups Projects
Select Git revision
  • ceda32be23c17c9bc526456fe6ae10ecfc6c867a
  • main default
  • 35-cgu
  • 34-peertube-support
  • 27-add-autoplay-to-iframe
  • 33-bug-on-youtube-embed-urls
  • RC-Rekall-v1.1-fix_lpo
  • tuleap-140-go-back-to-my-capsules-page-when-i-m-on-capsule-preview-page
  • RC-Rekall-v1.2-fix10
  • RC-Rekall-v1.2-fix9
  • RC-Rekall-v1.2-fix8
  • RC-Rekall-v1.2-fix7
  • RC-Rekall-v1.2-fix6
  • RC-Rekall-v1.2-fix5
  • RC-Rekall-v1.2-fix4
  • RC-Rekall-v1.2-fix3
  • RC-Rekall-v1.2-fix2
  • RC-Rekall-v1.2-fix1
  • RC-Rekall-v1.1-fix-3
  • RC-Rekall-v1.1-fix-2
  • RC-Rekall-v1.1-fix-1
  • RC-Rekall-v1.1-delivered
  • preprod20220209-1535
23 results

phpstan.neon

Blame
  • LocalStorageAdapter.js 1.50 KiB
    /** */
    export default class LocalStorageAdapter {
      /** */
      constructor(annotationPageId) {
        this.annotationPageId = annotationPageId;
      }
    
      /** */
      async create(annotation) {
        const emptyAnnoPage = {
          id: this.annotationPageId,
          items: [],
          type: 'AnnotationPage',
        };
        const annotationPage = await this.all() || emptyAnnoPage;
        annotationPage.items.push(annotation);
        localStorage.setItem(this.annotationPageId, JSON.stringify(annotationPage));
        return annotationPage;
      }
    
      /** */
      async update(annotation) {
        const annotationPage = await this.all();
        if (annotationPage) {
          const currentIndex = annotationPage.items.findIndex((item) => item.id === annotation.id);
          annotationPage.items.splice(currentIndex, 1, annotation);
          localStorage.setItem(this.annotationPageId, JSON.stringify(annotationPage));
          return annotationPage;
        }
        return null;
      }
    
      /** */
      async delete(annoId) {
        const annotationPage = await this.all();
        if (annotationPage) {
          annotationPage.items = annotationPage.items.filter((item) => item.id !== annoId);
        }
        localStorage.setItem(this.annotationPageId, JSON.stringify(annotationPage));
        return annotationPage;
      }
    
      /** */
      async get(annoId) {
        const annotationPage = await this.all();
        if (annotationPage) {
          return annotationPage.items.find((item) => item.id === annoId);
        }
        return null;
      }
    
      /** */
      async all() {
        return JSON.parse(localStorage.getItem(this.annotationPageId));
      }
    }