1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-08 06:55:26 +02:00

fix next/prev buttons

This commit is contained in:
Nikita Melnikov 2022-10-03 18:32:19 +08:00
parent 432edd6167
commit 8d566c8c78
2 changed files with 6 additions and 5 deletions

View file

@ -2,6 +2,7 @@ import Page from './page.js';
import PageOrder from './pageOrder.js';
import NodeCache from 'node-cache';
import { EntityId } from '../database/types.js';
import { isEqualIds } from '../database/index.js';
// Create cache for flat array
const cache = new NodeCache({ stdTTL: 120 });
@ -109,7 +110,7 @@ class PagesFlatArray {
public static async getPageBefore(pageId: EntityId): Promise<PagesFlatArrayData | undefined> {
const arr = await this.get();
const pageIndex = arr.findIndex( (item) => item.id == pageId);
const pageIndex = arr.findIndex((item) => isEqualIds(item.id, pageId));
// Check if index is not the first
if (pageIndex && pageIndex > 0) {
@ -129,7 +130,7 @@ class PagesFlatArray {
public static async getPageAfter(pageId: EntityId): Promise<PagesFlatArrayData | undefined> {
const arr = await this.get();
const pageIndex = arr.findIndex( (item) => item.id == pageId );
const pageIndex = arr.findIndex( (item) => isEqualIds(item.id, pageId));
// Check if index is not the last
if (pageIndex < arr.length -1) {
@ -153,7 +154,7 @@ class PagesFlatArray {
pages: Array<Page>, orders: Array<PageOrder>): Array<PagesFlatArrayData> {
let arr: Array<PagesFlatArrayData> = new Array<PagesFlatArrayData>();
const page = pages.find( item => item._id == pageId );
const page = pages.find(item => isEqualIds(item._id, pageId));
// Add element to child array
if (page) {
@ -167,7 +168,7 @@ class PagesFlatArray {
} );
}
const order = orders.find(item => item.page == pageId);
const order = orders.find(item => isEqualIds(item.page, pageId));
if (order) {
for (const childPageId of order.order) {

View file

@ -29,7 +29,7 @@
<a
class="docs-sidebar__section-list-item-wrapper"
href="{{ child.uri ? '/' ~ child.uri : '/page/' ~ child._id }}">
<div class="docs-sidebar__section-list-item {{page is defined and page._id == child._id ? 'docs-sidebar__section-list-item--active' : ''}}">
<div class="docs-sidebar__section-list-item {{page is defined and toString(page._id) == toString(child._id) ? 'docs-sidebar__section-list-item--active' : ''}}">
<span>{{ child.title | striptags }}</span>
</div>
</a>