-
Notifications
You must be signed in to change notification settings - Fork 0
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
3fbac21
commit 25e000f
Showing
18 changed files
with
254 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NEXT_PUBLIC_URL_PRODUCT_API=ws://messenger-backend.fly.dev |
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,2 @@ | ||
NEXT_PUBLIC_URL_PRODUCT_API=ws://localhost:8000 | ||
# NEXT_PUBLIC_URL_PRODUCT_API=ws://messenger-backend.fly.dev |
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,6 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {} | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
} | ||
|
||
module.exports = nextConfig |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Autobuild | ||
autofetch | ||
GOLUB | ||
tailwindcss | ||
tsbuildinfo | ||
|
Binary file not shown.
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,25 +1,25 @@ | ||
import type { Metadata } from 'next' | ||
'use client' | ||
|
||
import Providers from '@/store/Providers' | ||
import { FC } from 'react' | ||
import { Toaster } from 'react-hot-toast' | ||
|
||
import { text, title } from './fonts' | ||
import './globals.css' | ||
|
||
export const metadata: Metadata = { | ||
description: 'Generated by create next app', | ||
title: 'Create Next App', | ||
interface PageProps { | ||
children: React.ReactNode | ||
} | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
const Layout: FC<PageProps> = ({ children } = { children: [] }) => { | ||
return ( | ||
<html lang="en" suppressHydrationWarning> | ||
<body className={`${title.variable} ${text.variable}`}> | ||
<Providers>{children}</Providers> | ||
<Toaster position="top-right" /> | ||
</body> | ||
</html> | ||
) | ||
} | ||
|
||
export default Layout |
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,29 +1,28 @@ | ||
import IconChange from '@/components/UI/Icons/IconChange' | ||
import Image from 'next/image' | ||
'use client' | ||
|
||
import Button from '@/components/UI/Button' | ||
import { useApi, useApiContext } from '@/utils' | ||
import { notify } from '@/utils/notifications' | ||
|
||
const Home = () => { | ||
const api = useApiContext() | ||
const condition = true | ||
|
||
const { fetch, response: calculated } = useApi( | ||
() => condition && api.example.add({ a: 1, b: 2 }), | ||
{ onSuccess: () => notify('It works') } | ||
) | ||
const { response: data } = useApi(() => condition && api.example.data(), { | ||
autofetch: true, | ||
}) | ||
|
||
export default function Home() { | ||
return ( | ||
<div className="flex items-baseline gap-5"> | ||
<div className="flex flex-col items-center"> | ||
This is Image:{' '} | ||
<Image | ||
alt="change" | ||
className="fill-blue-500" | ||
height={24} | ||
src="/icons/change.svg" | ||
width={24} | ||
/> | ||
</div> | ||
<div className="flex flex-col items-center"> | ||
This is an IconChange component:{' '} | ||
<IconChange | ||
className="text-base-gray-1 hover:text-bright-orange transition-colors" | ||
size="lg" | ||
/> | ||
<p>Hover me!</p> | ||
</div> | ||
<div>GOLUB</div> | ||
<div>🚀</div> | ||
<div className="flex items-center gap-20 text-white"> | ||
<Button onClick={fetch}>Calculate 1 + 2</Button> | ||
{calculated} | ||
<div> {data}</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Home |
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 @@ | ||
export const URL_PRODUCT_API = process.env.NEXT_PUBLIC_URL_PRODUCT_API || '' |
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 @@ | ||
export * from './env' |
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,60 @@ | ||
import { useCallback, useEffect, useRef, useState } from 'react' | ||
|
||
import { notify } from '..' | ||
|
||
export const useApi = <T extends Promise<any>>( | ||
fetcher: () => '' | T | false | null | undefined, | ||
options: { | ||
autofetch?: boolean | ||
onBeforeFetch?: () => Promise<void> | void | ||
onError?: () => void | ||
onResponse?: (res: Awaited<T>) => Promise<void> | void | ||
onSuccess?: () => void | ||
} = {} | ||
) => { | ||
const [isLoading, setLoading] = useState(false) | ||
const [response, setResponse] = useState(null) | ||
|
||
const optionsRef = useRef(options) | ||
optionsRef.current = options | ||
|
||
const fetcherRef = useRef(fetcher) | ||
fetcherRef.current = fetcher | ||
|
||
const refetch = useCallback(async () => { | ||
setLoading(true) | ||
await optionsRef.current.onBeforeFetch?.() | ||
const res = await fetcherRef.current() | ||
if (!res) { | ||
setLoading(false) | ||
return | ||
} | ||
await optionsRef.current.onResponse?.(res) | ||
if (res.error) { | ||
if (optionsRef.current.onError) { | ||
await optionsRef.current.onError?.() | ||
} | ||
} else { | ||
setResponse(res) | ||
try { | ||
await optionsRef.current.onSuccess?.() | ||
} catch (e) { | ||
notify('Network error', { type: 'error' }) | ||
console.error(e) | ||
} | ||
} | ||
setLoading(false) | ||
}, []) | ||
|
||
useEffect(() => { | ||
if (optionsRef.current.autofetch) { | ||
refetch() | ||
} | ||
}, [refetch]) | ||
|
||
return { | ||
fetch: refetch, | ||
isLoading, | ||
response, | ||
} | ||
} |
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,2 @@ | ||
export * from './metacom' | ||
export * from './hooks' |
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,36 @@ | ||
import { URL_PRODUCT_API } from '@/constants' | ||
import { Metacom } from 'metacom' | ||
import { | ||
createContext, | ||
useCallback, | ||
useContext, | ||
useEffect, | ||
useMemo, | ||
useState, | ||
} from 'react' | ||
|
||
const units = ['example'] | ||
const metacom = Metacom.create(URL_PRODUCT_API) | ||
|
||
export const useApiLoader = () => { | ||
const [api, setApi] = useState<any>({}) | ||
const isApiReady = useMemo( | ||
() => Object.keys(api).length === units.length, | ||
[api] | ||
) | ||
const loadApi = useCallback(async () => { | ||
await metacom.load(...units) | ||
setApi(metacom.api) | ||
}, []) | ||
|
||
useEffect(() => { | ||
;(async () => { | ||
if (!isApiReady) loadApi() | ||
})() | ||
}, [isApiReady, loadApi]) | ||
|
||
return { api, isApiReady } | ||
} | ||
|
||
export const ApiContext = createContext<any>(null) | ||
export const useApiContext = () => useContext(ApiContext) |
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,3 @@ | ||
export * from './misc' | ||
export * from './api' | ||
export * from './notifications' |
Oops, something went wrong.