-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
23 changed files
with
862 additions
and
95 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
Empty file.
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,17 @@ | ||
import { API_SETTINGS } from '@constants'; | ||
import axios from 'axios'; | ||
|
||
const queryData = async (query: string) => { | ||
const response = await axios({ | ||
method: 'POST', | ||
url: API_SETTINGS.API_BASE_URL, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
data: JSON.stringify({ query }), | ||
}); | ||
|
||
return response.data; | ||
}; | ||
|
||
export default queryData; |
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,22 @@ | ||
import { createStyles } from '@mantine/core'; | ||
|
||
const useStyles = createStyles((theme) => ({ | ||
editor: { | ||
height: '100%', | ||
overflowY: 'auto', | ||
|
||
'.cm-editor': { | ||
height: '100%', | ||
}, | ||
|
||
'.cm-scroller': { | ||
backgroundColor: theme.colors.gray[1], | ||
}, | ||
|
||
'.cm-activeLine': { | ||
backgroundColor: 'transparent', | ||
}, | ||
}, | ||
})); | ||
|
||
export default useStyles; |
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,34 @@ | ||
import { javascript } from '@codemirror/lang-javascript'; | ||
import { Box } from '@mantine/core'; | ||
import { githubLight } from '@uiw/codemirror-theme-github'; | ||
import ReactCodeMirror from '@uiw/react-codemirror'; | ||
|
||
import useStyles from './CodeEditor.styles'; | ||
|
||
type CodeEditorType = { | ||
code: string; | ||
isActive: boolean; | ||
onChange?: (code: string) => void; | ||
}; | ||
|
||
const CodeEditor = ({ code, isActive, onChange }: CodeEditorType) => { | ||
const { classes } = useStyles(); | ||
|
||
return ( | ||
<Box | ||
className={classes.editor} | ||
component={ReactCodeMirror} | ||
value={code} | ||
extensions={[javascript()]} | ||
theme={githubLight} | ||
basicSetup={{ | ||
foldGutter: false, | ||
lineNumbers: false, | ||
}} | ||
readOnly={!isActive} | ||
onChange={onChange} | ||
/> | ||
); | ||
}; | ||
|
||
export default CodeEditor; |
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
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 |
---|---|---|
@@ -1,7 +1 @@ | ||
export const API_CREDENTIALS = {}; | ||
|
||
export const API_BASE_URL = 'https://countries.trevorblades.com/graphql'; | ||
|
||
export const API_ENDPOINTS = { | ||
TEMP: '/temp', | ||
}; |
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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
import { notifications } from '@mantine/notifications'; | ||
import { IconX } from '@tabler/icons-react'; | ||
|
||
export const showNotificationsError = (err: unknown) => { | ||
export const showNotificationsError = (errorMessage: unknown) => { | ||
return notifications.show({ | ||
title: 'Error', | ||
message: `${err} 🤥`, | ||
message: `${errorMessage} 🤥`, | ||
autoClose: 3000, | ||
icon: <IconX />, | ||
color: 'red', | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export { default as useAppColorScheme } from './useAppColorScheme'; | ||
export { default as useAppLanguage } from './useAppLanguage'; | ||
export { default as useAppScroll } from './useAppScroll'; | ||
export { default as useGetGraphQL } from './useGetGraphQL'; | ||
export { default as useEditor } from './useEditor'; |
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,30 @@ | ||
import { useEffect, useMemo } from 'react'; | ||
|
||
import queryData from '@api/api'; | ||
import { showNotificationsError } from '@helpers'; | ||
import { useStoreQuery } from '@store'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
const useEditor = () => { | ||
const query = useStoreQuery((state) => state.query); | ||
const setQuery = useStoreQuery((state) => state.setQuery); | ||
const { data, isLoading, isError, mutate } = useMutation({ mutationFn: queryData }); | ||
|
||
const code = useMemo(() => { | ||
if (typeof data === 'string') return data; | ||
if (!data) return ''; | ||
return JSON.stringify(data, null, ' '); | ||
}, [data]); | ||
|
||
useEffect(() => { | ||
if (isError) showNotificationsError('something'); | ||
}, [isError]); | ||
|
||
const onMutate = () => { | ||
mutate(query); | ||
}; | ||
|
||
return { query, setQuery, code, onMutate, isLoading }; | ||
}; | ||
|
||
export default useEditor; |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
export {}; | ||
export { default as useStoreQuery } from './useStoreQuery'; |
Oops, something went wrong.