Skip to content

Commit

Permalink
add src
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatyana-js committed May 30, 2024
1 parent f3d947a commit 6bb2ed3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1 class="display-3 mb-0">RSS агрегатор</h1>
<div class="container-xl">
<div class="text-center">
created by
<a href="https://github.com/Tatyana-js" target="_blank">Tatyana</a>
<a href="https://github.com/Tatyana-js" rel="noopener" target="_blank">Tatyana</a>
</div>
</div>
</footer>
Expand Down
6 changes: 3 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import i18next from 'i18next';
import * as yup from 'yup';
import axios from 'axios';
import validate, { proxyObj } from './utils.js';
import validate, { createLink } from './utils.js';
import watch from './view.js';
import resources from './locales/index.js';

Expand All @@ -25,7 +25,7 @@ const state = {
isValid: false,
},
loadingProcess: {
status: 'waiting',
status: 'waiting', // 'sending'
error: '',
},
posts: [],
Expand Down Expand Up @@ -64,7 +64,7 @@ export default () => {
watchedState.loadingProcess.state = 'sending';

validate(urlTarget, urlFeeds)
.then(({ url }) => axios.get(proxyObj(url)))
.then(({ url }) => axios.get(createLink(url)))
.catch((error) => {
watchedState.form.isValid = false;
watchedState.form.errors.push(error);
Expand Down
13 changes: 0 additions & 13 deletions src/frontend-project-11.code-workspace

This file was deleted.

7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ const validate = (url, urlFeeds) => {
return schema.validate({ url });
};

export const proxyObj = (url) => url;
export const createLink = (url) => {
const originsUrl = new URL('https://allorigins.hexlet.app/get?');
originsUrl.searchParams.set('disableCache', 'true');
originsUrl.searchParams.set('url', url);
return originsUrl;
};
export default validate;
3 changes: 2 additions & 1 deletion src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ export default (elements, i18n, state) => {
});
};
const watchedState = onChange(state, (path) => {
const { errorElement } = elements;
const { errorElement, input } = elements;
switch (path) {
case 'form.isValid':
renderValid();
break;
case 'form.errors':
input.classList.add('is-invalid');
errorElement.classList.remove('text-success');
errorElement.classList.add('text-danger');
errorElement.textContent = t('errors.invalidUrl');
Expand Down

0 comments on commit 6bb2ed3

Please sign in to comment.