Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
fix: formater
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Kizuku committed Aug 10, 2024
1 parent 890073d commit a9152d8
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 99 deletions.
78 changes: 39 additions & 39 deletions src/hooks/useOrientation.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import { useEffect, useState, useCallback } from "react";
import { useCallback, useEffect, useState } from "react";

export interface Orientation {
alpha: number;
beta: number;
gamma: number;
alpha: number;
beta: number;
gamma: number;
}

export const useOrientation = () => {
const [initialOrientation, setInitialOrientation] =
useState<Orientation | null>(null);
const [orientationDiff, setOrientationDiff] = useState<Orientation>({
alpha: 0,
beta: 0,
gamma: 0,
});
const [initialOrientation, setInitialOrientation] =
useState<Orientation | null>(null);
const [orientationDiff, setOrientationDiff] = useState<Orientation>({
alpha: 0,
beta: 0,
gamma: 0,
});

const handleOrientation = useCallback(
(event: DeviceOrientationEvent) => {
if (!initialOrientation) {
setInitialOrientation({
alpha: event.alpha || 0,
beta: event.beta || 0,
gamma: event.gamma || 0,
});
} else {
setOrientationDiff({
alpha: (event.alpha || 0) - initialOrientation.alpha,
beta: (event.beta || 0) - initialOrientation.beta,
gamma: (event.gamma || 0) - initialOrientation.gamma,
});
}
},
[initialOrientation]
);
const handleOrientation = useCallback(
(event: DeviceOrientationEvent) => {
if (!initialOrientation) {
setInitialOrientation({
alpha: event.alpha || 0,
beta: event.beta || 0,
gamma: event.gamma || 0,
});
} else {
setOrientationDiff({
alpha: (event.alpha || 0) - initialOrientation.alpha,
beta: (event.beta || 0) - initialOrientation.beta,
gamma: (event.gamma || 0) - initialOrientation.gamma,
});
}
},
[initialOrientation],
);

const reset = useCallback(() => {
setInitialOrientation(null);
}, []);
const reset = useCallback(() => {
setInitialOrientation(null);
}, []);

useEffect(() => {
window.addEventListener("deviceorientation", handleOrientation);
return () => {
window.removeEventListener("deviceorientation", handleOrientation);
};
}, [handleOrientation]);
useEffect(() => {
window.addEventListener("deviceorientation", handleOrientation);
return () => {
window.removeEventListener("deviceorientation", handleOrientation);
};
}, [handleOrientation]);

return { orientationDiff, reset };
return { orientationDiff, reset };
};
10 changes: 5 additions & 5 deletions src/store/useSocketRefStore.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { create } from "zustand";
import type { MutableRefObject } from "react";
import { create } from "zustand";

type State = {
socketRef: MutableRefObject<WebSocket | undefined> | null;
socketRef: MutableRefObject<WebSocket | undefined> | null;
};

type Action = {
setRef: (ref: MutableRefObject<WebSocket | undefined>) => void;
setRef: (ref: MutableRefObject<WebSocket | undefined>) => void;
};

export const useSocketRefStore = create<State & Action>()((set) => ({
socketRef: null,
setRef: (ref) => set(() => ({ socketRef: ref })),
socketRef: null,
setRef: (ref) => set(() => ({ socketRef: ref })),
}));
22 changes: 11 additions & 11 deletions src/store/useUUIDStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { persist } from "zustand/middleware";
import { generateUUID } from "../utils/uuid";

type State = {
uuid: string;
uuid: string;
};

type Action = {
updateUUID: () => void;
updateUUID: () => void;
};

export const useUUIDStore = create<State & Action>()(
persist(
(set) => ({
uuid: generateUUID(),
updateUUID: () => set(() => ({ uuid: generateUUID() })),
}),
{
name: "user-uuid",
}
)
persist(
(set) => ({
uuid: generateUUID(),
updateUUID: () => set(() => ({ uuid: generateUUID() })),
}),
{
name: "user-uuid",
},
),
);
32 changes: 16 additions & 16 deletions src/type/schema.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
export interface Schema {
id: string;
interval: number;
angle: angle;
acceleration: acceleration;
distance: distance;
message_type: message_type;
id: string;
interval: number;
angle: angle;
acceleration: acceleration;
distance: distance;
message_type: message_type;
}

interface angle {
x: number;
y: number;
x: number;
y: number;
}

interface acceleration {
x: number;
y: number;
z: number;
x: number;
y: number;
z: number;
}

interface distance {
x: number;
y: number;
z: number;
x: number;
y: number;
z: number;
}

export enum message_type {
pointer = "pointer",
action = "action",
pointer = "pointer",
action = "action",
}
50 changes: 25 additions & 25 deletions src/utils/parmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
* 角度・加速度センサーのパーミッションをリクエストする関数
*/
export const requestPermission = async () => {
// @ts-expect-error only safari property
if (typeof DeviceMotionEvent.requestPermission === "function") {
try {
// @ts-expect-error only safari property
const permissionState = await DeviceMotionEvent.requestPermission();
if (permissionState !== "granted") {
console.warn("Device Motion permission denied.");
}
} catch (error) {
console.error("Error requesting Device Motion permission:", error);
}
}
// @ts-expect-error only safari property
if (typeof DeviceMotionEvent.requestPermission === "function") {
try {
// @ts-expect-error only safari property
const permissionState = await DeviceMotionEvent.requestPermission();
if (permissionState !== "granted") {
console.warn("Device Motion permission denied.");
}
} catch (error) {
console.error("Error requesting Device Motion permission:", error);
}
}

// @ts-expect-error only safari property
if (typeof DeviceOrientationEvent.requestPermission === "function") {
try {
const permissionState =
// @ts-expect-error only safari property
await DeviceOrientationEvent.requestPermission();
if (permissionState !== "granted") {
console.warn("Device Orientation permission denied.");
}
} catch (error) {
console.error("Error requesting Device Orientation permission:", error);
}
}
// @ts-expect-error only safari property
if (typeof DeviceOrientationEvent.requestPermission === "function") {
try {
const permissionState =
// @ts-expect-error only safari property
await DeviceOrientationEvent.requestPermission();
if (permissionState !== "granted") {
console.warn("Device Orientation permission denied.");
}
} catch (error) {
console.error("Error requesting Device Orientation permission:", error);
}
}
};
6 changes: 3 additions & 3 deletions src/utils/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const generateUUID = (): string => {
const timestamp = Date.now().toString(16);
const randomHex = Math.floor(Math.random() * 0xffffff).toString(16);
return `${timestamp}-${randomHex}`;
const timestamp = Date.now().toString(16);
const randomHex = Math.floor(Math.random() * 0xffffff).toString(16);
return `${timestamp}-${randomHex}`;
};

0 comments on commit a9152d8

Please sign in to comment.