Skip to content

Commit 64b6e5b

Browse files
committed
fix(NativeTree): Set location to Local
see #1749 Signed-off-by: Marcel Klehr <[email protected]>
1 parent 7b64f39 commit 64b6e5b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/lib/adapters/Caching.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ export default class CachingAdapter implements Adapter, BulkImportResource<TItem
1818
protected highestId: number
1919
protected bookmarksCache: Folder<TItemLocation>
2020
protected server: any
21+
protected location: TItemLocation = ItemLocation.SERVER
22+
2123
constructor(server: any) {
2224
this.resetCache()
2325
}
2426

2527
resetCache() {
2628
this.highestId = 0
27-
this.bookmarksCache = new Folder({ id: 0, title: 'root', location: ItemLocation.SERVER })
29+
this.bookmarksCache = new Folder({ id: 0, title: 'root', location: this.location })
2830
}
2931

3032
getLabel():string {
@@ -113,7 +115,7 @@ export default class CachingAdapter implements Adapter, BulkImportResource<TItem
113115

114116
async createFolder(folder:Folder<TItemLocation>): Promise<string|number> {
115117
Logger.log('CREATEFOLDER', { folder })
116-
const newFolder = new Tree.Folder({ id: ++this.highestId, parentId: folder.parentId, title: folder.title, location: ItemLocation.SERVER })
118+
const newFolder = new Tree.Folder({ id: ++this.highestId, parentId: folder.parentId, title: folder.title, location: this.location })
117119
const foundParentFolder = this.bookmarksCache.findFolder(newFolder.parentId)
118120
if (!foundParentFolder) {
119121
throw new UnknownCreateTargetError()

src/lib/native/NativeTree.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Preferences as Storage } from '@capacitor/preferences'
2-
import { Bookmark, Folder, ItemLocation } from '../Tree'
2+
import { Bookmark, Folder, ItemLocation, TItemLocation } from '../Tree'
33
import Ordering from '../interfaces/Ordering'
44
import CachingAdapter from '../adapters/Caching'
55
import IAccountStorage from '../interfaces/AccountStorage'
66
import { BulkImportResource } from '../interfaces/Resource'
77

88
export default class NativeTree extends CachingAdapter implements BulkImportResource<typeof ItemLocation.LOCAL> {
9-
private tree: Folder<typeof ItemLocation.LOCAL>
9+
protected location: TItemLocation = ItemLocation.LOCAL
10+
1011
private storage: IAccountStorage
1112
private readonly accountId: string
1213
private saveTimeout: any
@@ -21,7 +22,7 @@ export default class NativeTree extends CachingAdapter implements BulkImportReso
2122
const {value: tree} = await Storage.get({key: `bookmarks[${this.accountId}].tree`})
2223
const {value: highestId} = await Storage.get({key: `bookmarks[${this.accountId}].highestId`})
2324
if (tree) {
24-
const oldHash = this.bookmarksCache && await this.bookmarksCache.clone(false).hash(true)
25+
const oldHash = this.bookmarksCache && await this.bookmarksCache.cloneWithLocation(false, this.location).hash(true)
2526
this.bookmarksCache = Folder.hydrate(JSON.parse(tree)).clone(false)
2627
const newHash = await this.bookmarksCache.hash(true)
2728
this.highestId = parseInt(highestId)

0 commit comments

Comments
 (0)