Skip to content

Commit eb2de6d

Browse files
authored
Merge pull request #40 from voscarmv/loadAllLabelsFromSelectedLanguageOnly
Load All labels from selected language only
2 parents 0fd3777 + 84a379e commit eb2de6d

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/actions/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,39 @@ export const rawLabels = async (repos, dispatch) => {
7676
return rawdata;
7777
};
7878

79-
export const getLabels = (repos) => async (dispatch, getState) => {
79+
export const getLabels = (repos, language) => async (dispatch, getState) => {
8080
if (repos === undefined) return;
8181
dispatch({
8282
type: label.GET_LABELS_REQUEST,
8383
loadingPercentage: 0
8484
});
8585
try {
8686
// get date for list of labels, saved in browser's local strorage
87-
const localDataDate = localStorage.getItem('date');
87+
const localStorageObj = JSON.parse(localStorage.getItem(language + '_labelslist'));
88+
const localDataDate = localStorageObj?.date;
8889
let today = new Date();
8990
const dd = String(today.getDate()).padStart(2, '0');
9091
const mm = String(today.getMonth() + 1).padStart(2, '0');
9192
const yyyy = today.getFullYear();
9293
today = (mm + dd + yyyy).toString();
9394
// if date, when data was saved, is more than a day, clear it.
9495
if (localDataDate !== today) {
95-
localStorage.removeItem('labelslist');
96-
localStorage.removeItem('date');
96+
localStorage.removeItem(language + '_labelslist');
9797
}
9898

9999
// get label list from local storage
100-
const localData = localStorage.getItem('labelslist');
100+
const localData = localStorageObj?.labels;
101101
let data = '';
102-
if (localData) data = JSON.parse(localData);
102+
if (localData) data = localData;
103103
else data = await rawLabels(repos, dispatch); // if label list is not present in local storage than get fresh list of labels.
104104
dispatch({
105105
type: label.GET_LABELS_SUCCESS,
106106
payload: data
107107
});
108-
localStorage.setItem('labelslist', JSON.stringify(getState().labelsStore.labelslist));
109-
localStorage.setItem('date', today);
108+
localStorage.setItem(
109+
language + '_labelslist',
110+
JSON.stringify({ language: language, date: today, labels: getState().labelsStore.labelslist })
111+
);
110112
} catch (e) {
111113
console.error(`getlabels error ${e.message}`);
112114
dispatch({

src/components/Home.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const Home = () => {
127127
</Select>
128128
<Button
129129
variant={`${darkMode ? 'light' : 'dark'} button button-green w-full h-15`}
130-
disabled={loading || (menu === 2 && label === 'All')}
130+
disabled={loading}
131131
onClick={() => findIssues()}>
132132
{label === 'All' ? 'Load Labels' : 'Find Issues'}
133133
</Button>

src/components/SearchEngine.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ import { getLabels } from '../actions';
55
export const SearchEngine = () => {
66
const dispatch = useDispatch();
77
const repos = useSelector((state) => state.reposStore);
8+
const { language } = useSelector((state) => state.issuesStore);
89

910
useEffect(
1011
() => {
11-
dispatch(getLabels(repos.reposlist));
12+
const filteredRepolist = repos.reposlist.filter(
13+
(repo) =>
14+
repo.language.trim() === language ||
15+
repo.topics?.trim().toLowerCase().split(' ').includes(language.toLowerCase())
16+
);
17+
dispatch(getLabels(filteredRepolist, language));
1218
},
1319
// eslint-disable-next-line
14-
[repos]
20+
[repos, language]
1521
);
1622
};

0 commit comments

Comments
 (0)