-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat/#28] 스냅샷 저장 및 조회 기능 추가, 저장된 스냅샷이 있는 경우 해당 스냅샷 사용하도록
- Loading branch information
Showing
9 changed files
with
190 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./auth" | ||
export * from "./snapshot" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import axiosInstance from "./axiosInstance" | ||
|
||
export type position = | ||
| "NOSE" | ||
| "LEFT_EYE" | ||
| "RIGHT_EYE" | ||
| "LEFT_EAR" | ||
| "RIGHT_EAR" | ||
| "LEFT_SHOULDER" | ||
| "RIGHT_SHOULDER" | ||
| "LEFT_ELBOW" | ||
| "RIGHT_ELBOW" | ||
| "LEFT_WRIST" | ||
| "RIGHT_WRIST" | ||
| "LEFT_HIP" | ||
| "RIGHT_HIP" | ||
| "LEFT_KNEE" | ||
| "RIGHT_KNEE" | ||
| "LEFT_ANKLE" | ||
| "RIGHT_ANKLE" | ||
|
||
export interface point { | ||
position: position | ||
x: number | ||
y: number | ||
} | ||
|
||
export interface snapshot { | ||
id?: number | ||
points: point[] | ||
} | ||
|
||
export interface createSnapshotRes { | ||
id: string | ||
} | ||
|
||
export const createSnapshot = async (snapshot: snapshot): Promise<createSnapshotRes> => { | ||
try { | ||
const res = await axiosInstance.post(`/pose-layouts`, { snapshot }) | ||
const { id } = res.data.data | ||
|
||
return { id } | ||
} catch (e) { | ||
throw e | ||
} | ||
} | ||
|
||
export const getSnapshots = async (id: string): Promise<snapshot> => { | ||
try { | ||
const res = await axiosInstance.get(`/pose-layouts/${id}`) | ||
return res.data.data | ||
} catch (e) { | ||
throw e | ||
} | ||
} | ||
|
||
export const getRecentSnapshot = async (): Promise<snapshot> => { | ||
try { | ||
const res = await axiosInstance.get(`/pose-layouts/recent`) | ||
return res.data.data | ||
} catch (e) { | ||
throw e | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { createSnapshot, createSnapshotRes, getRecentSnapshot, getSnapshots, snapshot } from "@/api" | ||
import { useMutation, UseMutationResult } from "@tanstack/react-query" | ||
|
||
export const useCreateSnaphot = (): UseMutationResult<createSnapshotRes, unknown, snapshot, unknown> => { | ||
return useMutation({ | ||
mutationFn: (snapshot: snapshot) => { | ||
return createSnapshot(snapshot) | ||
}, | ||
onSuccess: (data) => { | ||
console.log(data) | ||
}, | ||
}) | ||
} | ||
|
||
export const useGetSnapshot = (): UseMutationResult<snapshot, unknown, string, unknown> => { | ||
return useMutation({ | ||
mutationFn: (id: string) => { | ||
return getSnapshots(id) | ||
}, | ||
onSuccess: (data) => { | ||
console.log(data) | ||
}, | ||
}) | ||
} | ||
|
||
export const useGetRecentSnapshot = (): UseMutationResult<snapshot, unknown, void, unknown> => { | ||
return useMutation({ | ||
mutationFn: () => { | ||
return getRecentSnapshot() | ||
}, | ||
onSuccess: (data) => { | ||
console.log(data) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { keypoint } from "@/utils" | ||
import { create } from "zustand" | ||
|
||
interface SnapshotState { | ||
snapshot: keypoint[] | null | ||
setSnapshot: (snapshot: keypoint[]) => void | ||
} | ||
|
||
export const useSnapshotStore = create<SnapshotState>((set) => ({ | ||
snapshot: null, | ||
setSnapshot: (snapshot: keypoint[]) => set({ snapshot }), | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters