mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-24 18:42:09 +02:00
web: add haptics for all copy actions
& prevent spamming the copy action along with haptic feedback :3 should probably unify all of this cuz this is really messy
This commit is contained in:
parent
fd5f7c36b2
commit
0d3044c5e6
@ -2,6 +2,7 @@
|
|||||||
import { t } from "$lib/i18n/translations";
|
import { t } from "$lib/i18n/translations";
|
||||||
|
|
||||||
import { device } from "$lib/device";
|
import { device } from "$lib/device";
|
||||||
|
import { hapticConfirm } from "$lib/haptics";
|
||||||
import {
|
import {
|
||||||
copyURL,
|
copyURL,
|
||||||
openURL,
|
openURL,
|
||||||
@ -101,8 +102,11 @@
|
|||||||
fill
|
fill
|
||||||
elevated
|
elevated
|
||||||
click={async () => {
|
click={async () => {
|
||||||
copyURL(url);
|
if (!copied) {
|
||||||
copied = true;
|
copyURL(url);
|
||||||
|
hapticConfirm();
|
||||||
|
copied = true;
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
ariaLabel={copied ? $t("button.copied") : ""}
|
ariaLabel={copied ? $t("button.copied") : ""}
|
||||||
>
|
>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { t } from "$lib/i18n/translations";
|
import { t } from "$lib/i18n/translations";
|
||||||
|
import { hapticConfirm } from "$lib/haptics";
|
||||||
import { copyURL, openURL } from "$lib/download";
|
import { copyURL, openURL } from "$lib/download";
|
||||||
|
|
||||||
import CopyIcon from "$components/misc/CopyIcon.svelte";
|
import CopyIcon from "$components/misc/CopyIcon.svelte";
|
||||||
@ -27,8 +28,11 @@
|
|||||||
})}
|
})}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
if (type === "copy") {
|
if (type === "copy") {
|
||||||
copied = true;
|
if (!copied) {
|
||||||
copyURL(address);
|
copyURL(address);
|
||||||
|
hapticConfirm();
|
||||||
|
copied = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
openURL(address);
|
openURL(address);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import { device } from "$lib/device";
|
import { device } from "$lib/device";
|
||||||
import locale from "$lib/i18n/locale";
|
import locale from "$lib/i18n/locale";
|
||||||
import { t } from "$lib/i18n/translations";
|
import { t } from "$lib/i18n/translations";
|
||||||
|
import { hapticConfirm } from "$lib/haptics";
|
||||||
|
|
||||||
import { openURL, copyURL, shareURL } from "$lib/download";
|
import { openURL, copyURL, shareURL } from "$lib/download";
|
||||||
|
|
||||||
@ -51,8 +52,11 @@
|
|||||||
id="action-button-copy"
|
id="action-button-copy"
|
||||||
class="action-button"
|
class="action-button"
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
copyURL(cobaltUrl);
|
if (!copied) {
|
||||||
copied = true;
|
copyURL(cobaltUrl);
|
||||||
|
hapticConfirm();
|
||||||
|
copied = true;
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
aria-label={copied ? $t("button.copied") : ""}
|
aria-label={copied ? $t("button.copied") : ""}
|
||||||
>
|
>
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from "$app/stores";
|
import { page } from "$app/stores";
|
||||||
import { t } from "$lib/i18n/translations";
|
|
||||||
import { copyURL } from "$lib/download";
|
import { copyURL } from "$lib/download";
|
||||||
|
import { t } from "$lib/i18n/translations";
|
||||||
|
import { hapticConfirm } from "$lib/haptics";
|
||||||
|
|
||||||
import CopyIcon from "$components/misc/CopyIcon.svelte";
|
import CopyIcon from "$components/misc/CopyIcon.svelte";
|
||||||
|
|
||||||
@ -40,8 +41,11 @@
|
|||||||
? $t("button.copied")
|
? $t("button.copied")
|
||||||
: $t(`button.copy${copyData ? "" : ".section"}`)}
|
: $t(`button.copy${copyData ? "" : ".section"}`)}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
copied = true;
|
if (!copied) {
|
||||||
copyURL(copyData || sectionURL);
|
copyURL(copyData || sectionURL);
|
||||||
|
hapticConfirm();
|
||||||
|
copied = true;
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CopyIcon check={copied} regularIcon={!!copyData} />
|
<CopyIcon check={copied} regularIcon={!!copyData} />
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from "$app/stores";
|
import { page } from "$app/stores";
|
||||||
import { copyURL as _copyURL } from "$lib/download";
|
|
||||||
|
|
||||||
import SectionHeading from "$components/misc/SectionHeading.svelte";
|
import SectionHeading from "$components/misc/SectionHeading.svelte";
|
||||||
|
|
||||||
export let title: string;
|
export let title: string;
|
||||||
|
@ -2,10 +2,10 @@ import { device } from "$lib/device";
|
|||||||
|
|
||||||
// not sure if vibrations feel the same on android,
|
// not sure if vibrations feel the same on android,
|
||||||
// so they're enabled only on ios 18+ for now
|
// so they're enabled only on ios 18+ for now
|
||||||
const shouldVibrate = device.is.modernIOS;
|
const useHaptics = device.is.modernIOS;
|
||||||
|
|
||||||
export const hapticSwitch = () => {
|
export const hapticSwitch = () => {
|
||||||
if (!shouldVibrate) return;
|
if (!useHaptics) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const label = document.createElement("label");
|
const label = document.createElement("label");
|
||||||
@ -24,3 +24,10 @@ export const hapticSwitch = () => {
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const hapticConfirm = () => {
|
||||||
|
if (!useHaptics) return;
|
||||||
|
|
||||||
|
hapticSwitch();
|
||||||
|
setTimeout(() => hapticSwitch(), 120);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user