Skip to content

Commit

Permalink
feat(model): 书签模型优化
Browse files Browse the repository at this point in the history
  • Loading branch information
czfadmin committed May 9, 2024
1 parent fe111c6 commit e12b6d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
21 changes: 7 additions & 14 deletions src/stores/bookmark-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import {BookmarkGroup, IBookmarkGroup} from './bookmark-group';
import {DEFAULT_BOOKMARK_GROUP_ID} from '../constants/bookmark';
import {isProxy} from 'util/types';
import {DEFAULT_BOOKMARK_COLOR} from '../constants';

const BookmarkGroupDataModel = types.model('BookmarkGroupDataModel', {
id: types.string,
Expand Down Expand Up @@ -277,7 +276,6 @@ export const BookmarksStore = types
? bookmark.customColor
: {
name: bookmark.color || 'default',
sortedIndex: -1,
};
const fsPath = workspace.asRelativePath(fileUri.fsPath, false);

Expand All @@ -287,27 +285,25 @@ export const BookmarksStore = types
)?.bookmarks.length || 0;

const idxInFileGroup =
self.bookmarksGroupedByFile.find(it => it.fileId === fsPath)?.bookmarks
.length || 0;
self.bookmarksGroupedByFile.find(it => it.fileUri.fsPath === fsPath)
?.bookmarks.length || 0;

const idxInCustomGroup =
self.bookmarksGroupedByCustom.find(it => it.id === bookmark.groupId)
?.bookmarks.length || 0;

let idxInWorkspaceGroup = 0;
const workspaceGroup = self.bookmarksGroupedByWorkspace.find(it =>
it.files.find(f => f.fileId === fsPath),
it.files.find(f => f.fileUri.fsPath === fsPath),
);
if (!workspaceGroup) {
idxInWorkspaceGroup = 0;
} else {
idxInWorkspaceGroup =
workspaceGroup.files.find(it => it.fileId === fsPath)?.bookmarks
.length || 0;
workspaceGroup.files.find(it => it.fileUri.fsPath === fsPath)
?.bookmarks.length || 0;
}

rangesOrOptions.hoverMessage = createHoverMessage(bookmark, true, true);

_bookmark = BookmarkProcessorModel.create({
id: id || generateUUID(),
label,
Expand Down Expand Up @@ -354,12 +350,9 @@ export const BookmarksStore = types
it => it.name === TreeViewGroupEnum.FILE,
);

if (
!fileGroupInfo ||
!fileGroupInfo.data.find(it => it.id === _bookmark.fileId)
) {
if (!fileGroupInfo || !fileGroupInfo.data.find(it => it.id === fsPath)) {
addFileGroupInfo({
id: _bookmark.fileId,
id: fsPath,
sortedIndex: fileGroupInfo ? fileGroupInfo.data.length : 0,
});
}
Expand Down
20 changes: 9 additions & 11 deletions src/stores/bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,24 @@ export const Bookmark = types
* @param idx
*/
function updateColorSortedIndex(idx: number) {
// self.customColor.sortedIndex = idx;
self.sortedInfo.color = idx;
}

/**
* 书签的按工作区间分组情况下组的排序索引
* @param idx
*/
function updateWorkspaceSortedIndex(idx: number) {
// self.workspaceFolder.sortedIndex = idx;
self.sortedInfo.workspace = idx;
}

/**
* 书签的按文件分组情况下组的排序索引
* @param idx
*/
function updateFileSortedIndex(idx: number) {
// self.fileUri.sortedIndex = idx;
self.sortedInfo.file = idx;
self.sortedInfo.default = idx;
}

/**
Expand All @@ -199,13 +200,7 @@ export const Bookmark = types
}
}

function afterCreate() {
// self.rangesOrOptions.hoverMessage = createHoverMessage(
// self as IBookmark,
// true,
// true,
// );
}
function afterCreate() {}

return {
afterCreate,
Expand Down Expand Up @@ -234,7 +229,7 @@ export const BookmarkProcessorModel: ISnapshotProcessor<
SnapshotIn<typeof Bookmark>,
SnapshotOut<typeof Bookmark>
> = types.snapshotProcessor(Bookmark, {
preProcessor(snapshot: SnapshotIn<typeof Bookmark>) {
preProcessor(snapshot: SnapshotIn<IBookmark>) {
console.log(snapshot);
return {
...snapshot,
Expand All @@ -244,6 +239,9 @@ export const BookmarkProcessorModel: ISnapshotProcessor<
},
} as unknown as SnapshotOut<typeof Bookmark>;
},
postProcessor(snapshot: SnapshotOut<IBookmark>, node) {
return snapshot;
},
});

export type IBookmarkProcessorModel = Instance<typeof BookmarkProcessorModel>;
Expand Down

0 comments on commit e12b6d4

Please sign in to comment.