Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix isMac #252

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/components/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { afterNavigate, goto } from '$app/navigation';
import { layoutState } from '$lib/layouts/Docs.svelte';
import { isMac } from '$lib/utils/platform';

import { createCombobox, melt } from '@melt-ui/svelte';

import { MeiliSearch, type Hit, type Hits } from 'meilisearch';
Expand Down
5 changes: 2 additions & 3 deletions src/lib/utils/persisted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const localStorageAdapter: Adapter = {
if (typeof window === 'undefined') return undefined;

const value = localStorage.getItem(key);
console.log(key, value);

if (value === null) {
return undefined;
}
Expand All @@ -35,7 +35,7 @@ export const persisted = <Value>(
) => {
const localValue = adapter.get(key);
let initialValue: Value | undefined = defaultValue;
console.log({ localValue, initialValue, validated: validate(localValue) });

if (validate(localValue)) {
initialValue = localValue;
}
Expand All @@ -54,7 +54,6 @@ export const persisted = <Value>(
};

const set: typeof store.set = (v) => {
console.log('set', v);
update(() => v);
};

Expand Down
8 changes: 4 additions & 4 deletions src/lib/utils/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ export const isDom = () => typeof window !== 'undefined';
export function getPlatform() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const agent = (navigator as any).userAgentData;
return agent?.platform ?? navigator.platform;
return (agent?.platform ?? navigator.platform) as string;
}
const pt = (v: RegExp) => isDom() && v.test(getPlatform());
const pt = (v: RegExp) => isDom() && v.test(getPlatform().toLowerCase());
const ua = (v: RegExp) => isDom() && v.test(navigator.userAgent);
const vn = (v: RegExp) => isDom() && v.test(navigator.vendor);
export const isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
export const isMac = () => pt(/^Mac/) && !isTouchDevice();
export const isIPhone = () => pt(/^iPhone/);
export const isMac = () => pt(/^mac/) && !isTouchDevice();
export const isIPhone = () => pt(/^iphone/);
export const isSafari = () => isApple() && vn(/apple/i);
export const isFirefox = () => ua(/firefox\//i);
export const isApple = () => pt(/mac|iphone|ipad|ipod/i);
Expand Down