Skip to content

Commit

Permalink
new functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
neandreev committed Aug 1, 2021
1 parent fb0549b commit a071419
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 63 deletions.
66 changes: 34 additions & 32 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,45 @@
<title>Webpack Package</title>
</head>
<body>
<div id="modal" class="modal fade" aria-hidden="true" tabindex="1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<a role="button" class="btn btn-primary">
</a>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
</button>
<div class="container-sm">
<div id="modal" class="modal fade" aria-hidden="true" tabindex="1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<a role="button" class="btn btn-primary">
</a>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
</button>
</div>
</div>
</div>
</div>
</div>
<div id="form">
<form class="md-3">
<div class='container-sm'>
<div class="row">
<div class="col-8">
<input name='url' type='href' class='form-control' id='rssHref'>
</div>
<div class="col-4">
<button type='submit' class='btn btn-primary'>Add RSS</button>
<div id="form">
<form class="md-3">
<div class='container-sm'>
<div class="row">
<div class="col-8">
<input name='url' type='href' class='form-control' id='rssHref'>
</div>
<div class="col-4">
<button type='submit' class='btn btn-primary'>Add RSS</button>
</div>
</div>
</div>
</div>
</form>
<p class='feedback small'></p>
</div>
<div id="posts_feeds">
<div id="feeds"></div>
<div id="posts"></div>
</form>
<p class='feedback small'></p>
</div>
<div id="posts_feeds">
<div id="feeds"></div>
<div id="posts"></div>
</div>
</div>
</body>
</html>
7 changes: 4 additions & 3 deletions src/handlers/formSubmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export default (data) => (e) => {
const id = _.uniqueId();
document.querySelector('form').reset();

request(id, url);
request(id, url, true);
})
.catch(({ message }) => {
.catch((e) => {
console.dir(e);
watchedState.uiState = {
status: 'invalid',
feedbackKey: message.key,
feedbackKey: e.message.key,
};
});
};
55 changes: 27 additions & 28 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default () => {
});

yup.setLocale({
mixed: {
required: ({ url }) => ({ key: 'feedback.empty', values: { url } }),
},
string: {
url: ({ url }) => ({ key: 'feedback.invalidUrl', values: { url } }),
},
Expand All @@ -51,6 +54,7 @@ export default () => {
button.textContent = i18next.t('buttons.form.add');

const watchedState = onChange(state, (path, value) => {
console.log(state);
if (path === 'uiState') {
switch (value.status) {
case 'pending':
Expand Down Expand Up @@ -104,7 +108,7 @@ export default () => {
console.log(state);
});

const request = (id, url) => {
const request = (id, url, makeStatus) => {
axios
.get(getAllOriginsUrl(url))
.then((response) => {
Expand All @@ -116,38 +120,33 @@ export default () => {
return;
}

const makeRequest = () => {
const parsedChannel = parse(response.data);
const { items, title, description } = parsedChannel;
const feed = {
id, url, title, description,
};
const posts = items
.map((item) => ({ ...item, feedId: id }));
console.log(posts);
const newPosts = _.differenceBy(posts, state.posts, 'link');
console.log(newPosts);

watchedState.feeds = _.sortBy(_.uniqBy([
feed,
...state.feeds,
], 'url'), 'id');
watchedState.posts = _.uniqBy([
...newPosts,
...state.posts,
], 'link');

setTimeout(makeRequest, 5000);

console.log('tick');
const parsedChannel = parse(response.data);
const { items, title, description } = parsedChannel;
const feed = {
id, url, title, description,
};

makeRequest();
watchedState.uiState = { status: 'complete', feedbackKey: 'feedback.complete' };
const posts = items
.map((item) => ({ ...item, feedId: id }));
console.log(posts);
const newPosts = _.differenceBy(posts, state.posts, 'link');
console.log(newPosts);

watchedState.feeds = _.sortBy(_.uniqBy([
feed,
...state.feeds,
], 'url'), 'id').reverse();
watchedState.posts = _.uniqBy([
...newPosts,
...state.posts,
], 'link');

if (makeStatus) watchedState.uiState = { status: 'complete', feedbackKey: 'feedback.complete' };
})
.catch(() => {
watchedState.uiState = { status: 'networkError', feedbackKey: 'feedback.networkError' };
});

setTimeout(() => request(id, url), 5000);
};

const formSubmitData = { watchedState, request };
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default {
invalidUrl: 'This link isn\'t URL',
duplicateUrl: 'This RSS is already in list',
complete: 'RSS properly loaded',
networkError: 'Network error',
empty: 'The value shouldn\'t be empty',
},
buttons: {
modal: {
Expand Down
1 change: 1 addition & 0 deletions src/locales/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
duplicateUrl: 'RSS уже существует',
complete: 'RSS успешно загружен',
networkError: 'Ошибка сети',
empty: 'Не должно быть пустым',
},
buttons: {
modal: {
Expand Down

0 comments on commit a071419

Please sign in to comment.