This repository was archived by the owner on Nov 8, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork37
refactor(redesign): explore as home page#1250
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletionssrc/containers/content/ExploreContent/styles/community_card.ts
This file contains hidden or 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
1 change: 0 additions & 1 deletionsrc/containers/content/ExploreContent/styles/community_list.ts
This file contains hidden or 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
2 changes: 1 addition & 1 deletionsrc/containers/content/ExploreContent/styles/sidebar.ts
This file contains hidden or 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
6 changes: 3 additions & 3 deletionssrc/containers/unit/Footer/DesktopView/TopInfo/index.tsx
This file contains hidden or 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
5 changes: 2 additions & 3 deletionssrc/containers/unit/Footer/DesktopView/index.tsx
This file contains hidden or 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
11 changes: 2 additions & 9 deletionssrc/pages/plaza.tsx → src/pages/gallery.tsx
This file contains hidden or 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
110 changes: 110 additions & 0 deletionssrc/pages/hot.tsx
This file contains hidden or 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,110 @@ | ||
import { Provider } from 'mobx-react' | ||
import { GetStaticProps } from 'next' | ||
import { merge, toLower } from 'ramda' | ||
// import { PAGE_SIZE } from '@/config' | ||
import { HCN, THREAD, METRIC, ROUTE } from '@/constant' | ||
import { useStore } from '@/stores/init' | ||
import { | ||
isArticleThread, | ||
ssrPagedArticleSchema, | ||
isrPagedArticlesFilter, | ||
ssrParseArticleThread, | ||
communitySEO, | ||
singular, | ||
makeGQClient, | ||
} from '@/utils' | ||
import GlobalLayout from '@/containers/layout/GlobalLayout' | ||
import CommunityContent from '@/containers/content/CommunityContent' | ||
import { P } from '@/schemas' | ||
const loader = async () => { | ||
const gqClient = makeGQClient('') | ||
// 线上环境会直接跳过 index 到这里,有待排查。。 | ||
const community = HCN | ||
const thread = THREAD.POST | ||
// query data | ||
const curCommunity = gqClient.request(P.community, { | ||
raw: community, | ||
userHasLogin: false, | ||
}) | ||
const pagedArticleTags = gqClient.request(P.pagedArticleTags, { | ||
filter: { communityRaw: community, thread: singular(thread, 'upperCase') }, | ||
}) | ||
const filter = isrPagedArticlesFilter({}) | ||
const pagedArticles = isArticleThread(thread) | ||
? gqClient.request(ssrPagedArticleSchema(thread), filter) | ||
: {} | ||
return { | ||
filter, | ||
...(await pagedArticleTags), | ||
...(await curCommunity), | ||
...(await pagedArticles), | ||
} | ||
} | ||
// export const getStaticPaths: GetStaticPaths = async () => { | ||
// return { paths: [], fallback: true } | ||
// } | ||
export const getStaticProps: GetStaticProps = async (ctx) => { | ||
console.log('hot params: ', ctx) | ||
const thread = THREAD.POST | ||
const resp = await loader() | ||
const { filter, community, pagedArticleTags } = resp | ||
// console.log('iii got resp: ', resp) | ||
const articleThread = ssrParseArticleThread(resp, thread, filter) | ||
const initProps = merge( | ||
{ | ||
// ...ssrBaseStates(resp), | ||
route: { | ||
communityPath: community.raw, | ||
mainPath: ROUTE.HOT, | ||
subPath: thread === THREAD.POST ? '' : thread, | ||
thread, | ||
}, | ||
tagsBar: { | ||
tags: pagedArticleTags.entries, | ||
}, | ||
viewing: { | ||
community, | ||
activeThread: toLower(thread), | ||
}, | ||
}, | ||
articleThread, | ||
) | ||
return { props: { errorCode: null, ...initProps }, revalidate: 10 } | ||
} | ||
const CommunityPage = (props) => { | ||
const store = useStore(props) | ||
const { viewing } = store | ||
const { community, activeThread } = viewing | ||
return ( | ||
<Provider store={store}> | ||
<GlobalLayout | ||
metric={METRIC.COMMUNITY} | ||
seoConfig={communitySEO(community, activeThread)} | ||
> | ||
<CommunityContent /> | ||
</GlobalLayout> | ||
</Provider> | ||
) | ||
} | ||
export default CommunityPage |
143 changes: 69 additions & 74 deletionssrc/pages/index.tsx
This file contains hidden or 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,106 +1,101 @@ | ||
/* | ||
this page is for /explore | ||
*/ | ||
import { Provider } from 'mobx-react' | ||
import { clone } from 'ramda' | ||
import { METRIC } from '@/constant' | ||
import { PAGE_SIZE } from '@/config' | ||
import { | ||
ssrBaseStates, | ||
ssrFetchPrepare, | ||
ssrGetParam, | ||
refreshIfneed, | ||
exploreSEO, | ||
ssrError, | ||
} from '@/utils' | ||
import { useStore } from '@/stores/init' | ||
import GlobalLayout from '@/containers/layout/GlobalLayout' | ||
importExploreContent from '@/containers/content/ExploreContent' | ||
import { P } from '@/schemas' | ||
const loader = async (context, opt = {}) => { | ||
const{gqClient, userHasLogin } = ssrFetchPrepare(context, opt) | ||
const category = ssrGetParam(context, 'nc_path') | ||
const page = ssrGetParam(context, 'page') | ||
const filter = { | ||
page: 1, | ||
size: PAGE_SIZE.M, | ||
} | ||
const communitiesFilter = clone(filter) | ||
// @ts-ignore | ||
if (category) communitiesFilter.category = category | ||
if (page) communitiesFilter.page = parseInt(page, 10) | ||
const sessionState = gqClient.request(P.sessionState) | ||
const pagedCommunities = gqClient.request(P.pagedCommunities, { | ||
filter: communitiesFilter, | ||
userHasLogin, | ||
}) | ||
const pagedCategories = gqClient.request(P.pagedCategories, { filter }) | ||
const subscribedCommunities = gqClient.request(P.subscribedCommunities, { | ||
filter: { | ||
page: 1, | ||
size: 30, | ||
}, | ||
}) | ||
return { | ||
...(await sessionState), | ||
...(awaitpagedCategories), | ||
...(awaitpagedCommunities), | ||
...(awaitsubscribedCommunities), | ||
} | ||
} | ||
export const getServerSideProps = async (context) => { | ||
let resp | ||
try { | ||
resp = await loader(context) | ||
const { sessionState } = resp | ||
refreshIfneed(sessionState, '/explore', context) | ||
} catch (e) { | ||
console.log('#### error from server: ', e) | ||
return ssrError(context, 'fetch', 500) | ||
} | ||
const { pagedCategories, pagedCommunities } = resp | ||
const initProps = { | ||
...ssrBaseStates(resp), | ||
exploreContent: { | ||
pagedCommunities, | ||
pagedCategories, | ||
}, | ||
} | ||
return { props: { errorCode: null, ...initProps } } | ||
} | ||
constExplorePage = (props) => { | ||
const store = useStore(props) | ||
const seoConfig = exploreSEO() | ||
return ( | ||
<Provider store={store}> | ||
<GlobalLayout metric={METRIC.EXPLORE} seoConfig={seoConfig} noSidebar> | ||
<ExploreContent /> | ||
</GlobalLayout> | ||
</Provider> | ||
) | ||
} | ||
export defaultExplorePage |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.