Skip to content

Commit

Permalink
chore: unify common conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayamame-beans committed Jul 17, 2024
1 parent 267aec2 commit 7c304f4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 47 deletions.
46 changes: 24 additions & 22 deletions packages/frontend/src/pages/search.note.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,33 @@ async function search() {
}
}

if (query.startsWith('@') && query.length > 1 && !query.includes(' ')) {
//Enterの入力によって検索が開始された場合、Confirmの方にもEnterが入力されてしまうため、遅延させる
await new Promise(x => setTimeout(x, 2));

const confirm = await os.confirm({
type: 'info',
text: i18n.ts.lookupConfirm,
});
if (!confirm.canceled) {
router.push(`/${query}`);
return;
if (query.length > 1 && !query.includes(' ')) {
if (query.startsWith('@')) {
//Enterの入力によって検索が開始された場合、Confirmの方にもEnterが入力されてしまうため、遅延させる
await new Promise(x => setTimeout(x, 2));

const confirm = await os.confirm({
type: 'info',
text: i18n.ts.lookupConfirm,
});
if (!confirm.canceled) {
router.push(`/${query}`);
return;
}
}
}

if (query.startsWith('#') && query.length > 1 && !query.includes(' ')) {
//Enterの入力によって検索が開始された場合、Confirmの方にもEnterが入力されてしまうため、遅延させる
await new Promise(x => setTimeout(x, 2));
if (query.startsWith('#')) {
//Enterの入力によって検索が開始された場合、Confirmの方にもEnterが入力されてしまうため、遅延させる
await new Promise(x => setTimeout(x, 2));

const confirm = await os.confirm({
type: 'info',
text: i18n.ts.openTagPageConfirm,
});
if (!confirm.canceled) {
router.push(`/tags/${encodeURIComponent(query.substring(1))}`);
return;
const confirm = await os.confirm({
type: 'info',
text: i18n.ts.openTagPageConfirm,
});
if (!confirm.canceled) {
router.push(`/tags/${encodeURIComponent(query.substring(1))}`);
return;
}
}
}

Expand Down
46 changes: 24 additions & 22 deletions packages/frontend/src/pages/search.user.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,33 @@ async function search() {
}
}

if (query.startsWith('@') && query.length > 1 && !query.includes(' ')) {
//Enterの入力によって検索が開始された場合、Confirmの方にもEnterが入力されてしまうため、遅延させる
await new Promise(x => setTimeout(x, 2));

const confirm = await os.confirm({
type: 'info',
text: i18n.ts.lookupConfirm,
});
if (!confirm.canceled) {
router.push(`/${query}`);
return;
if (query.length > 1 && !query.includes(' ')) {
if (query.startsWith('@')) {
//Enterの入力によって検索が開始された場合、Confirmの方にもEnterが入力されてしまうため、遅延させる
await new Promise(x => setTimeout(x, 2));

const confirm = await os.confirm({
type: 'info',
text: i18n.ts.lookupConfirm,
});
if (!confirm.canceled) {
router.push(`/${query}`);
return;
}
}
}

if (query.startsWith('#') && query.length > 1 && !query.includes(' ')) {
//Enterの入力によって検索が開始された場合、Confirmの方にもEnterが入力されてしまうため、遅延させる
await new Promise(x => setTimeout(x, 2));
if (query.startsWith('#')) {
//Enterの入力によって検索が開始された場合、Confirmの方にもEnterが入力されてしまうため、遅延させる
await new Promise(x => setTimeout(x, 2));

const confirm = await os.confirm({
type: 'info',
text: i18n.ts.openTagPageConfirm,
});
if (!confirm.canceled) {
router.push(`/user-tags/${encodeURIComponent(query.substring(1))}`);
return;
const confirm = await os.confirm({
type: 'info',
text: i18n.ts.openTagPageConfirm,
});
if (!confirm.canceled) {
router.push(`/user-tags/${encodeURIComponent(query.substring(1))}`);
return;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/scripts/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export async function lookup(router?: Router) {
title: i18n.ts.lookup,
});
const query = temp ? temp.trim() : '';
if (canceled) return;
if (canceled || query.length <= 1) return;

if (query.startsWith('@') && query.length > 1 && !query.includes(' ')) {
if (query.startsWith('@') && !query.includes(' ')) {
_router.push(`/${query}`);
return;
}

if (query.startsWith('#') && query.length > 1) {
if (query.startsWith('#')) {
_router.push(`/tags/${encodeURIComponent(query.substring(1))}`);
return;
}
Expand Down

0 comments on commit 7c304f4

Please sign in to comment.