Skip to content

Commit

Permalink
Merge pull request #38 from AlexSciFier/links-number-fix
Browse files Browse the repository at this point in the history
Maximum number of links fixed
  • Loading branch information
AlexSciFier authored Mar 30, 2023
2 parents 2a60594 + 28c5fa7 commit cfe11cb
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 99 deletions.
122 changes: 56 additions & 66 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion frontend/src/context/bookmarkList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { createContext, useContext, useRef, useState } from "react";
import { deleteJSON, getJSON, putJSON } from "../helpers/fetch";
import { useInterfaceSettings } from "./interfaceSettingsContext";

const BookMarkList = createContext();

Expand All @@ -8,6 +9,8 @@ export function useBookMarkList() {
}

export function BookMarkListProvider({ children }) {
const { maxItemsInList } = useInterfaceSettings();

const [bookmarkList, setBookmarkList] = useState([]);
const [isBookmarksLoading, setIsBookmarksLoading] = useState(true);
const [currentPage, setCurrentPage] = useState(1);
Expand All @@ -21,7 +24,7 @@ export function BookMarkListProvider({ children }) {

async function fetchBookmarks({
offset = 0,
limit = 25,
limit = maxItemsInList,
query,
tag,
category,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/helpers/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const APP_NAME = "NeonLink";
export const VERSION = "1.2.6";
export const VERSION = "1.2.7";
export const DEF_MAX_ITEMS = 20;
export const DEF_COLUMNS = 3;
export const CARD_HEADER_STYLE = [
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/link/components/BookmarksHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DEF_MAX_ITEMS } from "../../../helpers/constants";
import { useLocalStorage } from "../../../hooks/useLocalStorage";
import { useRef } from "react";
import { useSearchParams } from "react-router-dom";
import { useInterfaceSettings } from "../../../context/interfaceSettingsContext";

export default function BookmarksHeader() {
const [query, setQuery] = useState("");
Expand All @@ -13,7 +14,7 @@ export default function BookmarksHeader() {
const delayedQuery = useCallback(debounce(updateBookmarkList, 800), [query]);

const { fetchBookmarks } = useBookMarkList();
const [maxItemsInList] = useLocalStorage("maxItemsInList", DEF_MAX_ITEMS);
const { maxItemsInList } = useInterfaceSettings();
const [searchParams] = useSearchParams();

const firstUpdate = useRef(true);
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/pages/link/components/BookmarksList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import SceletalBokmarkList from "./SceletalBokmarkList";
import { useSearchParams } from "react-router-dom";
import { useBookMarkList } from "../../../context/bookmarkList";
import NoBookmarks from "./NoBookmarks";
import { useLocalStorage } from "../../../hooks/useLocalStorage";
import { DEF_MAX_ITEMS } from "../../../helpers/constants";
import { useInterfaceSettings } from "../../../context/interfaceSettingsContext";

export default function BookmarksList() {
const [searchParams] = useSearchParams();
const [maxItemsInList] = useLocalStorage("maxItemsInList", DEF_MAX_ITEMS);
const { maxItemsInList } = useInterfaceSettings();
const {
bookmarkList,
currentPage,
Expand All @@ -27,7 +26,7 @@ export default function BookmarksList() {
let offset = (page - 1) * limit;

let tag = searchParams.get("tag");
let category = searchParams.get("category")
let category = searchParams.get("category");

if (tag || category) {
fetchBookmarks({ offset, limit, tag, category });
Expand Down
20 changes: 18 additions & 2 deletions frontend/src/pages/link/components/Pagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,25 @@ function range(maxPage, currentPage, siblings) {
if (totalPageNumbers >= maxPage) {
return [...Array(maxPage).keys()].map((idx) => ++idx);
}
let centerArray = [...Array(siblings * 2 + 1).keys()];
centerArray = centerArray.map((idx) => {
let padedArray = [...Array(siblings * 2 + 1).keys()];

let startArray = padedArray.map((idx) => {
return idx + 1;
});

let centerArray = padedArray.map((idx) => {
return idx + currentPage - siblings;
});

let endArray = padedArray.reverse().map((idx) => {
return maxPage - idx;
});

if (currentPage <= 1 + siblings * 2 - 1) {
return [...startArray, "DOTS", maxPage];
}
if (currentPage > maxPage - siblings * 2) {
return [1, "DOTS", ...endArray];
}
return [1, "DOTS", ...centerArray, "DOTS", maxPage];
}
Loading

0 comments on commit cfe11cb

Please sign in to comment.