Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
7768c114
Commit
7768c114
authored
Jan 10, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add wrapping hook
parent
dbcb52f9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
10 deletions
+28
-10
lib.tsx
jest/lib.tsx
+6
-3
useFeatureValue.ts
lib/growthbook/useFeatureValue.ts
+11
-0
_app.tsx
pages/_app.tsx
+2
-1
TestApp.tsx
playwright/TestApp.tsx
+6
-3
Login.tsx
ui/pages/Login.tsx
+3
-3
No files found.
jest/lib.tsx
View file @
7768c114
import
{
ChakraProvider
}
from
'
@chakra-ui/react
'
;
import
{
ChakraProvider
}
from
'
@chakra-ui/react
'
;
import
{
GrowthBookProvider
}
from
'
@growthbook/growthbook-react
'
;
import
{
QueryClient
,
QueryClientProvider
}
from
'
@tanstack/react-query
'
;
import
{
QueryClient
,
QueryClientProvider
}
from
'
@tanstack/react-query
'
;
import
type
{
RenderOptions
}
from
'
@testing-library/react
'
;
import
type
{
RenderOptions
}
from
'
@testing-library/react
'
;
import
{
render
}
from
'
@testing-library/react
'
;
import
{
render
}
from
'
@testing-library/react
'
;
...
@@ -36,9 +37,11 @@ const TestApp = ({ children }: {children: React.ReactNode}) => {
...
@@ -36,9 +37,11 @@ const TestApp = ({ children }: {children: React.ReactNode}) => {
<
QueryClientProvider
client=
{
queryClient
}
>
<
QueryClientProvider
client=
{
queryClient
}
>
<
AppContextProvider
pageProps=
{
PAGE_PROPS
}
>
<
AppContextProvider
pageProps=
{
PAGE_PROPS
}
>
<
ScrollDirectionProvider
>
<
ScrollDirectionProvider
>
<
SocketProvider
>
<
GrowthBookProvider
>
{
children
}
<
SocketProvider
>
</
SocketProvider
>
{
children
}
</
SocketProvider
>
</
GrowthBookProvider
>
</
ScrollDirectionProvider
>
</
ScrollDirectionProvider
>
</
AppContextProvider
>
</
AppContextProvider
>
</
QueryClientProvider
>
</
QueryClientProvider
>
...
...
lib/growthbook/useFeatureValue.ts
0 → 100644
View file @
7768c114
import
{
useFeatureValue
,
useGrowthBook
}
from
'
@growthbook/growthbook-react
'
;
export
default
function
useGbFeatureValue
<
T
extends
Parameters
<
typeof
useFeatureValue
>
[
1
]
>
(
name
:
Parameters
<
typeof
useFeatureValue
>
[
0
],
fallback
:
T
,
):
{
value
:
ReturnType
<
typeof
useFeatureValue
<
T
>>
;
isLoading
:
boolean
}
{
const
value
=
useFeatureValue
(
name
,
fallback
);
const
growthBook
=
useGrowthBook
();
return
{
value
,
isLoading
:
!
(
growthBook
?.
ready
??
true
)
};
}
pages/_app.tsx
View file @
7768c114
...
@@ -10,6 +10,7 @@ import type { NextPageWithLayout } from 'nextjs/types';
...
@@ -10,6 +10,7 @@ import type { NextPageWithLayout } from 'nextjs/types';
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
useQueryClientConfig
from
'
lib/api/useQueryClientConfig
'
;
import
useQueryClientConfig
from
'
lib/api/useQueryClientConfig
'
;
import
{
SECOND
}
from
'
lib/consts
'
;
import
{
AppContextProvider
}
from
'
lib/contexts/app
'
;
import
{
AppContextProvider
}
from
'
lib/contexts/app
'
;
import
{
ChakraProvider
}
from
'
lib/contexts/chakra
'
;
import
{
ChakraProvider
}
from
'
lib/contexts/chakra
'
;
import
{
ScrollDirectionProvider
}
from
'
lib/contexts/scrollDirection
'
;
import
{
ScrollDirectionProvider
}
from
'
lib/contexts/scrollDirection
'
;
...
@@ -42,7 +43,7 @@ const ERROR_SCREEN_STYLES: ChakraProps = {
...
@@ -42,7 +43,7 @@ const ERROR_SCREEN_STYLES: ChakraProps = {
function
MyApp
({
Component
,
pageProps
}:
AppPropsWithLayout
)
{
function
MyApp
({
Component
,
pageProps
}:
AppPropsWithLayout
)
{
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
growthBook
?.
loadFeatures
();
growthBook
?.
loadFeatures
(
{
timeout
:
SECOND
}
);
},
[]);
},
[]);
const
queryClient
=
useQueryClientConfig
();
const
queryClient
=
useQueryClientConfig
();
...
...
playwright/TestApp.tsx
View file @
7768c114
import
{
ChakraProvider
}
from
'
@chakra-ui/react
'
;
import
{
ChakraProvider
}
from
'
@chakra-ui/react
'
;
import
{
GrowthBookProvider
}
from
'
@growthbook/growthbook-react
'
;
import
{
QueryClient
,
QueryClientProvider
}
from
'
@tanstack/react-query
'
;
import
{
QueryClient
,
QueryClientProvider
}
from
'
@tanstack/react-query
'
;
import
{
createWeb3Modal
,
defaultWagmiConfig
}
from
'
@web3modal/wagmi/react
'
;
import
{
createWeb3Modal
,
defaultWagmiConfig
}
from
'
@web3modal/wagmi/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
...
@@ -63,9 +64,11 @@ const TestApp = ({ children, withSocket, appContext = defaultAppContext }: Props
...
@@ -63,9 +64,11 @@ const TestApp = ({ children, withSocket, appContext = defaultAppContext }: Props
<
QueryClientProvider
client=
{
queryClient
}
>
<
QueryClientProvider
client=
{
queryClient
}
>
<
SocketProvider
url=
{
withSocket
?
`ws://${ app.domain }:${ app.socketPort }`
:
undefined
}
>
<
SocketProvider
url=
{
withSocket
?
`ws://${ app.domain }:${ app.socketPort }`
:
undefined
}
>
<
AppContextProvider
{
...
appContext
}
>
<
AppContextProvider
{
...
appContext
}
>
<
WagmiConfig
config=
{
wagmiConfig
}
>
<
GrowthBookProvider
>
{
children
}
<
WagmiConfig
config=
{
wagmiConfig
}
>
</
WagmiConfig
>
{
children
}
</
WagmiConfig
>
</
GrowthBookProvider
>
</
AppContextProvider
>
</
AppContextProvider
>
</
SocketProvider
>
</
SocketProvider
>
</
QueryClientProvider
>
</
QueryClientProvider
>
...
...
ui/pages/Login.tsx
View file @
7768c114
import
{
VStack
,
Textarea
,
Button
,
Alert
,
AlertTitle
,
AlertDescription
,
Code
,
Flex
,
Box
}
from
'
@chakra-ui/react
'
;
import
{
VStack
,
Textarea
,
Button
,
Alert
,
AlertTitle
,
AlertDescription
,
Code
,
Flex
,
Box
}
from
'
@chakra-ui/react
'
;
import
{
useFeatureValue
}
from
'
@growthbook/growthbook-react
'
;
import
*
as
Sentry
from
'
@sentry/react
'
;
import
*
as
Sentry
from
'
@sentry/react
'
;
import
mixpanel
from
'
mixpanel-browser
'
;
import
mixpanel
from
'
mixpanel-browser
'
;
import
type
{
ChangeEvent
}
from
'
react
'
;
import
type
{
ChangeEvent
}
from
'
react
'
;
...
@@ -7,6 +6,7 @@ import React from 'react';
...
@@ -7,6 +6,7 @@ import React from 'react';
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
useFeatureValue
from
'
lib/growthbook/useFeatureValue
'
;
import
useGradualIncrement
from
'
lib/hooks/useGradualIncrement
'
;
import
useGradualIncrement
from
'
lib/hooks/useGradualIncrement
'
;
import
useToast
from
'
lib/hooks/useToast
'
;
import
useToast
from
'
lib/hooks/useToast
'
;
import
PageTitle
from
'
ui/shared/Page/PageTitle
'
;
import
PageTitle
from
'
ui/shared/Page/PageTitle
'
;
...
@@ -16,7 +16,7 @@ const Login = () => {
...
@@ -16,7 +16,7 @@ const Login = () => {
const
toast
=
useToast
();
const
toast
=
useToast
();
const
[
num
,
setNum
]
=
useGradualIncrement
(
0
);
const
[
num
,
setNum
]
=
useGradualIncrement
(
0
);
const
testFeature
Value
=
useFeatureValue
(
'
test_value
'
,
'
fallback
'
);
const
testFeature
=
useFeatureValue
(
'
test_value
'
,
'
fallback
'
);
const
[
isFormVisible
,
setFormVisibility
]
=
React
.
useState
(
false
);
const
[
isFormVisible
,
setFormVisibility
]
=
React
.
useState
(
false
);
const
[
token
,
setToken
]
=
React
.
useState
(
''
);
const
[
token
,
setToken
]
=
React
.
useState
(
''
);
...
@@ -88,7 +88,7 @@ const Login = () => {
...
@@ -88,7 +88,7 @@ const Login = () => {
<
Box
w=
"50px"
textAlign=
"center"
>
{
num
}
</
Box
>
<
Box
w=
"50px"
textAlign=
"center"
>
{
num
}
</
Box
>
<
Button
onClick=
{
handleNumIncrement
}
size=
"sm"
>
add
</
Button
>
<
Button
onClick=
{
handleNumIncrement
}
size=
"sm"
>
add
</
Button
>
</
Flex
>
</
Flex
>
<
Box
>
Test feature value:
<
b
>
{
testFeature
Value
}
</
b
></
Box
>
<
Box
>
Test feature value:
<
b
>
{
testFeature
.
isLoading
?
'
loading...
'
:
JSON
.
stringify
(
testFeature
.
value
)
}
</
b
></
Box
>
</
VStack
>
</
VStack
>
);
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment