|
1 | 1 | import R from 'ramda' |
2 | 2 |
|
3 | | -import { makeDebugger, isEmptyNil } from '../../utils' |
| 3 | +import { makeDebugger /* isEmptyNil, getParameterByName */ } from '../../utils' |
4 | 4 |
|
5 | 5 | /* eslint-disable no-unused-vars */ |
6 | 6 | const debug = makeDebugger('L:Route') |
7 | 7 | /* eslint-enable no-unused-vars */ |
8 | 8 |
|
9 | 9 | let route = null |
10 | 10 |
|
11 | | -const getAsPathList = R.compose( |
| 11 | +/* |
| 12 | + const getAsPathList = R.compose( |
| 13 | + R.reject(R.isEmpty), |
| 14 | + R.split('/'), |
| 15 | + R.prop('asPath') |
| 16 | + ) |
| 17 | +
|
| 18 | + const getQueryMain = routeObj => { |
| 19 | + if (R.isEmpty(routeObj)) return '' |
| 20 | +
|
| 21 | + if (isEmptyNil(routeObj.query) && routeObj.pathname !== '/') { |
| 22 | + return routeObj.pathname.slice(1) |
| 23 | + } else if (isEmptyNil(routeObj.query) && routeObj.pathname === '/') { |
| 24 | + const asPathList = getAsPathList(routeObj) |
| 25 | + return R.head(asPathList) |
| 26 | + } |
| 27 | +
|
| 28 | + return routeObj.query.main |
| 29 | + } |
| 30 | +
|
| 31 | + const getQuerySub = routeObj => { |
| 32 | + const asPathList = getAsPathList(routeObj) |
| 33 | + return R.last(asPathList) |
| 34 | + } |
| 35 | + */ |
| 36 | + |
| 37 | +const asPathForMain = R.compose( |
| 38 | + R.head, |
| 39 | + R.split('?'), |
| 40 | + R.head, |
12 | 41 | R.reject(R.isEmpty), |
13 | 42 | R.split('/'), |
14 | 43 | R.prop('asPath') |
15 | 44 | ) |
16 | 45 |
|
17 | | -const getQueryMain = routeObj => { |
18 | | - if (R.isEmpty(routeObj)) return '' |
| 46 | +const INDEX = '' |
| 47 | +const getMainPath = routeObj => { |
| 48 | + if (R.isEmpty(routeObj)) return INDEX |
| 49 | + const { asPath } = routeObj |
| 50 | + if (asPath === '/') return INDEX |
19 | 51 |
|
20 | | - if (isEmptyNil(routeObj.query) && routeObj.pathname !== '/') { |
21 | | - return routeObj.pathname.slice(1) |
22 | | - } else if (isEmptyNil(routeObj.query) && routeObj.pathname === '/') { |
23 | | - const asPathList = getAsPathList(routeObj) |
24 | | - return R.head(asPathList) |
25 | | - } |
| 52 | + /* const test = splitAsPathTest('/communities/posts/?page=1&size=20') */ |
| 53 | + /* console.log('test --> ', test) */ |
26 | 54 |
|
27 | | - return routeObj.query.main |
| 55 | + /* const asPathList = splitAsPath(routeObj) */ |
| 56 | + /* console.log('asPathList -- > ', asPathList) */ |
| 57 | + return asPathForMain(routeObj) |
28 | 58 | } |
29 | 59 |
|
30 | | -const getQuerySub = routeObj => { |
31 | | - const asPathList = getAsPathList(routeObj) |
32 | | - return R.last(asPathList) |
| 60 | +const asPathForSub = R.compose( |
| 61 | + R.reject(R.isEmpty), |
| 62 | + R.split('/'), |
| 63 | + R.head, |
| 64 | + R.reject(R.contains('=')), |
| 65 | + R.reject(R.isEmpty), |
| 66 | + R.split('?'), |
| 67 | + R.prop('asPath') |
| 68 | +) |
| 69 | + |
| 70 | +const getSubPath = routeObj => { |
| 71 | + if (R.isEmpty(routeObj)) return INDEX |
| 72 | + |
| 73 | + const { asPath } = routeObj |
| 74 | + if (asPath === '/') return INDEX |
| 75 | + |
| 76 | + const asPathList = asPathForSub(routeObj) |
| 77 | + /* console.log('asPath jjj -> ', asPathList) */ |
| 78 | + /* const asPathList = asPathForSub('/communities') */ |
| 79 | + |
| 80 | + /* const asPathList = asPathForSub('/communities/posts?page=2&size=20') */ |
| 81 | + /* const asPathListtest = asPathForSub('/communities/posts/?page=2&size=20') */ |
| 82 | + /* const asPathListtest = fuckmetest('/communities') */ |
| 83 | + /* const asPathListtest = fuckmetest('/communities/') */ |
| 84 | + /* console.log('asPathListtest jjj -> ', asPathListtest) */ |
| 85 | + |
| 86 | + return asPathList.length > 1 ? asPathList[1] : asPathList[0] |
33 | 87 | } |
34 | 88 |
|
35 | 89 | export function syncRoute(routeObj) { |
36 | | - /* console.log('syncRoute routeObj: ', routeObj) */ |
37 | | - /* |
38 | | - console.log('syncRoute query: ', routeObj.query) |
39 | | - console.log('syncRoute pathname: ', routeObj.pathname) |
40 | | - console.log('syncRoute asPath: ', routeObj.asPath) |
41 | | - console.log('syncRoute route: ', routeObj.route) |
| 90 | + /* const mainQuery = getQueryMain(routeObj) */ |
| 91 | + const mainQuery = getMainPath(routeObj) |
| 92 | + /* console.log('mainQuery ## ', mainQuery) */ |
42 | 93 |
|
43 | | - console.log(' ---------- ') |
44 | | - console.log('### getQueryMain: ', getQueryMain(routeObj)) |
45 | | - console.log('### getQuerySub: ', getQuerySub(routeObj)) |
46 | | - */ |
| 94 | + const subQuery = getSubPath(routeObj) |
| 95 | + /* const subQuery = getSubPath(routeObj) */ |
| 96 | + /* const subPath = getSubPath(routeObj) */ |
| 97 | + /* console.log('subPath final --> ', subPath) */ |
47 | 98 |
|
48 | | - const mainQuery = getQueryMain(routeObj) |
49 | | - const subQuery = getQuerySub(routeObj) |
| 99 | + const { query } = routeObj |
50 | 100 |
|
| 101 | + // TODO: mainQuery -> mainPath |
| 102 | + // subQuery -> subPath |
51 | 103 | route.markState({ |
52 | 104 | mainQuery, |
53 | 105 | subQuery, |
| 106 | + query, |
54 | 107 | }) |
55 | 108 | } |
56 | 109 |
|
|
0 commit comments