11import React , { useEffect , useState } from 'react'
2- import axios from 'axios'
3- import { apiURL } from '../config.json'
42import { trackPromise , usePromiseTracker } from 'react-promise-tracker'
53import {
64 FacebookShareButton ,
@@ -25,6 +23,7 @@ import Navigation from '../components/Navigation'
2523import { Link , navigate } from '@reach/router'
2624import Vote from '../components/Vote'
2725import Modal from '../components/Modal'
26+ import userStory from '../services/user_story'
2827
2928const Story = ( props ) => {
3029 const { storyId } = props
@@ -49,46 +48,12 @@ const Story = (props) => {
4948
5049 useEffect ( ( ) => {
5150 const fetchStory = async ( ) => {
52- const response = await axios . post (
53- `${ apiURL } /graphql` ,
54- {
55- query : `query {
56- userStory(id: "${ storyId } ") {
57- id
58- Title
59- Description
60- user_story_status {
61- Status
62- }
63- author {
64- id
65- username
66- }
67- followers {
68- id
69- username
70- }
71- }
72- }`
73- } ,
74- {
75- withCredentials : true
76- }
77- )
51+ const response = await userStory . getStory ( storyId )
7852 setStory ( response . data . data . userStory )
7953 }
8054 trackPromise ( fetchStory ( ) )
8155 const editStory = async ( ) => {
82- const check = await axios . post (
83- `${ apiURL } /checkAuthor` ,
84- {
85- id : userId ,
86- storyId : storyId
87- } ,
88- {
89- withCredentials : true
90- }
91- )
56+ const check = await userStory . checkAuthor ( userId , storyId )
9257 if ( check . data ) {
9358 setEditMode ( true )
9459 }
@@ -105,23 +70,7 @@ const Story = (props) => {
10570 event . preventDefault ( )
10671 const combinedDescription = story . Description + editDescription
10772 const filteredDescription = filterDescriptionText ( combinedDescription )
108- await axios . post (
109- `${ apiURL } /graphql` ,
110- {
111- query : `mutation {
112- updateUserStory(
113- input: { where: { id: "${ storyId } " }, data: { Description: "${ filteredDescription } " } }
114- ) {
115- userStory {
116- updatedAt
117- }
118- }
119- }`
120- } ,
121- {
122- withCredentials : true
123- }
124- )
73+ await userStory . updateUserStoryDescription ( storyId , filteredDescription )
12574 setEditor ( false )
12675 setStory ( {
12776 ...story ,
0 commit comments