Skip to content

Commit 84d8192

Browse files
authored
T286725: Use screen-sized images (#372)
* Load screen-sized images * Update special case test * Only one api call in Gallery
1 parent 0013ad4 commit 84d8192

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

cypress/integration/special-cases.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('special cases tests', () => {
2626
articlePage.title().should('have.text', 'Użytkownicy[24]')
2727
cy.rightArrow()
2828
cy.enter()
29-
cy.get('.gallery-view>.img>img').should('be.visible').should('have.attr', 'src', 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/Tupolev_Tu-154B%2C_Tarom_AN0679876.jpg/640px-Tupolev_Tu-154B%2C_Tarom_AN0679876.jpg')
29+
cy.get('.gallery-view>.img>img').should('be.visible').should('have.attr', 'src', 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/Tupolev_Tu-154B%2C_Tarom_AN0679876.jpg/240px-Tupolev_Tu-154B%2C_Tarom_AN0679876.jpg')
3030
})
3131

3232
it('check goto quickfacts holly', () => {

src/api/getArticleMediaInfo.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cachedFetch, buildMwApiUrl, buildCommonsApiUrl } from 'utils'
1+
import { cachedFetch, buildMwApiUrl, buildCommonsApiUrl, viewport } from 'utils'
22

33
export const getArticleMediaInfo = (lang, title, fromCommon) => {
44
const params = {
@@ -7,6 +7,8 @@ export const getArticleMediaInfo = (lang, title, fromCommon) => {
77
iiextmetadatafilter: 'License|LicenseShortName|ImageDescription|Artist',
88
iiextmetadatalanguage: lang,
99
iiextmetadatamultilang: 1,
10+
iiurlwidth: viewport().width,
11+
iiurlheight: viewport().height,
1012
iiprop: 'url|extmetadata',
1113
titles: title
1214
}
@@ -31,7 +33,8 @@ export const getArticleMediaInfo = (lang, title, fromCommon) => {
3133
author,
3234
description,
3335
license: LicenseShortName && LicenseShortName.value,
34-
filePage: convertUrlToMobile(imageInfo[0].descriptionshorturl)
36+
filePage: convertUrlToMobile(imageInfo[0].descriptionshorturl),
37+
source: imageInfo[0].thumburl
3538
}
3639
})
3740
}

src/api/getArticleMediaList.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export const getArticleMediaList = (lang, title) => {
77
const source = item && item.srcset && `https:${item.srcset[0].src}`
88
const media = {
99
caption: item.caption && item.caption.text.trim(),
10-
thumbnail: source,
1110
title: item.title,
1211
canonicalizedTitle:
1312
item.title && canonicalizeTitle(item.title.split(':')[1]),

src/components/Gallery.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import { useI18n, useSoftkey, usePopup, useRange, useArticleMediaInfo } from 'ho
44

55
const MAX_DESCRIPTION_HEIGHT = 45
66

7-
const AboutContainer = ({ lang, dir, title, caption, fromCommon, close }) => {
7+
const AboutContainer = ({ mediaInfo, dir, title, caption, close }) => {
88
const i18n = useI18n()
99
const containerRef = useRef()
10-
const mediaInfo = useArticleMediaInfo(lang, title, fromCommon)
1110

1211
useSoftkey('About', {
1312
left: i18n('softkey-close'),
@@ -88,6 +87,7 @@ export const Gallery = ({ close, closeAll, items, startFileName, lang, dir }) =>
8887
currentIndex, onPrevImage, onNextImage
8988
] = useRange(getInitialIndex(items, startFileName), items.length - 1)
9089
const [showAboutPopup] = usePopup(AboutContainer, { stack: true })
90+
const mediaInfo = useArticleMediaInfo(lang, items[currentIndex].title, items[currentIndex].fromCommon, currentIndex)
9191

9292
const onImageLoad = ({ target: img }) => {
9393
const galleryNode = containerRef.current
@@ -105,7 +105,7 @@ export const Gallery = ({ close, closeAll, items, startFileName, lang, dir }) =>
105105
left: i18n('softkey-close'),
106106
onKeyLeft: closeAll,
107107
center: i18n('softkey-about'),
108-
onKeyCenter: () => showAboutPopup({ ...items[currentIndex], lang, dir }),
108+
onKeyCenter: () => showAboutPopup({ ...items[currentIndex], mediaInfo, dir }),
109109
[dir === 'rtl' ? 'onKeyFixedArrowLeft' : 'onKeyFixedArrowRight']: onNextImage,
110110
[dir === 'rtl' ? 'onKeyFixedArrowRight' : 'onKeyFixedArrowLeft']: onPrevImage,
111111
onKeyBackspace: close
@@ -124,7 +124,7 @@ export const Gallery = ({ close, closeAll, items, startFileName, lang, dir }) =>
124124
)
125125
}
126126
<div class='img'>
127-
<img onLoad={onImageLoad} src={items[currentIndex].thumbnail} />
127+
<img onLoad={onImageLoad} src={mediaInfo && mediaInfo.source} />
128128
</div>
129129
</div>
130130
)

src/hooks/useArticleMediaInfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { useState, useEffect } from 'preact/hooks'
22
import { getArticleMediaInfo } from 'api'
33

4-
export const useArticleMediaInfo = (lang, title, fromCommon) => {
4+
export const useArticleMediaInfo = (lang, title, fromCommon, currentIndex) => {
55
const [media, setMedia] = useState()
66

77
useEffect(() => {
88
const [promise, abort] = getArticleMediaInfo(lang, title, fromCommon)
99
promise.then(setMedia)
1010
return abort
11-
}, [])
11+
}, [currentIndex])
1212

1313
return media
1414
}

0 commit comments

Comments
 (0)