Skip to content

Commit

Permalink
fix(NativeTree): Set location to Local
Browse files Browse the repository at this point in the history
see #1749

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed Nov 17, 2024
1 parent 7b64f39 commit 64b6e5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/lib/adapters/Caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export default class CachingAdapter implements Adapter, BulkImportResource<TItem
protected highestId: number
protected bookmarksCache: Folder<TItemLocation>
protected server: any
protected location: TItemLocation = ItemLocation.SERVER

constructor(server: any) {
this.resetCache()
}

resetCache() {
this.highestId = 0
this.bookmarksCache = new Folder({ id: 0, title: 'root', location: ItemLocation.SERVER })
this.bookmarksCache = new Folder({ id: 0, title: 'root', location: this.location })
}

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

async createFolder(folder:Folder<TItemLocation>): Promise<string|number> {
Logger.log('CREATEFOLDER', { folder })
const newFolder = new Tree.Folder({ id: ++this.highestId, parentId: folder.parentId, title: folder.title, location: ItemLocation.SERVER })
const newFolder = new Tree.Folder({ id: ++this.highestId, parentId: folder.parentId, title: folder.title, location: this.location })
const foundParentFolder = this.bookmarksCache.findFolder(newFolder.parentId)
if (!foundParentFolder) {
throw new UnknownCreateTargetError()
Expand Down
7 changes: 4 additions & 3 deletions src/lib/native/NativeTree.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Preferences as Storage } from '@capacitor/preferences'
import { Bookmark, Folder, ItemLocation } from '../Tree'
import { Bookmark, Folder, ItemLocation, TItemLocation } from '../Tree'
import Ordering from '../interfaces/Ordering'
import CachingAdapter from '../adapters/Caching'
import IAccountStorage from '../interfaces/AccountStorage'
import { BulkImportResource } from '../interfaces/Resource'

export default class NativeTree extends CachingAdapter implements BulkImportResource<typeof ItemLocation.LOCAL> {
private tree: Folder<typeof ItemLocation.LOCAL>
protected location: TItemLocation = ItemLocation.LOCAL

private storage: IAccountStorage
private readonly accountId: string
private saveTimeout: any
Expand All @@ -21,7 +22,7 @@ export default class NativeTree extends CachingAdapter implements BulkImportReso
const {value: tree} = await Storage.get({key: `bookmarks[${this.accountId}].tree`})
const {value: highestId} = await Storage.get({key: `bookmarks[${this.accountId}].highestId`})
if (tree) {
const oldHash = this.bookmarksCache && await this.bookmarksCache.clone(false).hash(true)
const oldHash = this.bookmarksCache && await this.bookmarksCache.cloneWithLocation(false, this.location).hash(true)
this.bookmarksCache = Folder.hydrate(JSON.parse(tree)).clone(false)
const newHash = await this.bookmarksCache.hash(true)
this.highestId = parseInt(highestId)
Expand Down

0 comments on commit 64b6e5b

Please # to comment.