-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate tags in admin panel (#405)
* fix(admin): tag styling * feat: integrate tags in admin panel * feat: add tag autocomplete * fix: update tags
- Loading branch information
1 parent
99989c5
commit 5476c71
Showing
11 changed files
with
326 additions
and
93 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
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,24 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
const updateArticleTags = gql` | ||
mutation ($id: ID!, $tag: ID!, $isAdded: Boolean!, $isAdmin: Boolean!) { | ||
updateArticleTags( | ||
id: $id | ||
tag: $tag | ||
isAdded: $isAdded | ||
isAdmin: $isAdmin | ||
) { | ||
tags { | ||
name | ||
reference | ||
isAdmin | ||
} | ||
adminTags { | ||
name | ||
reference | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default updateArticleTags; |
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,13 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
const createTag = gql` | ||
mutation createTag($name: String!, $isAdmin: Boolean, $adminColor: String) { | ||
createTag(name: $name, isAdmin: $isAdmin, adminColor: $adminColor) { | ||
id | ||
name | ||
isAdmin | ||
} | ||
} | ||
`; | ||
|
||
export default createTag; |
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,16 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
const getAutocomplete = gql` | ||
query ($searchTerm: String!, $isAdmin: Boolean!, $limit: Int) { | ||
getTagAutocomplete( | ||
searchTerm: $searchTerm | ||
isAdmin: $isAdmin | ||
limit: $limit | ||
) { | ||
id | ||
name | ||
isAdmin | ||
} | ||
} | ||
`; | ||
export default getAutocomplete; |
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,40 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { GraphClient } from '../config/ApolloClient'; | ||
import getTagAutocomplete from '../graphql/queries/tag/getTagAutocomplete'; | ||
|
||
const useTagAutoComplete = (searchTag, isAdmin, limit) => { | ||
const [searchKeyword, setSearchKeyword] = useState(searchTag); | ||
const [result, setResult] = useState([]); | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
setSearchKeyword(searchTag); | ||
}, 100); | ||
|
||
return () => clearTimeout(timer); | ||
}, [searchTag]); | ||
|
||
useEffect(() => { | ||
if (!searchKeyword) return; | ||
|
||
(async () => { | ||
const { | ||
data: { getTagAutocomplete: autoCompleteResult }, | ||
} = await GraphClient.query({ | ||
query: getTagAutocomplete, | ||
variables: { | ||
searchTerm: searchKeyword, | ||
isAdmin: isAdmin, | ||
limit: limit, | ||
}, | ||
}); | ||
|
||
setResult(autoCompleteResult); | ||
})(); | ||
}, [searchKeyword]); | ||
|
||
return result; | ||
}; | ||
|
||
export default useTagAutoComplete; |
Oops, something went wrong.