This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
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.
feat(modal): add wip modals with routing
- Loading branch information
1 parent
5295b31
commit 7205edb
Showing
16 changed files
with
137 additions
and
21 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 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,13 +1,13 @@ | ||
import { createContext } from 'react' | ||
|
||
interface ModalContextValue { | ||
openKeys: string[] | ||
openKeys: Set<string> | ||
open: (key: string) => void | ||
close: (key: string) => void | ||
} | ||
|
||
export const ModalContext = createContext<ModalContextValue>({ | ||
openKeys: [], | ||
openKeys: new Set(), | ||
open: () => null, | ||
close: () => null, | ||
}) |
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 MODAL_QUERY_PREFIX = 'modal__' |
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,8 @@ | ||
import { MODAL_QUERY_PREFIX } from './MODAL_QUERY_PREFIX' | ||
|
||
export const getModalKeys = (query: object) => | ||
new Set( | ||
Object.keys(query) | ||
.filter(key => key.startsWith(MODAL_QUERY_PREFIX)) | ||
.map(key => key.replace(MODAL_QUERY_PREFIX, '')), | ||
) |
15 changes: 15 additions & 0 deletions
15
front/src/features/modal/helpers/updateRoute/getNewPathname.ts
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,15 @@ | ||
import { getQuery } from './getQuery' | ||
import { getNewSearch } from './getNewSearch' | ||
|
||
export const getNewPathname = ( | ||
search: string, | ||
keyName: string, | ||
keyValue: string | undefined, | ||
pathname: string, | ||
) => { | ||
const prevQuery = getQuery(search) | ||
const newSearch = getNewSearch(prevQuery, keyName, keyValue) | ||
const searchSuffix = newSearch.length > 0 ? `?${newSearch}` : '' | ||
const newPathname = `${pathname}${searchSuffix}` | ||
return newPathname | ||
} |
11 changes: 11 additions & 0 deletions
11
front/src/features/modal/helpers/updateRoute/getNewSearch.ts
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,11 @@ | ||
import qs from 'qs' | ||
|
||
export const getNewSearch = ( | ||
prevQuery: any, | ||
keyName: string, | ||
currentKey?: string, | ||
) => | ||
qs.stringify({ | ||
...(prevQuery || {}), | ||
[keyName]: currentKey, | ||
}) |
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,3 @@ | ||
import qs from 'qs' | ||
|
||
export const getQuery = (search: string) => qs.parse(search.split('?')[1]) |
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 { updateRoute } from './updateRoute' |
10 changes: 10 additions & 0 deletions
10
front/src/features/modal/helpers/updateRoute/updateRoute.ts
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,10 @@ | ||
import { pushRoute } from '@front/features/routing' | ||
|
||
import { getNewPathname } from './getNewPathname' | ||
|
||
export const updateRoute = (keyName: string, keyValue?: string) => { | ||
const { pathname, search } = window.location | ||
const newPathname = getNewPathname(search, keyName, keyValue, pathname) | ||
|
||
return pushRoute(newPathname) | ||
} |
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,14 +1,11 @@ | ||
import { useContext } from 'react' | ||
import { useMemo } from 'react' | ||
import { ModalContext } from './ModalContext' | ||
|
||
export const useModalActions = (key: string) => { | ||
const { open, close } = useContext(ModalContext) | ||
|
||
return useMemo(() => { | ||
return { | ||
open: () => open(key), | ||
close: () => close(key), | ||
} | ||
}, [open, close, key]) | ||
return { | ||
open: () => open(key), | ||
close: () => close(key), | ||
} | ||
} |
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