Skip to content

Commit b8656bd

Browse files
committed
file-tree: incomplete route querying
1 parent 89beddc commit b8656bd

File tree

1 file changed

+44
-21
lines changed

1 file changed

+44
-21
lines changed

os-checks/pages/file-tree.vue

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const selected = reactive<{
7373
checker: null,
7474
kind: null,
7575
});
76-
watch(selected, val => console.log(val));
76+
// watch(selected, val => console.log(val));
7777
7878
const displayFilters = ref(true);
7979
@@ -86,7 +86,7 @@ const user_repo = ref<UserRepo>({});
8686
githubFetch<UserRepo>({ path: "ui/user_repo.json" })
8787
.then(data => user_repo.value = data);
8888
watch(user_repo, val => {
89-
if (!selected.user && !selected.repo) {
89+
if (!selected.user || !selected.repo) {
9090
const user = Object.keys(user_repo.value).sort()[0] ?? "";
9191
selected.user = user;
9292
selected.repo = val[user][0] ?? "";
@@ -154,6 +154,8 @@ function get_ck_kinds(ck: string | null): string[] | null {
154154
}
155155
// switch to another Get
156156
watch(got, g => {
157+
if (lock_filters()) return;
158+
157159
// reset pkg and features since it's less likely to see the same selected pkg in another repo
158160
selected.pkg = null;
159161
selected.features = null;
@@ -175,31 +177,45 @@ watch(got, g => {
175177
if (reset_checker) selected.checker = null;
176178
});
177179
180+
// should be called only once in start-up
181+
function lock_filters(): boolean {
182+
if (query_params.lock === "true") {
183+
lockURL.value = true;
184+
const { user, repo, target, pkg, features, checker, kind } = query_params;
185+
if (user) selected.user = user;
186+
if (repo) selected.repo = repo;
187+
if (target && target !== ALL_TARGETS) selected.target = target;
188+
if (pkg) selected.pkg = pkg;
189+
if (features) selected.features = features;
190+
if (checker) selected.checker = checker;
191+
if (kind) selected.kind = kind;
192+
query_params.lock = undefined;
193+
return true;
194+
} else {
195+
lockURL.value = false;
196+
return false
197+
}
198+
}
199+
178200
// watch selection changes
179201
watch(
180202
() => ({
181203
pkg: selected.pkg, feat: selected.features,
182204
kind: selected.kind, ck: selected.checker, g: got.value
183205
}),
184206
({ pkg, feat, kind, ck, g }) => {
185-
if (query_params.lock === "true") {
186-
if (query_params.pkg) selected.pkg = query_params.pkg;
187-
if (query_params.features) selected.features = query_params.features;
188-
if (query_params.checker) selected.checker = query_params.checker;
189-
if (query_params.kind) selected.kind = query_params.kind;
190-
}
191207
192-
const target = cloneDeep(g);
208+
const val = cloneDeep(g);
193209
194-
Dropdown.update_by_features(feat, target);
195-
Dropdown.update_by_pkg(pkg, target);
210+
Dropdown.update_by_features(feat, val);
211+
Dropdown.update_by_pkg(pkg, val);
196212
197213
const ck_kinds = get_ck_kinds(ck);
198-
if (ck_kinds) Dropdown.update_by_checker(ck_kinds, target);
214+
if (ck_kinds) Dropdown.update_by_checker(ck_kinds, val);
199215
200-
Dropdown.update_by_kind(kind, target);
216+
Dropdown.update_by_kind(kind, val);
201217
202-
got2.value = target;
218+
got2.value = val;
203219
}
204220
);
205221
@@ -271,19 +287,25 @@ function updateFilter(query: Params) {
271287
if (repo) { query_params.repo = decodeURIComponent(repo); }
272288
if (target) { query_params.target = decodeURIComponent(target); }
273289
if (pkg) { query_params.pkg = decodeURIComponent(pkg); }
274-
if (features) { query_params.features = decodeURIComponent(features); }
290+
if (features !== undefined) { query_params.features = decodeURIComponent(features); }
275291
if (checker) { query_params.checker = decodeURIComponent(checker); }
276292
if (kind) { query_params.kind = decodeURIComponent(kind); }
277293
if (lock === "true") {
278294
query_params.lock = decodeURIComponent(lock);
279-
lockURL.value = true;
295+
lockURL.value = false;
280296
}
281297
}
282298
updateFilter(route.query);
283299
284-
285300
const router = useRouter();
286-
watchEffect(() => {
301+
const router_params = ref<Params | null>({});
302+
watch(router_params, query => router.push({ path: route.path, query: query || {} }));
303+
304+
watch(lockURL, lock => {
305+
if (!lock) {
306+
router_params.value = {};
307+
return;
308+
}
287309
const { user, repo, target, pkg, features, checker, kind } = selected;
288310
289311
let query: any = {};
@@ -292,12 +314,13 @@ watchEffect(() => {
292314
if (repo) query.repo = encodeURIComponent(repo);
293315
if (target && target !== ALL_TARGETS) query.target = encodeURIComponent(target);
294316
if (pkg) query.pkg = encodeURIComponent(pkg);
295-
if (features) query.features = encodeURIComponent(features);
317+
if (features !== null) query.features = encodeURIComponent(features);
296318
if (checker) query.checker = encodeURIComponent(checker);
297319
if (kind) query.kind = encodeURIComponent(kind);
298-
if (lockURL.value) query.lock = encodeURIComponent(lockURL.value);
299320
300-
router.push({ path: route.path, query });
321+
query.lock = encodeURIComponent("true");
322+
323+
router_params.value = query;
301324
});
302325
</script>
303326

0 commit comments

Comments
 (0)