Skip to content

Commit

Permalink
feat(dataset): support url query to save random offset value
Browse files Browse the repository at this point in the history
  • Loading branch information
xifanii committed Mar 27, 2024
1 parent 54be034 commit 3313506
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/app/src/models/dataset/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default () => {
);

const { loading: loadingImgList, run: loadImgList } = useRequest(
(isSlient = false) => {
(isSlient = false, withouOffset = false) => {
// when to load slient
if (!pageState.datasetId || !pageState.filterValues.categoryId) {
throw null;
Expand All @@ -160,7 +160,7 @@ export default () => {
};
if (pageState.queryMode === QueryMode.random) {
Object.assign(params, {
offset: -1,
offset: withouOffset ? -1 : pageState.offset,
pageSize: DEFAULT_PAGE_SIZE,
});
}
Expand Down Expand Up @@ -197,6 +197,9 @@ export default () => {
s.imgList = result.imageList;
s.total = result.total;
});
setPageState((s) => {
s.offset = isNumber(result.offset) ? result.offset : -1;
});
},
onError: () => {},
},
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/models/dataset/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface PageState {
datasetId: string;
datasetName: string;
queryMode: QueryMode;
offset: number;
page: number;
pageSize: number;
// config
Expand Down Expand Up @@ -69,6 +70,7 @@ export const DEFAULT_PAGE_STATE = {
datasetId: '',
datasetName: '',
queryMode: QueryMode.pagination,
offset: -1,
page: 1,
pageSize: DEFAULT_PAGE_SIZE,
cloumnCount: 5,
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/pages/Dataset/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const Header: React.FC = () => {
type="text"
icon={<RandomIcon />}
className={styles.randomBtn}
onClick={() => loadImgList()}
onClick={() => loadImgList(false, true)}
>
{localeText('dataset.detail.randomQuery')}
</Button>
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export namespace NsApiDataset {

export interface FetchImgListRsp {
imageList: Array<NsDataSet.DataSetImg>;
offset: number;
total: number;
}

Expand Down

0 comments on commit 3313506

Please sign in to comment.