-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acfdf96
commit f80ed92
Showing
10 changed files
with
54 additions
and
212 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 was deleted.
Oops, something went wrong.
109 changes: 0 additions & 109 deletions
109
source/javascripts/components/common/RepoYmlStorageActions.tsx
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
source/javascripts/components/common/notifications/CreatingYmlOnWebsiteProgress.tsx
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
source/javascripts/components/common/notifications/LookingForYmlInRepoProgress.tsx
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
source/javascripts/components/common/notifications/ValidatingYmlInRepoProgress.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,52 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
import { AppConfig } from '@/models/AppConfig'; | ||
import BitriseYmlApi from '@/core/api/BitriseYmlApi'; | ||
import useMonolithApiCallback from '@/hooks/api/useMonolithApiCallback'; | ||
|
||
const identityParser = (result: string): any => result; | ||
|
||
const useFormattedYml = (appConfig: AppConfig): string => { | ||
const [yml, setYml] = useState(typeof appConfig === 'string' ? appConfig : ''); | ||
const formatAppConfigRef = useRef<(options?: RequestInit) => void>(); | ||
const { failed, result, call } = useMonolithApiCallback<string>( | ||
'/api/cli/format', | ||
{ | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/x-yaml, application/json', | ||
}, | ||
}, | ||
identityParser, | ||
); | ||
|
||
// NOTE: call function isn't referentially stable | ||
useEffect(() => { | ||
formatAppConfigRef.current = call; | ||
}); | ||
|
||
// Set the js-yaml value as fallback, kick off format endpoint | ||
useEffect(() => { | ||
const yaml = BitriseYmlApi.toYml(appConfig); | ||
setYml(yaml); | ||
|
||
if (typeof appConfig === 'object') { | ||
formatAppConfigRef.current?.({ | ||
body: JSON.stringify({ | ||
app_config_datastore_yaml: yaml, | ||
}), | ||
}); | ||
} | ||
}, [appConfig]); | ||
|
||
// When result finally comes in override the fallback value | ||
useEffect(() => { | ||
if (result && !failed) { | ||
setYml(result); | ||
} | ||
}, [result, failed]); | ||
|
||
return yml; | ||
}; | ||
|
||
export default useFormattedYml; |
This file was deleted.
Oops, something went wrong.