Skip to content

Commit 0dd6b70

Browse files
authored
Merge pull request #7 from Arylo/feat/add-unit-tests-for-injectDataIndex
Add unit tests and refactor injectDataIndex utility function
2 parents 4c9db14 + 271e89f commit 0dd6b70

5 files changed

Lines changed: 516 additions & 36 deletions

File tree

apps/monkey/copymanga-enhance/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"lint:type-check": "tsc -p tsconfig.json --noEmit",
1414
"lint:formatter": "oxfmt --check",
1515
"lint:oxlint": "oxlint",
16+
"fix": "concurrently -m 1 --timings npm:fix:*",
1617
"fix:formatter": "oxfmt"
1718
},
1819
"dependencies": {

apps/monkey/copymanga-enhance/scripts/detail/newPage/hooks/useImageList.ts

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import flow from '@scripts/flow'
2-
import { defineComponent, onMounted, readonly, ref, unref, watch } from '@scripts/gm-vue'
2+
import { onMounted, readonly, ref, unref, watch } from '@scripts/gm-vue'
33
import Image from '../component/Image'
44
import WhitePage from '../component/WhitePage'
55
import { DirectionMode, PageType } from '../constant'
66
import useDirectionMode from './useDirectionMode'
77
import useImageInfoMap from './useImageInfoMap'
88
import useRawImageList from './useRawImageList'
99
import useWhitePage from './useWhitePage'
10-
11-
type ImageItem = {
12-
component: ReturnType<typeof defineComponent> | string
13-
props: { key: string; pageType: PageType } & Record<string, any>
14-
}
10+
import { injectDataIndexInternal } from './utils/injectDataIndex'
11+
import { ImageItem } from './utils/types'
1512

1613
export default function useImageList() {
1714
const rawImageListRef = useRawImageList()
@@ -116,36 +113,7 @@ export default function useImageList() {
116113
return tempList.flat()
117114
}
118115
const injectDataIndex = (list: ImageItem[]): ImageItem[] => {
119-
let portraitCount = 0
120-
return list.map((item, index) => {
121-
let targetIndex = index + 1
122-
let side = 'A'
123-
if (item.props.pageType === PageType.LANDSCAPE) {
124-
portraitCount = 0
125-
side = 'A'
126-
} else {
127-
portraitCount++
128-
if (DirectionMode.RTL === unref(directionModeRef)) {
129-
if (portraitCount % 2 === 0) {
130-
targetIndex -= 1
131-
} else {
132-
targetIndex += 1
133-
}
134-
side = portraitCount % 2 === 1 ? 'R' : 'L'
135-
}
136-
if (DirectionMode.LTR === unref(directionModeRef)) {
137-
side = portraitCount % 2 === 1 ? 'L' : 'R'
138-
}
139-
}
140-
return {
141-
...item,
142-
props: {
143-
...item.props,
144-
'data-index': targetIndex,
145-
'data-side': side,
146-
},
147-
}
148-
})
116+
return injectDataIndexInternal(list, unref(directionModeRef))
149117
}
150118
const imagesRef = ref<ImageItem[]>([])
151119
function refresh() {

0 commit comments

Comments
 (0)