@@ -4,11 +4,11 @@ import StoreAdapter from './StoreAdapter';
44// StoreAdapter for working with localStorage
55// This is ideal for testing, examples, and prototyping
66export default class LocalStoreAdapter extends StoreAdapter {
7- constructor ( ) {
7+ constructor ( userId = "user" ) {
88 super ( {
99 getAnnotations ( documentId , pageNumber ) {
1010 return new Promise ( ( resolve , reject ) => {
11- let annotations = getAnnotations ( documentId ) . filter ( ( i ) => {
11+ let annotations = getAnnotations ( documentId , userId ) . filter ( ( i ) => {
1212 return i . page === pageNumber && i . class === 'Annotation' ;
1313 } ) ;
1414
@@ -21,7 +21,7 @@ export default class LocalStoreAdapter extends StoreAdapter {
2121 } ,
2222
2323 getAnnotation ( documentId , annotationId ) {
24- return Promise . resolve ( getAnnotations ( documentId ) [ findAnnotation ( documentId , annotationId ) ] ) ;
24+ return Promise . resolve ( getAnnotations ( documentId , userId ) [ findAnnotation ( documentId , annotationId ) ] ) ;
2525 } ,
2626
2727 addAnnotation ( documentId , pageNumber , annotation ) {
@@ -30,19 +30,19 @@ export default class LocalStoreAdapter extends StoreAdapter {
3030 annotation . uuid = uuid ( ) ;
3131 annotation . page = pageNumber ;
3232
33- let annotations = getAnnotations ( documentId ) ;
33+ let annotations = getAnnotations ( documentId , userId ) ;
3434 annotations . push ( annotation ) ;
35- updateAnnotations ( documentId , annotations ) ;
35+ updateAnnotations ( documentId , userId , annotations ) ;
3636
3737 resolve ( annotation ) ;
3838 } ) ;
3939 } ,
4040
4141 editAnnotation ( documentId , annotationId , annotation ) {
4242 return new Promise ( ( resolve , reject ) => {
43- let annotations = getAnnotations ( documentId ) ;
43+ let annotations = getAnnotations ( documentId , userId ) ;
4444 annotations [ findAnnotation ( documentId , annotationId ) ] = annotation ;
45- updateAnnotations ( documentId , annotations ) ;
45+ updateAnnotations ( documentId , userId , annotations ) ;
4646
4747 resolve ( annotation ) ;
4848 } ) ;
@@ -52,9 +52,9 @@ export default class LocalStoreAdapter extends StoreAdapter {
5252 return new Promise ( ( resolve , reject ) => {
5353 let index = findAnnotation ( documentId , annotationId ) ;
5454 if ( index > - 1 ) {
55- let annotations = getAnnotations ( documentId ) ;
55+ let annotations = getAnnotations ( documentId , userId ) ;
5656 annotations . splice ( index , 1 ) ;
57- updateAnnotations ( documentId , annotations ) ;
57+ updateAnnotations ( documentId , userId , annotations ) ;
5858 }
5959
6060 resolve ( true ) ;
@@ -63,7 +63,7 @@ export default class LocalStoreAdapter extends StoreAdapter {
6363
6464 getComments ( documentId , annotationId ) {
6565 return new Promise ( ( resolve , reject ) => {
66- resolve ( getAnnotations ( documentId ) . filter ( ( i ) => {
66+ resolve ( getAnnotations ( documentId , userId ) . filter ( ( i ) => {
6767 return i . class === 'Comment' && i . annotation === annotationId ;
6868 } ) ) ;
6969 } ) ;
@@ -78,19 +78,19 @@ export default class LocalStoreAdapter extends StoreAdapter {
7878 content : content
7979 } ;
8080
81- let annotations = getAnnotations ( documentId ) ;
81+ let annotations = getAnnotations ( documentId , userId ) ;
8282 annotations . push ( comment ) ;
83- updateAnnotations ( documentId , annotations ) ;
83+ updateAnnotations ( documentId , userId , annotations ) ;
8484
8585 resolve ( comment ) ;
8686 } ) ;
8787 } ,
8888
8989 deleteComment ( documentId , commentId ) {
9090 return new Promise ( ( resolve , reject ) => {
91- getAnnotations ( documentId ) ;
91+ getAnnotations ( documentId , userId ) ;
9292 let index = - 1 ;
93- let annotations = getAnnotations ( documentId ) ;
93+ let annotations = getAnnotations ( documentId , userId ) ;
9494 for ( let i = 0 , l = annotations . length ; i < l ; i ++ ) {
9595 if ( annotations [ i ] . uuid === commentId ) {
9696 index = i ;
@@ -100,7 +100,7 @@ export default class LocalStoreAdapter extends StoreAdapter {
100100
101101 if ( index > - 1 ) {
102102 annotations . splice ( index , 1 ) ;
103- updateAnnotations ( documentId , annotations ) ;
103+ updateAnnotations ( documentId , userId , annotations ) ;
104104 }
105105
106106 resolve ( true ) ;
@@ -110,12 +110,12 @@ export default class LocalStoreAdapter extends StoreAdapter {
110110 }
111111}
112112
113- function getAnnotations ( documentId ) {
114- return JSON . parse ( localStorage . getItem ( `${ documentId } /annotations` ) ) || [ ] ;
113+ function getAnnotations ( documentId , userId ) {
114+ return JSON . parse ( localStorage . getItem ( `${ documentId } /${ userId } / annotations` ) ) || [ ] ;
115115}
116116
117- function updateAnnotations ( documentId , annotations ) {
118- localStorage . setItem ( `${ documentId } /annotations` , JSON . stringify ( annotations ) ) ;
117+ function updateAnnotations ( documentId , userId , annotations ) {
118+ localStorage . setItem ( `${ documentId } /${ userId } / annotations` , JSON . stringify ( annotations ) ) ;
119119}
120120
121121function findAnnotation ( documentId , annotationId ) {
0 commit comments