Skip to content

Commit

Permalink
complete basic all api
Browse files Browse the repository at this point in the history
  • Loading branch information
ducga1998 committed Nov 18, 2018
1 parent 2105f00 commit d10d83b
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/API/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function checkLoginUser(user: any) {
login
name
avatarLink
articles{
articles {
idArticle
hashTag
category
Expand Down
56 changes: 55 additions & 1 deletion src/API/commentAPI.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@

import gql from "graphql-tag";
import { client } from "./client";
export function getAllInfomationUserFollowYour(idUser: string) {
return new Promise(resolve => {
const data = client.query({
query: gql`
query {
getAllInfomationUserFollowYour( id : "${idUser}"){
idUser
idUserFollow
userComment {
name
avatarLink
}
articleComment {
idUser
createTime
}
}
}
`
})
resolve(data)
})
}
//MUATION
// this is function felp we add comment into a article ,
// input : idArticle and content comment ? . Iam not sure :v
export function addComment(input: { idUser: string, idUserFollow: string }) {
return new Promise(resolve => {
const data = client.mutate({
mutation: gql`
mutation AddCommentIntoArticle($input: CommentInput) {
addCommentIntoArticle(input: $input) {
idUser
idUserFollow
userComment
userComment {
name
avatarLink
}
articleComment {
idUser
createTime
}
}
}
`,
variables: {
input
}
})
resolve(data);
})
}
76 changes: 76 additions & 0 deletions src/API/followAPI.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import gql from "graphql-tag";
import { client } from "./client";
export function getAllInfomationUserFollowYour(idUser) {
return new Promise(resolve => {
const data = client.query({
query: gql`
query {
getAllInfomationUserFollowYour( id : "${idUser}"){
idUser
idUserFollow
userFollow {
name
avatarLink
articles {
idArticle
}
}
}
}
`
})
resolve(data)
})
}
//MUTATION
// define input => idUser and idUserFollow
export function follow(input: any) {
return new Promise(resolve => {
const data = client.mutate({
mutation: gql`
mutation Follow($input: FollowInput) {
follow(input: $input) {
idUser
idUserFollow
userFollow {
name
avatarLink
articles {
idArticle
}
}
}
}
`,
variables: {
input
}
})
resolve(data);
})
}
export function unFollow(input: any) {
return new Promise(resolve => {
const data = client.mutate({
mutation: gql`
mutation UnFollow($input: FollowInput) {
unFollow(input: $input) {
idUser
idUserFollow
userFollow {
name
avatarLink
articles {
idArticle
}
}
}
}
`,
variables: {
input
}
})
resolve(data);
})
}
28 changes: 28 additions & 0 deletions src/API/hashtagAPI.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import gql from "graphql-tag";
import { client } from "./client";
//QUERY
export function getAllInfomationUserFollowYour(idUser) {
return new Promise(resolve => {
const data = client.query({
query: gql`
query {
getAllInfomationUserFollowYour( id : "${idUser}"){
idUser
idUserFollow
userFollow {
name
avatarLink
articles {
idArticle
}
}
}
}
`
})
resolve(data)
})
}
//MUTATION
// hash tag not Mutation

4 changes: 2 additions & 2 deletions src/Component/Navigation/buttonWriteArticle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default function ButtonArticle({ history }: any) {
const [nameHashTag, setNameHashTag] = React.useState('')
const [checkPublicArticle, setCheckPublicArticle] = React.useState(true)
const handleAddHashTag = async () => {
if (arrHashTag.length > 6) {
toast.error('Maximum 6 hash tag!!!!');
if (arrHashTag.length > 6 || arrHashTag < 1) {
toast.error('Maximum 6 hash tag and Min > 0!!!!');
return
}
if (arrHashTag.includes(nameHashTag)) {
Expand Down

0 comments on commit d10d83b

Please sign in to comment.