Explorar o código

"LIMIT" -> "PAGING_LIMIT"

Shun Miyazawa %!s(int64=4) %!d(string=hai) anos
pai
achega
9f59d00d98

+ 7 - 6
packages/app/src/components/Sidebar/Tag.tsx

@@ -9,12 +9,13 @@ import TagCloudBox from '../TagCloudBox';
 import TagList from '../TagList';
 import TagList from '../TagList';
 
 
 
 
-const LIMIT = 10;
+const PAGING_LIMIT = 10;
 
 
 const Tag: FC = () => {
 const Tag: FC = () => {
+  const [activePage, setActivePage] = useState<number>(1);
   const [offset, setOffset] = useState<number>(0);
   const [offset, setOffset] = useState<number>(0);
 
 
-  const { data: tagDataList, mutate: mutateTagDataList, error } = useSWRxTagsList(LIMIT, offset);
+  const { data: tagDataList, mutate: mutateTagDataList, error } = useSWRxTagsList(PAGING_LIMIT, offset);
   const tagData: ITagCountHasId[] = tagDataList?.data || [];
   const tagData: ITagCountHasId[] = tagDataList?.data || [];
   const totalCount: number = tagDataList?.totalCount || 0;
   const totalCount: number = tagDataList?.totalCount || 0;
   const isLoading = tagDataList === undefined && error == null;
   const isLoading = tagDataList === undefined && error == null;
@@ -22,8 +23,8 @@ const Tag: FC = () => {
   const { t } = useTranslation('');
   const { t } = useTranslation('');
 
 
   const setOffsetByPageNumber = useCallback((selectedPageNumber: number) => {
   const setOffsetByPageNumber = useCallback((selectedPageNumber: number) => {
-    // offset = (selectedPageNumber - 1) * 10
-    setOffset((selectedPageNumber - 1) * 10);
+    setActivePage(selectedPageNumber);
+    setOffset((selectedPageNumber - 1) * PAGING_LIMIT);
   }, []);
   }, []);
 
 
   const onReload = useCallback(() => {
   const onReload = useCallback(() => {
@@ -69,9 +70,9 @@ const Tag: FC = () => {
           <TagList
           <TagList
             tagData={tagData}
             tagData={tagData}
             totalTags={totalCount}
             totalTags={totalCount}
-            activePage={1 + (offset / 10)} // activePage = 1 + offset / 10
+            activePage={activePage}
             onChangePage={setOffsetByPageNumber}
             onChangePage={setOffsetByPageNumber}
-            limit={LIMIT}
+            pagingLimit={PAGING_LIMIT}
           />
           />
         )
         )
       }
       }

+ 3 - 3
packages/app/src/components/TagList.tsx

@@ -13,7 +13,7 @@ type TagListProps = {
   totalTags: number,
   totalTags: number,
   activePage: number,
   activePage: number,
   onChangePage?: (selectedPageNumber: number) => void,
   onChangePage?: (selectedPageNumber: number) => void,
-  limit: number,
+  pagingLimit: number,
   isPaginationShown?: boolean,
   isPaginationShown?: boolean,
 }
 }
 
 
@@ -23,7 +23,7 @@ const defaultProps = {
 
 
 const TagList: FC<TagListProps> = (props:(TagListProps & typeof defaultProps)) => {
 const TagList: FC<TagListProps> = (props:(TagListProps & typeof defaultProps)) => {
   const {
   const {
-    tagData, totalTags, activePage, onChangePage, limit, isPaginationShown,
+    tagData, totalTags, activePage, onChangePage, pagingLimit, isPaginationShown,
   } = props;
   } = props;
   const isTagExist: boolean = tagData.length > 0;
   const isTagExist: boolean = tagData.length > 0;
   const { t } = useTranslation('');
   const { t } = useTranslation('');
@@ -60,7 +60,7 @@ const TagList: FC<TagListProps> = (props:(TagListProps & typeof defaultProps)) =
           activePage={activePage}
           activePage={activePage}
           changePage={onChangePage}
           changePage={onChangePage}
           totalItemsCount={totalTags}
           totalItemsCount={totalTags}
-          pagingLimit={limit}
+          pagingLimit={pagingLimit}
           align="center"
           align="center"
           size="md"
           size="md"
         />
         />

+ 4 - 5
packages/app/src/components/TagPage.tsx

@@ -8,12 +8,12 @@ import { useSWRxTagsList } from '~/stores/tag';
 import TagCloudBox from './TagCloudBox';
 import TagCloudBox from './TagCloudBox';
 import TagList from './TagList';
 import TagList from './TagList';
 
 
-const LIMIT = 10;
+const PAGING_LIMIT = 10;
 
 
 const TagPage: FC = () => {
 const TagPage: FC = () => {
   const [offset, setOffset] = useState<number>(0);
   const [offset, setOffset] = useState<number>(0);
 
 
-  const { data: tagDataList, error } = useSWRxTagsList(LIMIT, offset);
+  const { data: tagDataList, error } = useSWRxTagsList(PAGING_LIMIT, offset);
   const tagData: ITagCountHasId[] = tagDataList?.data || [];
   const tagData: ITagCountHasId[] = tagDataList?.data || [];
   const totalCount: number = tagDataList?.totalCount || 0;
   const totalCount: number = tagDataList?.totalCount || 0;
   const isLoading = tagDataList === undefined && error == null;
   const isLoading = tagDataList === undefined && error == null;
@@ -21,8 +21,7 @@ const TagPage: FC = () => {
   const { t } = useTranslation('');
   const { t } = useTranslation('');
 
 
   const setOffsetByPageNumber = useCallback((selectedPageNumber: number) => {
   const setOffsetByPageNumber = useCallback((selectedPageNumber: number) => {
-    // offset = (selectedPageNumber - 1) * 10
-    setOffset((selectedPageNumber - 1) * 10);
+    setOffset((selectedPageNumber - 1) * PAGING_LIMIT);
   }, []);
   }, []);
 
 
   // todo: adjust margin and redesign tags page
   // todo: adjust margin and redesign tags page
@@ -45,7 +44,7 @@ const TagPage: FC = () => {
               totalTags={totalCount}
               totalTags={totalCount}
               activePage={1 + (offset / 10)} // activePage = 1 + offset / 10
               activePage={1 + (offset / 10)} // activePage = 1 + offset / 10
               onChangePage={setOffsetByPageNumber}
               onChangePage={setOffsetByPageNumber}
-              limit={LIMIT}
+              pagingLimit={PAGING_LIMIT}
             />
             />
           </div>
           </div>
         )
         )