Skip to content

Commit 64bb265

Browse files
authored
Merge pull request #71 from medyo/develop
V 1.11.0
2 parents e8ce2e0 + e2e6286 commit 64bb265

6 files changed

Lines changed: 89 additions & 38 deletions

File tree

src/App.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,9 @@ Producthunt item
671671
.navigationItem.active {
672672
background-color: #3c4f651f;
673673
}
674-
674+
.changelogTooltip {
675+
overflow-x: hidden !important;
676+
}
675677
.changelogButton {
676678
width: 20px;
677679
height: 20px;

src/Constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ export const SUPPORTED_SEARCH_ENGINES = [
134134
label: 'Yandex',
135135
url: 'https://yandex.ru/search/?text=',
136136
},
137+
{
138+
label: 'Startpage',
139+
url: 'https://www.startpage.com/sp/search?query=',
140+
},
137141
]
138142
export const LS_PREFERENCES_KEY = 'hackerTabPrefs'
139143
export const LS_ANALYTICS_ID_KEY = 'hackerTabAnalyticsId'

src/cards/HNCard.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,44 @@ const StoryItem = ({ item, index, analyticsTag }) => {
2020

2121
return (
2222
<CardItemWithActions
23-
source={"hackernews"}
23+
source={'hackernews'}
2424
index={index}
2525
item={item}
2626
key={index}
2727
cardItem={
2828
<>
2929
<p className="rowTitle">
3030
<CardLink link={item.url} analyticsSource={analyticsTag}>
31-
{ listingMode === "compact" &&
32-
<div className="counterWrapper">
33-
<VscTriangleUp/>
34-
<span className="value">{item.score}</span>
35-
</div>
36-
}
37-
38-
<div className="subTitle">
39-
{item.title}
40-
</div>
31+
{listingMode === 'compact' && (
32+
<span className="counterWrapper">
33+
<VscTriangleUp />
34+
<span className="value">{item.score}</span>
35+
</span>
36+
)}
37+
38+
<span className="subTitle">{item.title}</span>
4139
</CardLink>
4240
</p>
43-
{listingMode === "normal" && (
41+
{listingMode === 'normal' && (
4442
<div className="rowDetails">
4543
<span className="rowItem hnRowItem">
4644
<GoPrimitiveDot className="rowItemIcon" /> {item.score} points
4745
</span>
48-
<span
49-
className="rowItem"
50-
title={new Date(item.time * 1000).toUTCString()}
51-
>
52-
<MdAccessTime className="rowItemIcon" />{" "}
53-
{format(new Date(item.time * 1000))}
46+
<span className="rowItem" title={new Date(item.time * 1000).toUTCString()}>
47+
<MdAccessTime className="rowItemIcon" /> {format(new Date(item.time * 1000))}
5448
</span>
5549
<ClickableItem
5650
link={`https://news.ycombinator.com/item?id=${item.id}`}
5751
className="rowItem rowItemClickable"
58-
analyticsSource={analyticsTag}
59-
>
60-
<BiCommentDetail className="rowItemIcon" /> {item.descendants}{" "}
61-
comments
52+
analyticsSource={analyticsTag}>
53+
<BiCommentDetail className="rowItemIcon" /> {item.descendants} comments
6254
</ClickableItem>
6355
</div>
6456
)}
6557
</>
6658
}
6759
/>
68-
);
60+
)
6961
}
7062

7163

src/cards/ReposCard.js

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,46 +63,61 @@ const TAGS_MENU_ID = "tags-menu";
6363
const DATE_RANGE_MENU_ID = "date-range-id"
6464

6565
function ReposCard({ analyticsTag, icon, withAds }) {
66+
67+
const getInitialSelectedTag = () => {
68+
const githubCardSettings = cardsSettings && cardsSettings.repos ? cardsSettings.repos : null
69+
if (githubCardSettings && githubCardSettings.language) {
70+
return getTags().find((t) => t.label == githubCardSettings.language)
71+
}
72+
73+
return getTags().find((t) => t.githubValues != null)
74+
}
75+
76+
const getInitialDateRange = () => {
77+
const githubCardSettings = cardsSettings && cardsSettings.repos ? cardsSettings.repos : null
78+
if (githubCardSettings && githubCardSettings.dateRange) {
79+
return githubCardSettings.dateRange
80+
}
81+
return 'daily'
82+
}
83+
6684
const globalTag = { value: 'global', label: 'All trending', githubValues: ['global'] }
85+
const myLangsTag = { value: 'myLangs', label: 'My Languages', githubValues: ['myLangs'] }
6786

6887
const preferences = useContext(PreferencesContext)
6988

70-
const { userSelectedTags = [], userBookmarks = [] } = preferences
89+
const { userSelectedTags = [], dispatcher, cardsSettings } = preferences
7190

72-
const getTags = () => [...userSelectedTags, globalTag]
91+
const getTags = () => [...userSelectedTags, globalTag, myLangsTag]
7392

7493
const { show: showMenu } = useContextMenu()
7594

76-
const [selectedTag, setSelectedTag] = useState(getTags()[0])
77-
const [since, setSince] = useState('daily')
95+
const [selectedTag, setSelectedTag] = useState(getInitialSelectedTag())
96+
const [since, setSince] = useState(getInitialDateRange())
7897
const [refresh, setRefresh] = useState(true)
98+
const [repos, setRepos] = useState({})
7999
const dateRangeMapper = {
80100
daily: 'the day',
81101
weekly: 'the week',
82102
monthly: 'the month',
83103
}
84104

85-
const getInitialSelectedTag = () => {
86-
return getTags().find((t) => t.githubValues != null)
87-
}
88-
89-
useEffect(() => {
90-
setSelectedTag(getInitialSelectedTag())
91-
}, [])
92-
93105
useEffect(() => {
94106
setSelectedTag(getInitialSelectedTag())
107+
setRepos({})
95108
setRefresh(!refresh)
96109
}, [userSelectedTags])
97110

98111
const onSelectedTagChange = (selTag) => {
99112
setSelectedTag(selTag)
100113
trackReposLanguageChange(selTag.value)
114+
dispatcher({ type: 'setCardSettings', value: { card: 'repos', language: selTag.label } })
101115
setRefresh(!refresh)
102116
}
103117

104118
const onDateRangeChange = (dateRange) => {
105119
setSince(dateRange)
120+
dispatcher({ type: 'setCardSettings', value: { card: 'repos', dateRange } })
106121
trackReposDateRangeChange(dateRange)
107122
setRefresh(!refresh)
108123
}
@@ -123,7 +138,34 @@ function ReposCard({ analyticsTag, icon, withAds }) {
123138
throw Error(`Github Trending does not support ${selectedTag.label}.`)
124139
}
125140

126-
const data = await githubApi.getTrending(selectedTag.githubValues[0], since)
141+
const tagValue = selectedTag.githubValues[0]
142+
const key = `${tagValue}-${since}`
143+
144+
if (repos[key]) {
145+
return repos[key]
146+
}
147+
148+
if (tagValue == myLangsTag.githubValues[0]) {
149+
const promises = userSelectedTags.map(
150+
t => !t.githubValues ? false : githubApi.getTrending(t.githubValues[0], since)
151+
)
152+
let values = await Promise.all(promises)
153+
const nbrTags = values.length
154+
let minLength = Math.min(...values.map(v => v.length))
155+
const data = []
156+
for (let index = 0; index < minLength; index++) {
157+
for (let i = 0; i < nbrTags; i++) {
158+
data.push(values[i][index])
159+
}
160+
}
161+
162+
setRepos({ ...repos, [key]: data })
163+
return data
164+
165+
}
166+
167+
const data = await githubApi.getTrending(tagValue, since)
168+
setRepos({ ...repos, [key]: data })
127169
return data
128170
}
129171

@@ -165,7 +207,7 @@ function ReposCard({ analyticsTag, icon, withAds }) {
165207
<Menu id={TAGS_MENU_ID} animation={animation.fade}>
166208
{getTags().map((tag) => {
167209
return (
168-
<Item key={tag} onClick={() => onSelectedTagChange(tag)}>
210+
<Item key={tag.value} onClick={() => onSelectedTagChange(tag)}>
169211
{tag.label}
170212
</Item>
171213
)

src/components/Changelog.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function Changelog({}) {
8282
scrollHide={false}
8383
afterShow={afterShow}
8484
place="bottom"
85+
className="changelogTooltip scrollable"
8586
globalEventOff="click">
8687
{loading ? (
8788
<div className="tooltipLoading">

src/preferences/AppReducer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ const AppReducer = (state, action) => {
5454
case 'setSearchEngine':
5555
newState = { ...newState, searchEngine: value.label }
5656
break
57+
case 'setCardSettings':
58+
newState = {
59+
...newState,
60+
cardsSettings: {
61+
...newState?.cardsSettings,
62+
[value.card]: { ...newState?.cardsSettings?.[value.card], ...value },
63+
},
64+
}
65+
break
5766
default:
5867
throw new Error()
5968
}
@@ -67,6 +76,7 @@ const AppReducer = (state, action) => {
6776
changelogMeta: newState.changelogMeta,
6877
userBookmarks: newState.userBookmarks,
6978
searchEngine: newState.searchEngine,
79+
cardsSettings: newState.cardsSettings,
7080
}
7181
AppStorage.setItem(LS_PREFERENCES_KEY, storageData)
7282
return newState

0 commit comments

Comments
 (0)