-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: fix typescript type and use loader to ensure data is loaded (#…
…16) * fix: 修复 TypeScript 类型问题 * example: Resolved TypeScript type and Using Loaders to ensure data is loaded
- Loading branch information
Showing
18 changed files
with
199 additions
and
110 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
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 was deleted.
Oops, something went wrong.
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,11 +1,19 @@ | ||
import React, { createFileRoute } from '@umijs/tnf/router'; | ||
import ItemList from '../../components/item-list'; | ||
import { fetchList } from '../../services/api'; | ||
import type { Params } from '../../types'; | ||
|
||
export const Route = createFileRoute('/ask/$page')({ | ||
component: AskComponent, | ||
loader: async ({ params }: { params: Params }) => | ||
await fetchList('ask', Number(params.page)), | ||
}); | ||
|
||
function AskComponent() { | ||
const { page } = Route.useParams(); | ||
return <ItemList type="ask" page={Number(page)} />; | ||
const { items, maxPage } = Route.useLoaderData(); | ||
|
||
return ( | ||
<ItemList type="ask" page={Number(page)} maxPage={maxPage} items={items} /> | ||
); | ||
} |
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,12 +1,18 @@ | ||
import { createFileRoute } from '@umijs/tnf/router'; | ||
import React, { createFileRoute } from '@umijs/tnf/router'; | ||
import ItemList from '../components/item-list'; | ||
import { fetchList } from '../services/api'; | ||
import type { Params } from '../types'; | ||
|
||
export const Route = createFileRoute('/')({ | ||
component: TopComponent, | ||
loader: async ({ params }: { params: Params }) => | ||
await fetchList('top', Number(params?.page ?? '1') ?? 1), | ||
}); | ||
|
||
function TopComponent() { | ||
const page = Number(Route.useParams()?.page ?? '1') ?? 1; | ||
const params = Route.useParams<Params>(); | ||
const page = Number(params?.page ?? '1') ?? 1; | ||
const { items, maxPage } = Route.useLoaderData(); | ||
|
||
return <ItemList type="top" page={page} />; | ||
return <ItemList type="top" page={page} maxPage={maxPage} items={items} />; | ||
} |
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,16 +1,14 @@ | ||
import React, { useContext } from 'react'; | ||
import { createFileRoute } from '@umijs/tnf/router'; | ||
import React, { createFileRoute } from '@umijs/tnf/router'; | ||
import ItemPage from '../../components/item-page'; | ||
import { Context } from '../../context'; | ||
import { fetchItem } from '../../services'; | ||
|
||
export const Route = createFileRoute('/item/$itemId')({ | ||
component: Item, | ||
loader: async ({ params }: { params: { itemId: string } }) => | ||
await fetchItem(params.itemId), | ||
}); | ||
|
||
function Item() { | ||
const { itemId } = Route.useParams(); | ||
const { state } = useContext(Context); | ||
return ( | ||
<ItemPage item={state.itemsById[itemId]} itemsById={state.itemsById} /> | ||
); | ||
const item = Route.useLoaderData(); | ||
return <ItemPage item={item} />; | ||
} |
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,11 +1,19 @@ | ||
import React, { createFileRoute } from '@umijs/tnf/router'; | ||
import ItemList from '../../components/item-list'; | ||
import { fetchList } from '../../services/api'; | ||
import type { Params } from '../../types'; | ||
|
||
export const Route = createFileRoute('/job/$page')({ | ||
component: JobComponent, | ||
loader: async ({ params }: { params: Params }) => | ||
await fetchList('job', Number(params.page)), | ||
}); | ||
|
||
function JobComponent() { | ||
const { page } = Route.useParams(); | ||
return <ItemList type="job" page={Number(page)} />; | ||
const { items, maxPage } = Route.useLoaderData(); | ||
|
||
return ( | ||
<ItemList type="job" page={Number(page)} maxPage={maxPage} items={items} /> | ||
); | ||
} |
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,11 +1,19 @@ | ||
import React, { createFileRoute } from '@umijs/tnf/router'; | ||
import ItemList from '../../components/item-list'; | ||
import { fetchList } from '../../services/api'; | ||
import type { Params } from '../../types'; | ||
|
||
export const Route = createFileRoute('/new/$page')({ | ||
component: NewComponent, | ||
loader: async ({ params }: { params: Params }) => | ||
await fetchList('new', Number(params.page)), | ||
}); | ||
|
||
function NewComponent() { | ||
const { page } = Route.useParams(); | ||
return <ItemList type="new" page={Number(page)} />; | ||
const { items, maxPage } = Route.useLoaderData(); | ||
|
||
return ( | ||
<ItemList type="new" page={Number(page)} maxPage={maxPage} items={items} /> | ||
); | ||
} |
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,11 +1,19 @@ | ||
import React, { createFileRoute } from '@umijs/tnf/router'; | ||
import ItemList from '../../components/item-list'; | ||
import { fetchList } from '../../services/api'; | ||
import type { Params } from '../../types'; | ||
|
||
export const Route = createFileRoute('/show/$page')({ | ||
component: ShowComponent, | ||
loader: async ({ params }: { params: Params }) => | ||
await fetchList('show', Number(params.page)), | ||
}); | ||
|
||
function ShowComponent() { | ||
const { page } = Route.useParams(); | ||
return <ItemList type="show" page={Number(page)} />; | ||
const { items, maxPage } = Route.useLoaderData(); | ||
|
||
return ( | ||
<ItemList type="show" page={Number(page)} maxPage={maxPage} items={items} /> | ||
); | ||
} |
Oops, something went wrong.