Skip to content

Commit

Permalink
fix: #5 修复块类型过滤选项保存问题 | Fix the issue of block type filter option save.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuoqiu-Yingyi committed May 12, 2023
1 parent c87c1c7 commit 0c57e8f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- 桌面端 | Desktop
- 浏览器 | Browser
- 渐进式网络应用 | Progressive Web Application (PWA)
- [#5](https://github.com/Zuoqiu-Yingyi/utools-siyuan/issues/5) 修复块类型过滤选项保存问题 | Fix the issue of block type filter option save.

## v0.1.1/2023-05-07

Expand Down
9 changes: 9 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ if (import.meta.env.PROD) {
configs: copy(entries),
} as IStorage);
});
} else if (import.meta.env.DEV) {
/* 开发环境 */
/* 保存用户配置列表 */
watch(configs_entries, entries => {
console.log({
config: copy(config),
configs: copy(entries),
});
});
}
const status = ref(Status.normal); // 连接状态
Expand Down
40 changes: 22 additions & 18 deletions src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,44 @@ const container_indeterminate = computed(() => containers.value.length > 0 && co

/* 处理叶子块全选 */
function handleLeaf(value: boolean | (string | number | boolean)[]): void {
const values: Leaf[] = [];
if (value) {
leafs.value = [Leaf.h, Leaf.p, Leaf.m, Leaf.t, Leaf.c, Leaf.html, Leaf.query_embed];
} else {
leafs.value = [];
values.push(Leaf.h, Leaf.p, Leaf.m, Leaf.t, Leaf.c, Leaf.html, Leaf.query_embed);
}

leafs.value = values;
handleLeafs(values);
}

/* 处理叶子块选择 */
function handleLeafs(values: (string | number | boolean)[]): void {
config.search.types.heading = Leaf.h in values;
config.search.types.paragraph = Leaf.p in values;
config.search.types.mathBlock = Leaf.m in values;
config.search.types.table = Leaf.t in values;
config.search.types.codeBlock = Leaf.c in values;
config.search.types.htmlBlock = Leaf.html in values;
config.search.types.embedBlock = Leaf.query_embed in values;
config.search.types.heading = values.includes(Leaf.h);
config.search.types.paragraph = values.includes(Leaf.p);
config.search.types.mathBlock = values.includes(Leaf.m);
config.search.types.table = values.includes(Leaf.t);
config.search.types.codeBlock = values.includes(Leaf.c);
config.search.types.htmlBlock = values.includes(Leaf.html);
config.search.types.embedBlock = values.includes(Leaf.query_embed);
}

/* 处理容器块全选 */
function handleContainer(value: boolean | (string | number | boolean)[]): void {
const values: Container[] = [];
if (value) {
containers.value = [Container.d, Container.s, Container.b, Container.l, Container.i];
} else {
containers.value = [];
values.push(Container.d, Container.s, Container.b, Container.l, Container.i);
}

containers.value = values;
handleContainers(values);
}

/* 处理容器块选择 */
function handleContainers(values: (string | number | boolean)[]): void {
config.search.types.document = Container.d in values;
config.search.types.superBlock = Container.s in values;
config.search.types.blockquote = Container.b in values;
config.search.types.list = Container.l in values;
config.search.types.listItem = Container.i in values;
config.search.types.document = values.includes(Container.d);
config.search.types.superBlock = values.includes(Container.s);
config.search.types.blockquote = values.includes(Container.b);
config.search.types.list = values.includes(Container.l);
config.search.types.listItem = values.includes(Container.i);
}
/* 👆 搜索型过滤 👆 */

Expand Down
2 changes: 1 addition & 1 deletion src/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
url: "http://localhost:6806",
},
search: {
groupBy: GroupBy.group,
groupBy: GroupBy.noGroupBy,
method: Method.keyword,
orderBy: OrderBy.sortByRankDesc,
paths: [],
Expand Down
15 changes: 12 additions & 3 deletions src/utils/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function isProxy(obj: Obj): boolean {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isArray(arr: any[]): boolean {
function isArray(arr: Obj): boolean {
return Array.isArray(arr);
}

Expand Down Expand Up @@ -62,6 +62,15 @@ function merge(target: Obj, ...arg: Obj[]): Obj {
}, target);
}

function copy<T extends Obj>(obj: T): T {
return merge({}, toRaw(obj)) as T;
function copy<T extends (Obj | Obj[])>(obj: T): T {
const obj_raw = toRaw(obj);
if (isObject(obj_raw)) {
return merge({}, obj_raw) as T;
}
else if (isArray(obj_raw)) {
return (obj_raw as Obj[]).map(item => copy(item)) as T;
}
else {
return obj_raw;
}
}

0 comments on commit 0c57e8f

Please sign in to comment.