This is a solution to the Shortly URL shortening API Challenge challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
form
is submitted if:input
field is emptyWell, I learn about the Clipboard API. However I didn't know it would make my page crash on Firefox! I deployed it on Vercel and checked it out on Firefox and booom!. This is the fix I came up with. I don't think it is very good, but at least works.
export const copiedLink = writable<string | null>(null, (set) => {
try {
navigator.clipboard.readText().then(set);
} catch (err) {
console.error('Unable to Read Text from the Clipboard');
}
return useListener(document.body, 'copy', () => {
const selection = document.getSelection()?.toString();
if (isString(selection) && !isEmpty(selection)) set(selection);
});
});
function copyShortLink() {
navigator.clipboard.writeText(shortLink);
$copiedLink = shortLink;
}