Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
feat: add image adaptive control
Browse files Browse the repository at this point in the history
  • Loading branch information
IronKinoko committed Nov 17, 2021
1 parent 641a6f2 commit 7dde851
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "e-hentai-view",
"productName": "EhentaiView",
"version": "4.1.0",
"version": "4.1.1",
"main": "server/src/app.js",
"license": "MIT",
"homepage": "https://exhentai.appspot.com",
Expand Down Expand Up @@ -111,4 +111,4 @@
"trailingComma": "es5",
"arrowParens": "always"
}
}
}
3 changes: 2 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@
"ShowTag.Watched": "Only Watched",
"ShowTag.All": "All",
"ShowTag.Hidden": "Hidden",
"Similar": "Similar"
"Similar": "Similar",
"imgFit":"Picture adaptive"
}
3 changes: 2 additions & 1 deletion public/locales/kr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@
"ShowTag.Watched": "Watched 만",
"ShowTag.All": "모두",
"ShowTag.Hidden": "숨김",
"Similar": "유사"
"Similar": "유사",
"imgFit":"픽처 어댑티브"
}
3 changes: 2 additions & 1 deletion public/locales/ms/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@
"ShowTag.Watched": "Only Watched",
"ShowTag.All": "All",
"ShowTag.Hidden": "Hidden",
"Similar": "Similar"
"Similar": "Similar",
"imgFit":"Picture adaptive"
}
3 changes: 2 additions & 1 deletion public/locales/th/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@
"ShowTag.Watched": "เฉพาะที่ติดตาม",
"ShowTag.All": "ทั้งหมด",
"ShowTag.Hidden": "ซ่อน",
"Similar": "คล้ายกัน"
"Similar": "คล้ายกัน",
"imgFit":"การปรับภาพ"
}
3 changes: 2 additions & 1 deletion public/locales/zh-CN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@
"ShowTag.Watched": "仅在订阅中显示",
"ShowTag.All": "全部显示",
"ShowTag.Hidden": "不显示",
"Similar": "相关画廊"
"Similar": "相关画廊",
"imgFit":"图片自适应"
}
8 changes: 8 additions & 0 deletions src/widgets/comic/ComicConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ import useEnhanceLocalStorageState from '@/hooks/useEnhanceLocalStorageState'
import { LOCAL_COMIC_CONFIG } from '@/constant'

export interface ComicConfigProps {
/**
* comic direction
*/
direction?: 'ltr' | 'rtl' | 'vertical'
/**
* horizontal mode image fit width/height
*/
imgFit?: boolean
}

const defualtComicConfig: ComicConfigProps = {
direction: 'vertical',
imgFit: true,
}

const ComicConfigContext = createContext<
Expand Down
12 changes: 11 additions & 1 deletion src/widgets/comic/ComicHorizontalList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const useStyles = makeStyles((theme: Theme) =>
userSelect: 'none',
},
imgContainer: {
display: 'flex',
alignItems: 'center',
minHeight: '100vh',
},
imgFitContainer: {
display: 'flex',
alignItems: 'center',
height: '100vh',
Expand Down Expand Up @@ -108,13 +113,18 @@ const ComicHorizontalList: React.FC<{
>
{data.list.map((o, k) => (
<SwiperSlide key={o?.url ?? k} data-hovindex={k}>
<div className={classes.imgContainer}>
<div
className={
config.imgFit ? classes.imgFitContainer : classes.imgContainer
}
>
<ComicItem
key={o?.url || k}
index={k}
thumb={o?.thumb}
url={o?.url}
comicPagesKey={comicPagesKey}
noMinHeight
/>
</div>
</SwiperSlide>
Expand Down
17 changes: 14 additions & 3 deletions src/widgets/comic/ComicItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,19 @@ const useStyles = makeStyles((theme: Theme) =>
)

const ComicItem: React.FC<
Partial<DetailPageListItemProps> & { index: number; comicPagesKey: string }
> = ({ index, thumb, url, aspectratio = 210 / 297, comicPagesKey }) => {
Partial<DetailPageListItemProps> & {
index: number
comicPagesKey: string
noMinHeight?: boolean
}
> = ({
index,
thumb,
url,
aspectratio = 210 / 297,
comicPagesKey,
noMinHeight,
}) => {
const classes = useStyles()
const ref = useRef<HTMLDivElement>(null)
const [pageUrl, setPageUrl] = useState(url)
Expand All @@ -51,7 +62,7 @@ const ComicItem: React.FC<
return (
<div
ref={ref}
style={{ minHeight }}
style={{ minHeight: noMinHeight ? '' : minHeight }}
className={classes.root}
data-index={index}
// eslint-disable-next-line jsx-a11y/aria-role
Expand Down
18 changes: 18 additions & 0 deletions src/widgets/comic/ComicSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
ListItemText,
MenuItem,
Select,
Switch,
} from '@material-ui/core'
import { useTranslation } from 'next-i18next'
import React from 'react'
import { ComicConfigProps, useComicConfigState } from './ComicConfig'

/**
* comic setting ui
*/
Expand All @@ -26,6 +28,9 @@ const ComicSettings: React.FC<{ onChange?: () => void }> = ({ onChange }) => {
})
onChange?.()
}

const isVertical = config.direction === 'vertical'

return (
<div>
<List>
Expand All @@ -43,6 +48,19 @@ const ComicSettings: React.FC<{ onChange?: () => void }> = ({ onChange }) => {
</Select>
</ListItemSecondaryAction>
</ListItem>
{!isVertical && (
<ListItem>
<ListItemText>{t('imgFit')}</ListItemText>
<ListItemSecondaryAction>
<Switch
checked={config.imgFit}
onChange={(e) =>
setConfig((t) => ({ ...t, imgFit: e.target.checked }))
}
/>
</ListItemSecondaryAction>
</ListItem>
)}
</List>
</div>
)
Expand Down

0 comments on commit 7dde851

Please sign in to comment.