fix(copy): prevent shorthand copy if source is present in useCopy (#559)

* fix(copy): prevent shorthand copy if source is present in useCopy

* refactor(copy): normalized copy usage
This commit is contained in:
Corentin THOMASSET 2023-08-10 00:07:44 +02:00 committed by GitHub
parent 7b6232a151
commit 86e964a274
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 26 additions and 20 deletions

View file

@ -7,7 +7,13 @@ export function useCopy({ source, text = 'Copied to the clipboard' }: { source?:
return {
async copy(content?: string, { notificationMessage }: { notificationMessage?: string } = {}) {
await copy(content);
if (source) {
await copy();
}
else {
await copy(content);
}
message.success(notificationMessage ?? text);
},
};

View file

@ -30,7 +30,7 @@ const { copy } = useCopy({ source: header, text: 'Header copied to the clipboard
</n-statistic>
</c-card>
<div mt-5 flex justify-center>
<c-button @click="copy">
<c-button @click="copy()">
Copy header
</c-button>
</div>

View file

@ -33,7 +33,7 @@ const compareMatch = computed(() => compareSync(compareString.value, compareHash
<c-input-text :value="hashed" readonly text-center />
<div mt-5 flex justify-center>
<c-button @click="copy">
<c-button @click="copy()">
Copy hash
</c-button>
</div>

View file

@ -151,10 +151,10 @@ function copyAsBulletList() {
</tbody>
</n-table>
<div mt-5 flex justify-center gap-3>
<c-button @click="copyAsMarkdown">
<c-button @click="copyAsMarkdown()">
Copy as markdown table
</c-button>
<c-button @click="copyAsBulletList">
<c-button @click="copyAsBulletList()">
Copy as bullet list
</c-button>
</div>

View file

@ -100,12 +100,12 @@ const { copy: copyPassphrase } = useCopy({ source: passphrase, text: 'Passphrase
<n-input-group>
<c-input-text v-model:value="entropy" placeholder="Your string..." />
<c-button @click="refreshEntropy">
<c-button @click="refreshEntropy()">
<n-icon size="22">
<Refresh />
</n-icon>
</c-button>
<c-button @click="copyEntropy">
<c-button @click="copyEntropy()">
<n-icon size="22">
<Copy />
</n-icon>
@ -122,7 +122,7 @@ const { copy: copyPassphrase } = useCopy({ source: passphrase, text: 'Passphrase
<n-input-group>
<c-input-text v-model:value="passphrase" placeholder="Your mnemonic..." raw-text />
<c-button @click="copyPassphrase">
<c-button @click="copyPassphrase()">
<n-icon size="22" :component="Copy" />
</c-button>
</n-input-group>

View file

@ -37,7 +37,7 @@ const { copy: copyUnescaped } = useCopy({ source: unescapeOutput });
</n-form-item>
<div flex justify-center>
<c-button @click="copyEscaped">
<c-button @click="copyEscaped()">
Copy
</c-button>
</div>
@ -66,7 +66,7 @@ const { copy: copyUnescaped } = useCopy({ source: unescapeOutput });
</n-form-item>
<div flex justify-center>
<c-button @click="copyUnescaped">
<c-button @click="copyUnescaped()">
Copy
</c-button>
</div>

View file

@ -42,7 +42,7 @@ const { copy } = useCopy({ source: loremIpsumText, text: 'Lorem ipsum copied to
<c-input-text :value="loremIpsumText" multiline placeholder="Your lorem ipsum..." readonly mt-5 rows="5" />
<div mt-5 flex justify-center>
<c-button autofocus @click="copy">
<c-button autofocus @click="copy()">
Copy
</c-button>
</div>

View file

@ -43,7 +43,7 @@ const { copy } = useCopy({ source: details, text: 'Vendor info copied to the cli
</c-card>
<div flex justify-center>
<c-button :disabled="!details" @click="copy">
<c-button :disabled="!details" @click="copy()">
Copy vendor info
</c-button>
</div>

View file

@ -14,7 +14,7 @@ const { copy } = useCopy({ source: port, text: 'Port copied to the clipboard' })
{{ port }}
</div>
<div flex justify-center gap-3>
<c-button @click="copy">
<c-button @click="copy()">
Copy
</c-button>
<c-button @click="refreshPort">

View file

@ -49,7 +49,7 @@ const { copy: copyArabic } = useCopy({ source: outputNumeral, text: 'Arabic numb
<div class="result">
{{ outputRoman }}
</div>
<c-button autofocus :disabled="validationNumeral.validationStatus === 'error'" @click="copyRoman">
<c-button autofocus :disabled="validationNumeral.validationStatus === 'error'" @click="copyRoman()">
Copy
</c-button>
</div>
@ -61,7 +61,7 @@ const { copy: copyArabic } = useCopy({ source: outputNumeral, text: 'Arabic numb
<div class="result">
{{ outputNumeral }}
</div>
<c-button :disabled="!validationRoman.isValid" @click="copyArabic">
<c-button :disabled="!validationRoman.isValid" @click="copyArabic()">
Copy
</c-button>
</div>

View file

@ -15,7 +15,7 @@ const { copy } = useCopy({ source: slug, text: 'Slug copied to clipboard' });
<c-input-text :value="slug" multiline readonly placeholder="You slug will be generated here (ex: my-file-path)" label="Your slug" mb-5 />
<div flex justify-center>
<c-button :disabled="slug.length === 0" @click="copy">
<c-button :disabled="slug.length === 0" @click="copy()">
Copy slug
</c-button>
</div>

View file

@ -26,7 +26,7 @@ const { copy } = useCopy({ source: natoText, text: 'NATO alphabet string copied.
</c-card>
<div mt-3 flex justify-center>
<c-button autofocus @click="copy">
<c-button autofocus @click="copy()">
Copy NATO string
</c-button>
</div>

View file

@ -66,7 +66,7 @@ const { copy } = useCopy({ source: token, text: 'Token copied to the clipboard'
/>
<div mt-5 flex justify-center gap-3>
<c-button @click="copy">
<c-button @click="copy()">
Copy
</c-button>
<c-button @click="refreshToken">

View file

@ -60,7 +60,7 @@ const { copy: copyDecoded } = useCopy({ source: decodeOutput, text: 'Decoded str
/>
<div flex justify-center>
<c-button @click="copyEncoded">
<c-button @click="copyEncoded()">
Copy
</c-button>
</div>
@ -89,7 +89,7 @@ const { copy: copyDecoded } = useCopy({ source: decodeOutput, text: 'Decoded str
/>
<div flex justify-center>
<c-button @click="copyDecoded">
<c-button @click="copyDecoded()">
Copy
</c-button>
</div>