Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
viet nguyen committed Jun 21, 2023
1 parent bbe49be commit 122d1d7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@turf/bbox": "^6.5.0",
"@types/underscore": "^1.11.4",
"@types/uuid": "^8.3.4",
"@udecode/zustood": "^0.4.4",
"@udecode/zustood": "^1.1.3",
"auth0": "^2.42.0",
"awesome-debounce-promise": "^2.1.0",
"aws-sdk": "^2.1265.0",
Expand Down Expand Up @@ -142,4 +142,4 @@
"engines": {
"node": "18"
}
}
}
15 changes: 8 additions & 7 deletions src/js/hooks/usePhotoTagCmd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,35 @@ import { toast } from 'react-toastify'
import { graphqlClient } from '../graphql/Client'
import { MUTATION_ADD_ENTITY_TAG, SetTagType } from '../graphql/gql/tags'
import { actions } from '../stores'
import { EntityTag } from '../types'

export interface UsePhotTagReturn {
tagPhotoCmd: (props: SetTagType) => Promise<void>
}

export interface P {
addEntityTag: EntityTag
}
/**
* A React hook for handling photo tagging.
* Todo: Move `useDeleteTagBanckend()` here.
*/
export default function usePhotoTagCmd (): UsePhotTagReturn {
const session = useSession({ required: true })
const addTagToLocalStore = async (data: any): Promise<void> => await actions.media.addTag(data)

// eslint-disable-next-line
const [tagPhoto] = useMutation<any, SetTagType>(
const [addEntityTag] = useMutation<P, SetTagType>(
MUTATION_ADD_ENTITY_TAG, {
client: graphqlClient,
errorPolicy: 'none',
onError: error => toast.error(error.message),
onCompleted: async (data) => {
await addTagToLocalStore(data)
onCompleted: async ({ addEntityTag: newTag }) => {
// await actions.media.addTag(newTag)
toast.success('Tag added.')
}
}
)

const tagPhotoCmd = async (props: SetTagType): Promise<any> => {
await tagPhoto({
await addEntityTag({
variables: props,
context: {
headers: {
Expand Down
9 changes: 4 additions & 5 deletions src/js/stores/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { v5 as uuidv5 } from 'uuid'
import { Dictionary } from 'underscore'
import produce from 'immer'

import type { MediaType, HybridMediaTag, MediaWithTags } from '../../js/types'
import type { MediaType, HybridMediaTag, MediaWithTags, EntityTag } from '../../js/types'
import { DeleteTagResult } from '../hooks/useDeleteTagBackend'

interface UserMediaStateProps {
Expand Down Expand Up @@ -97,10 +97,9 @@ export const userMediaStore = createStore('userMedia')(INITIAL_STATE, STORE_OPTS
/**
* Add a new tag to local store
*/
addTag: async (data: any) => {
const { setTag } = data
if (setTag == null) return
const { mediaUuid } = setTag
addTag: async (tag: EntityTag) => {
if (tag == null) return
const { mediaUuid } = tag

const newState = produce<Dictionary<HybridMediaTag[]>>(get.tagMap(), draft => {
const currentTagList = draft?.[mediaUuid] ?? []
Expand Down
39 changes: 29 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2961,12 +2961,13 @@
"@typescript-eslint/types" "5.42.0"
eslint-visitor-keys "^3.3.0"

"@udecode/zustood@^0.4.4":
version "0.4.4"
resolved "https://registry.yarnpkg.com/@udecode/zustood/-/zustood-0.4.4.tgz#0f3467f1ec3656623c16bb803d64e6dc55ea7b42"
integrity sha512-OtkRGu8TKBkidOOf28TY4tqYJRhMAiVt+BF6lHbF/FnXRmOa8eLal8Q/k9sqQcGzQAHBaZYcx0pR1+wlQzaurg==
"@udecode/zustood@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@udecode/zustood/-/zustood-1.1.3.tgz#0ccff0beeaf7a79510117e8946f589bafdcb8df4"
integrity sha512-f3mxHDaOF+q2XvDh/mMvLhCNs0LfCLhIBl8jGmvZT/i3WWq7YujzGXgnbK8mxIkun9irfe6wlPhg9sTIB9Gnug==
dependencies:
immer "9.0.6"
immer "^9.0.6"
react-tracked "^1.7.9"

"@wry/context@^0.6.0":
version "0.6.1"
Expand Down Expand Up @@ -5201,16 +5202,16 @@ ignore@^5.1.1, ignore@^5.1.8, ignore@^5.2.0:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==

immer@9.0.6:
version "9.0.6"
resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.6.tgz#7a96bf2674d06c8143e327cbf73539388ddf1a73"
integrity sha512-G95ivKpy+EvVAnAab4fVa4YGYn24J1SpEktnJX7JJ45Bd7xqME/SCplFzYFmTbrkwZbQ4xJK1xMTUYBkN6pWsQ==

immer@^9.0.12:
version "9.0.16"
resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.16.tgz#8e7caab80118c2b54b37ad43e05758cdefad0198"
integrity sha512-qenGE7CstVm1NrHQbMh8YaSzTZTFNP3zPqr3YU0S0UY441j4bJTg4A2Hh5KAhwgaiU6ZZ1Ar6y/2f4TblnMReQ==

immer@^9.0.6:
version "9.0.21"
resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.21.tgz#1e025ea31a40f24fb064f1fef23e931496330176"
integrity sha512-bc4NBHqOqSfRW7POMkHd51LvClaeMXpm8dx0e8oE2GORbq5aRK7Bxl4FyzVLdGtLmvLKL7BTDBG5ACQm4HWjTA==

import-fresh@^3.0.0, import-fresh@^3.2.1:
version "3.3.0"
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b"
Expand Down Expand Up @@ -7059,6 +7060,11 @@ protocol-buffers-schema@^3.3.1:
resolved "https://registry.yarnpkg.com/protocol-buffers-schema/-/protocol-buffers-schema-3.6.0.tgz#77bc75a48b2ff142c1ad5b5b90c94cd0fa2efd03"
integrity sha512-TdDRD+/QNdrCGCE7v8340QyuXd4kIWIgapsE2+n/SaGiSSbomYl4TjHlvIoCWRpE7wFt02EpB35VVA2ImcBVqw==

proxy-compare@2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/proxy-compare/-/proxy-compare-2.4.0.tgz#90f6abffe734ef86d8e37428c5026268606a9c1b"
integrity sha512-FD8KmQUQD6Mfpd0hywCOzcon/dbkFP8XBd9F1ycbKtvVsfv6TsFUKJ2eC0Iz2y+KzlkdT1Z8SY6ZSgm07zOyqg==

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
Expand Down Expand Up @@ -7314,6 +7320,14 @@ react-toastify@^9.1.1:
dependencies:
clsx "^1.1.1"

react-tracked@^1.7.9:
version "1.7.11"
resolved "https://registry.yarnpkg.com/react-tracked/-/react-tracked-1.7.11.tgz#b2adccf1d8ee3941e8dc68f754513bdb7b235db4"
integrity sha512-+XXv4dJH7NnLtSD/cPVL9omra4A3KRK91L33owevXZ81r7qF/a9DdCsVZa90jMGht/V1Ym9sasbmidsJykhULQ==
dependencies:
proxy-compare "2.4.0"
use-context-selector "1.4.1"

react-transition-group@2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-2.9.0.tgz#df9cdb025796211151a436c69a8f3b97b5b07c8d"
Expand Down Expand Up @@ -8441,6 +8455,11 @@ use-callback-ref@^1.3.0:
dependencies:
tslib "^2.0.0"

use-context-selector@1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/use-context-selector/-/use-context-selector-1.4.1.tgz#eb96279965846b72915d7f899b8e6ef1d768b0ae"
integrity sha512-Io2ArvcRO+6MWIhkdfMFt+WKQX+Vb++W8DS2l03z/Vw/rz3BclKpM0ynr4LYGyU85Eke+Yx5oIhTY++QR0ZDoA==

use-isomorphic-layout-effect@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/use-isomorphic-layout-effect/-/use-isomorphic-layout-effect-1.1.2.tgz#497cefb13d863d687b08477d9e5a164ad8c1a6fb"
Expand Down

0 comments on commit 122d1d7

Please sign in to comment.