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
4d8d344d
Unverified
Commit
4d8d344d
authored
Nov 03, 2022
by
Igor Stuev
Committed by
GitHub
Nov 03, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #297 from blockscout/ssr
ssr
parents
d1663540
58e24bb8
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
133 additions
and
76 deletions
+133
-76
Chakra.tsx
lib/Chakra.tsx
+24
-0
appContext.tsx
lib/appContext.tsx
+24
-0
cookies.ts
lib/cookies.ts
+6
-2
getServerSideProps.ts
lib/next/getServerSideProps.ts
+13
-0
getServerSidePropsDummy.ts
lib/next/getServerSidePropsDummy.ts
+0
-10
getStaticPaths.ts
lib/next/getStaticPaths.ts
+0
-5
getStaticProps.ts
lib/next/getStaticProps.ts
+0
-7
_app.tsx
pages/_app.tsx
+10
-7
api_key.tsx
pages/account/api_key.tsx
+1
-1
custom_abi.tsx
pages/account/custom_abi.tsx
+1
-1
public_tags_request.tsx
pages/account/public_tags_request.tsx
+1
-1
tag_address.tsx
pages/account/tag_address.tsx
+1
-1
watchlist.tsx
pages/account/watchlist.tsx
+1
-1
apps.tsx
pages/apps.tsx
+1
-1
[id].tsx
pages/apps/[id].tsx
+1
-2
profile.tsx
pages/auth/profile.tsx
+1
-1
[id].tsx
pages/block/[id].tsx
+1
-2
blocks.tsx
pages/blocks.tsx
+1
-1
index.tsx
pages/index.tsx
+1
-1
[id].tsx
pages/tx/[id].tsx
+1
-2
txs.tsx
pages/txs.tsx
+1
-1
MyProfile.tsx
ui/pages/MyProfile.tsx
+2
-2
Page.tsx
ui/shared/Page/Page.tsx
+5
-1
UserAvatar.tsx
ui/shared/UserAvatar.tsx
+14
-3
NavigationDesktop.tsx
ui/snippets/navigation/NavigationDesktop.tsx
+17
-18
ProfileMenuDesktop.tsx
ui/snippets/profileMenu/ProfileMenuDesktop.tsx
+2
-2
ProfileMenuMobile.tsx
ui/snippets/profileMenu/ProfileMenuMobile.tsx
+3
-3
No files found.
lib/Chakra.tsx
0 → 100644
View file @
4d8d344d
import
{
ChakraProvider
,
cookieStorageManagerSSR
,
localStorageManager
,
}
from
'
@chakra-ui/react
'
;
import
type
{
ChakraProviderProps
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
interface
Props
extends
ChakraProviderProps
{
cookies
?:
string
;
}
export
function
Chakra
({
cookies
,
theme
,
children
}:
Props
)
{
const
colorModeManager
=
typeof
cookies
===
'
string
'
?
cookieStorageManagerSSR
(
cookies
)
:
localStorageManager
;
return
(
<
ChakraProvider
colorModeManager=
{
colorModeManager
}
theme=
{
theme
}
>
{
children
}
</
ChakraProvider
>
);
}
lib/appContext.tsx
0 → 100644
View file @
4d8d344d
import
React
,
{
createContext
,
useContext
}
from
'
react
'
;
import
type
{
Props
as
PageProps
}
from
'
lib/next/getServerSideProps
'
;
type
Props
=
{
children
:
React
.
ReactNode
;
pageProps
:
PageProps
;
}
const
AppContext
=
createContext
<
PageProps
>
({
cookies
:
''
});
export
function
AppWrapper
({
children
,
pageProps
}:
Props
)
{
const
appProps
=
{
cookies
:
pageProps
.
cookies
};
return
(
<
AppContext
.
Provider
value=
{
appProps
}
>
{
children
}
</
AppContext
.
Provider
>
);
}
export
function
useAppContext
()
{
return
useContext
(
AppContext
);
}
lib/cookies.ts
View file @
4d8d344d
...
...
@@ -9,9 +9,9 @@ export enum NAMES {
TXS_SORT
=
'
txs_sort
'
,
}
export
function
get
(
name
?:
string
|
undefined
|
null
)
{
export
function
get
(
name
?:
NAMES
|
undefined
|
null
,
serverCookie
?:
string
)
{
if
(
!
isBrowser
())
{
return
undefined
;
return
serverCookie
?
getFromCookieString
(
serverCookie
,
name
)
:
undefined
;
}
return
Cookies
.
get
(
name
);
}
...
...
@@ -21,3 +21,7 @@ export function set(name: string, value: string, attributes: Types.CookieAttribu
return
Cookies
.
set
(
name
,
value
,
attributes
);
}
export
function
getFromCookieString
(
cookieString
:
string
,
name
?:
NAMES
|
undefined
|
null
)
{
return
cookieString
.
split
(
`
${
name
}
=`
)[
1
]?.
split
(
'
;
'
)[
0
];
}
lib/next/getServerSideProps.ts
0 → 100644
View file @
4d8d344d
import
type
{
GetServerSideProps
,
GetServerSidePropsResult
}
from
'
next
'
;
export
type
Props
=
{
cookies
:
string
;
}
export
const
getServerSideProps
:
GetServerSideProps
=
async
({
req
}):
Promise
<
GetServerSidePropsResult
<
Props
>>
=>
{
return
{
props
:
{
cookies
:
req
.
headers
.
cookie
||
''
,
},
};
};
lib/next/getServerSidePropsDummy.ts
deleted
100644 → 0
View file @
d1663540
import
type
{
GetServerSideProps
}
from
'
next
'
;
export
const
getServerSideProps
:
GetServerSideProps
=
async
({
res
})
=>
{
res
.
setHeader
(
'
Cache-Control
'
,
`public, s-maxage=
${
60
*
60
}
, stale-while-revalidate=
${
2
*
60
*
60
}
`
,
);
return
{
props
:
{}
};
};
lib/next/getStaticPaths.ts
deleted
100644 → 0
View file @
d1663540
import
type
{
GetStaticPaths
}
from
'
next
'
;
export
const
getStaticPaths
:
GetStaticPaths
=
async
()
=>
{
return
{
paths
:
[],
fallback
:
'
blocking
'
};
};
lib/next/getStaticProps.ts
deleted
100644 → 0
View file @
d1663540
import
type
{
GetStaticProps
,
GetStaticPropsResult
}
from
'
next
'
;
export
const
getStaticProps
:
GetStaticProps
=
async
():
Promise
<
GetStaticPropsResult
<
{
[
key
:
string
]:
unknown
}
>>
=>
{
return
{
props
:
{},
};
};
pages/_app.tsx
View file @
4d8d344d
import
{
ChakraProvider
}
from
'
@chakra-ui/react
'
;
import
{
QueryClient
,
QueryClientProvider
}
from
'
@tanstack/react-query
'
;
import
{
ReactQueryDevtools
}
from
'
@tanstack/react-query-devtools
'
;
import
type
{
AppProps
}
from
'
next/app
'
;
import
React
,
{
useState
}
from
'
react
'
;
import
{
AppWrapper
}
from
'
lib/appContext
'
;
import
{
Chakra
}
from
'
lib/Chakra
'
;
import
useConfigSentry
from
'
lib/hooks/useConfigSentry
'
;
import
type
{
ErrorType
}
from
'
lib/hooks/useFetch
'
;
import
theme
from
'
theme
'
;
...
...
@@ -30,12 +31,14 @@ function MyApp({ Component, pageProps }: AppProps) {
}));
return
(
<
QueryClientProvider
client=
{
queryClient
}
>
<
ChakraProvider
theme=
{
theme
}
>
<
Component
{
...
pageProps
}
/>
</
ChakraProvider
>
<
ReactQueryDevtools
/>
</
QueryClientProvider
>
<
AppWrapper
pageProps=
{
pageProps
}
>
<
QueryClientProvider
client=
{
queryClient
}
>
<
Chakra
theme=
{
theme
}
cookies=
{
pageProps
.
cookies
}
>
<
Component
{
...
pageProps
}
/>
</
Chakra
>
<
ReactQueryDevtools
/>
</
QueryClientProvider
>
</
AppWrapper
>
);
}
...
...
pages/account/api_key.tsx
View file @
4d8d344d
...
...
@@ -17,4 +17,4 @@ const ApiKeysPage: NextPage = () => {
export
default
ApiKeysPage
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
Dummy
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/account/custom_abi.tsx
View file @
4d8d344d
...
...
@@ -17,4 +17,4 @@ const CustomAbiPage: NextPage = () => {
export
default
CustomAbiPage
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
Dummy
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/account/public_tags_request.tsx
View file @
4d8d344d
...
...
@@ -17,4 +17,4 @@ const PublicTagsPage: NextPage = () => {
export
default
PublicTagsPage
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
Dummy
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/account/tag_address.tsx
View file @
4d8d344d
...
...
@@ -17,4 +17,4 @@ const AddressTagsPage: NextPage = () => {
export
default
AddressTagsPage
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
Dummy
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/account/watchlist.tsx
View file @
4d8d344d
...
...
@@ -19,4 +19,4 @@ const WatchListPage: NextPage = () => {
export
default
WatchListPage
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
Dummy
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/apps.tsx
View file @
4d8d344d
...
...
@@ -19,4 +19,4 @@ const AppsPage: NextPage = () => {
export
default
AppsPage
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
Dummy
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/apps/[id].tsx
View file @
4d8d344d
...
...
@@ -47,5 +47,4 @@ const AppPage: NextPage = () => {
export
default
AppPage
;
export
{
getStaticPaths
}
from
'
lib/next/getStaticPaths
'
;
export
{
getStaticProps
}
from
'
lib/next/getStaticProps
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/auth/profile.tsx
View file @
4d8d344d
...
...
@@ -15,4 +15,4 @@ const MyProfilePage: NextPage = () => {
export
default
MyProfilePage
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
Dummy
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/block/[id].tsx
View file @
4d8d344d
...
...
@@ -17,5 +17,4 @@ const BlockPage: NextPage<Props> = ({ pageParams }: Props) => {
export
default
BlockPage
;
export
{
getStaticPaths
}
from
'
lib/next/getStaticPaths
'
;
export
{
getStaticProps
}
from
'
lib/next/getStaticProps
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/blocks.tsx
View file @
4d8d344d
...
...
@@ -11,4 +11,4 @@ const BlockPage: NextPage = () => {
export
default
BlockPage
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
Dummy
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/index.tsx
View file @
4d8d344d
...
...
@@ -15,4 +15,4 @@ const HomePage: NextPage = () => {
export
default
HomePage
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
Dummy
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/tx/[id].tsx
View file @
4d8d344d
...
...
@@ -17,5 +17,4 @@ const TransactionPage: NextPage<Props> = ({ pageParams }: Props) => {
export
default
TransactionPage
;
export
{
getStaticPaths
}
from
'
lib/next/getStaticPaths
'
;
export
{
getStaticProps
}
from
'
lib/next/getStaticProps
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
pages/txs.tsx
View file @
4d8d344d
...
...
@@ -17,4 +17,4 @@ const TxsPage: NextPage = () => {
export
default
TxsPage
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
Dummy
'
;
export
{
getServerSideProps
}
from
'
lib/next/getServerSideProps
'
;
ui/pages/MyProfile.tsx
View file @
4d8d344d
...
...
@@ -9,7 +9,7 @@ import PageTitle from 'ui/shared/Page/PageTitle';
import
UserAvatar
from
'
ui/shared/UserAvatar
'
;
const
MyProfile
=
()
=>
{
const
{
data
,
isLoading
,
isError
}
=
useFetchProfileInfo
();
const
{
data
,
isLoading
,
isError
,
isFetched
}
=
useFetchProfileInfo
();
const
content
=
(()
=>
{
if
(
isLoading
)
{
...
...
@@ -22,7 +22,7 @@ const MyProfile = () => {
return
(
<
VStack
maxW=
"412px"
mt=
{
12
}
gap=
{
5
}
alignItems=
"stretch"
>
<
UserAvatar
size=
{
64
}
data=
{
data
}
/>
<
UserAvatar
size=
{
64
}
data=
{
data
}
isFetched=
{
isFetched
}
/>
<
FormControl
variant=
"floating"
id=
"name"
isRequired
size=
"lg"
>
<
Input
required
...
...
ui/shared/Page/Page.tsx
View file @
4d8d344d
...
...
@@ -18,7 +18,11 @@ interface Props {
hideMobileHeaderOnScrollDown
?:
boolean
;
}
const
Page
=
({
children
,
wrapChildren
=
true
,
hideMobileHeaderOnScrollDown
}:
Props
)
=>
{
const
Page
=
({
children
,
wrapChildren
=
true
,
hideMobileHeaderOnScrollDown
,
}:
Props
)
=>
{
const
fetch
=
useFetch
();
useQuery
<
unknown
,
unknown
,
unknown
>
([
QueryKeys
.
csrf
],
async
()
=>
await
fetch
(
'
/node-api/account/csrf
'
),
{
...
...
ui/shared/UserAvatar.tsx
View file @
4d8d344d
import
{
useColorModeValue
,
chakra
,
Image
}
from
'
@chakra-ui/react
'
;
import
{
useColorModeValue
,
chakra
,
SkeletonCircle
,
Image
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
Identicon
from
'
react-identicons
'
;
import
type
{
UserInfo
}
from
'
types/api/account
'
;
import
{
useAppContext
}
from
'
lib/appContext
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
const
ProfileIcon
=
chakra
(
Identicon
);
interface
Props
{
size
:
number
;
data
?:
UserInfo
;
isFetched
:
boolean
;
}
const
UserAvatar
=
({
size
,
data
}:
Props
)
=>
{
const
UserAvatar
=
({
size
,
data
,
isFetched
}:
Props
)
=>
{
const
appProps
=
useAppContext
();
const
hasAuth
=
Boolean
(
cookies
.
get
(
cookies
.
NAMES
.
API_TOKEN
,
appProps
.
cookies
));
const
sizeString
=
`
${
size
}
px`
;
const
bgColor
=
useColorModeValue
(
'
blackAlpha.100
'
,
'
white
'
);
if
(
hasAuth
&&
!
isFetched
)
{
return
<
SkeletonCircle
h=
{
sizeString
}
w=
{
sizeString
}
/>;
}
if
(
data
?.
avatar
)
{
return
(
<
Image
flexShrink=
{
0
}
src=
{
data
.
avatar
}
alt=
{
`Profile picture of ${ data
.name || data
.nickname || '' }`
}
alt=
{
`Profile picture of ${ data
?.name || data?
.nickname || '' }`
}
w=
{
sizeString
}
minW=
{
sizeString
}
h=
{
sizeString
}
...
...
ui/snippets/navigation/NavigationDesktop.tsx
View file @
4d8d344d
...
...
@@ -3,9 +3,9 @@ import React from 'react';
import
appConfig
from
'
configs/app/config
'
;
import
chevronIcon
from
'
icons/arrows/east-mini.svg
'
;
import
{
useAppContext
}
from
'
lib/appContext
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
useNavItems
from
'
lib/hooks/useNavItems
'
;
import
isBrowser
from
'
lib/isBrowser
'
;
import
getDefaultTransitionProps
from
'
theme/utils/getDefaultTransitionProps
'
;
import
NetworkLogo
from
'
ui/snippets/networkMenu/NetworkLogo
'
;
import
NetworkMenu
from
'
ui/snippets/networkMenu/NetworkMenu
'
;
...
...
@@ -14,25 +14,24 @@ import NavFooter from './NavFooter';
import
NavLink
from
'
./NavLink
'
;
const
NavigationDesktop
=
()
=>
{
const
{
mainNavItems
,
accountNavItems
}
=
useNavItems
();
const
appProps
=
useAppContext
();
const
cookiesString
=
appProps
.
cookies
;
const
isNavBarCollapsedCookie
=
cookies
.
get
(
cookies
.
NAMES
.
NAV_BAR_COLLAPSED
,
cookiesString
);
let
isNavBarCollapsed
;
if
(
isNavBarCollapsedCookie
===
'
true
'
)
{
isNavBarCollapsed
=
true
;
}
if
(
isNavBarCollapsedCookie
===
'
false
'
)
{
isNavBarCollapsed
=
false
;
}
const
isInBrowser
=
isBrowser
(
);
const
[
hasAccount
,
setHasAccount
]
=
React
.
useState
(
false
);
const
[
isCollapsed
,
setCollapsedState
]
=
React
.
useState
<
boolean
|
undefined
>
();
const
hasAuth
=
Boolean
(
cookies
.
get
(
cookies
.
NAMES
.
API_TOKEN
,
cookiesString
)
);
const
{
mainNavItems
,
accountNavItems
}
=
useNavItems
();
React
.
useEffect
(()
=>
{
const
navBarCollapsedCookie
=
cookies
.
get
(
cookies
.
NAMES
.
NAV_BAR_COLLAPSED
);
const
isAuth
=
Boolean
(
cookies
.
get
(
cookies
.
NAMES
.
API_TOKEN
));
if
(
isInBrowser
)
{
if
(
navBarCollapsedCookie
===
'
true
'
)
{
setCollapsedState
(
true
);
}
if
(
navBarCollapsedCookie
===
'
false
'
)
{
setCollapsedState
(
false
);
}
setHasAccount
(
Boolean
(
appConfig
.
isAccountSupported
&&
isAuth
&&
isInBrowser
));
}
},
[
isInBrowser
]);
const
hasAccount
=
hasAuth
&&
appConfig
.
isAccountSupported
;
const
[
isCollapsed
,
setCollapsedState
]
=
React
.
useState
<
boolean
|
undefined
>
(
isNavBarCollapsed
);
const
handleTogglerClick
=
React
.
useCallback
(()
=>
{
setCollapsedState
((
flag
)
=>
!
flag
);
...
...
ui/snippets/profileMenu/ProfileMenuDesktop.tsx
View file @
4d8d344d
...
...
@@ -7,7 +7,7 @@ import UserAvatar from 'ui/shared/UserAvatar';
import
ProfileMenuContent
from
'
ui/snippets/profileMenu/ProfileMenuContent
'
;
const
ProfileMenuDesktop
=
()
=>
{
const
{
data
}
=
useFetchProfileInfo
();
const
{
data
,
isFetched
}
=
useFetchProfileInfo
();
const
loginUrl
=
link
(
'
auth
'
);
return
(
...
...
@@ -21,7 +21,7 @@ const ProfileMenuDesktop = () => {
as=
{
data
?
undefined
:
'
a
'
}
href=
{
data
?
undefined
:
loginUrl
}
>
<
UserAvatar
size=
{
50
}
data=
{
data
}
/>
<
UserAvatar
size=
{
50
}
data=
{
data
}
isFetched=
{
isFetched
}
/>
</
Button
>
</
PopoverTrigger
>
{
data
&&
(
...
...
ui/snippets/profileMenu/ProfileMenuMobile.tsx
View file @
4d8d344d
...
...
@@ -10,13 +10,13 @@ import ProfileMenuContent from 'ui/snippets/profileMenu/ProfileMenuContent';
const
ProfileMenuMobile
=
()
=>
{
const
{
isOpen
,
onOpen
,
onClose
}
=
useDisclosure
();
const
{
data
}
=
useFetchProfileInfo
();
const
{
data
,
isFetched
}
=
useFetchProfileInfo
();
const
loginUrl
=
link
(
'
auth
'
);
return
(
<>
<
Box
padding=
{
2
}
onClick=
{
onOpen
}
>
<
UserAvatar
size=
{
24
}
data=
{
data
}
/>
<
UserAvatar
size=
{
24
}
data=
{
data
}
isFetched=
{
isFetched
}
/>
</
Box
>
<
Drawer
isOpen=
{
isOpen
}
...
...
@@ -34,7 +34,7 @@ const ProfileMenuMobile = () => {
>
<
ColorModeToggler
/>
<
Box
onClick=
{
onClose
}
>
<
UserAvatar
size=
{
24
}
data=
{
data
}
/>
<
UserAvatar
size=
{
24
}
data=
{
data
}
isFetched=
{
isFetched
}
/>
</
Box
>
</
Flex
>
{
data
?
<
ProfileMenuContent
{
...
data
}
/>
:
(
...
...
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