Skip to content

Commit

Permalink
feat(token): Can pre-search icon by issuer and store issuer name.
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Jun 23, 2024
1 parent 0f07608 commit 3a19ce3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/components/account/edit/CreationStep1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const secretInput = ref<typeof IonInput>();
const secret = ref('');
const title = ref('');
const host = ref('');
const issuer = ref('');
onMounted(async () => {
try {
Expand All @@ -34,6 +35,9 @@ onMounted(async () => {
}, 500);
});
// Quick test code
// otpauth://totp/Google:example@gmail.com?secret=JBSWY3DPEHPK3PXP&issuer=Google
async function scanQRCode() {
await stopScan();
Expand Down Expand Up @@ -95,7 +99,7 @@ function decodeTheUri(uri: string) {
const url = new URL(uri);
if (url.protocol !== 'otpauth:') {
simpleAlert('Wrong account URI');
simpleAlert('Wrong URI format');
return;
}
Expand All @@ -105,7 +109,12 @@ function decodeTheUri(uri: string) {
host.value = path[0];
secret.value = url.searchParams.get('secret') || '';
issuer.value = url.searchParams.get('issuer') || '';
title.value = decodeURIComponent(String(path[1])) || '';
if (issuer.value === '') {
issuer.value = String(String(path[1]).split(':').shift());
}
}
const saving = ref(false);
Expand All @@ -125,6 +134,7 @@ async function next() {
secret: secret.value,
title: title.value,
host: host.value,
issuer: issuer.value,
},
);
Expand Down
9 changes: 8 additions & 1 deletion src/components/account/edit/CreationStep2.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const props = defineProps<{
secret: string;
title: string;
host: string;
issuer: string;
}>();
const logo = ref('');
Expand All @@ -31,6 +32,7 @@ async function save() {
secret: props.secret.replace(/\s+/, ''),
url: props.host,
image: logo.value,
issuer: props.issuer,
},
image: '',
created: dayjs().toISOString(),
Expand All @@ -52,13 +54,18 @@ async function save() {
}, 300);
});
}
function simplifyIssuer(issuer: string): string {
return issuer.toLowerCase()
.replace(/\s+/g, '-');
}
</script>

<template>
<ModalLayout title="Select Logo">
<div class="box-center ion-padding" style="height: 100%;">
<div style="width: 85%">
<LogoSelect v-model="logo" />
<LogoSelect v-model="logo" :pre-search="simplifyIssuer(issuer || '')" />

<div style="margin-top: 2rem">
<ion-button expand="block" @click="save"
Expand Down
12 changes: 10 additions & 2 deletions src/components/account/edit/LogoSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,27 @@ enum ImageSource {
DEFAULT,
}
const props = defineProps<{
preSearch?: string;
}>();
const logo = defineModel({ default: '' });
const q = ref('');
const imageSource = ref(ImageSource.DEFAULT);
const { loading, run } = useLoading();
onMounted(async () => {
logo.value = logo.value || await findFontAwesome('key');
if (props.preSearch) {
searchIcon(props.preSearch);
}
});
const emptyImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
async function searchIcon() {
const img = await findFontAwesome(q.value);
async function searchIcon(text?: string) {
const img = await findFontAwesome(text || props.preSearch || '');
if (img) {
logo.value = img;
Expand Down
1 change: 1 addition & 0 deletions src/types/entity/account.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export interface AccountContent {
secret: string;
image: string;
url: string;
issuer?: string;
}

0 comments on commit 3a19ce3

Please sign in to comment.