diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..b58b603f
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..d932b94c
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..35eb1ddf
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/webdev-cw-instapro.iml b/.idea/webdev-cw-instapro.iml
new file mode 100644
index 00000000..24643cc3
--- /dev/null
+++ b/.idea/webdev-cw-instapro.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..6b665aaa
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "liveServer.settings.port": 5501
+}
diff --git a/README.md b/README.md
index 216dfc2a..e8af705c 100644
--- a/README.md
+++ b/README.md
@@ -4,12 +4,12 @@ MVP аналога популярной соц. сети для обмена ф
## Ссылка на приложение:
-https::
+https://aleks3y1.github.io/webdev-cw-instapro/
## Первоначальная оценка
-ХХХХ часов
+5 часов.
## Фактически затраченное время
-YYYY часов
+12 часов.
diff --git a/api.js b/api.js
index 8997c44d..346a1e71 100644
--- a/api.js
+++ b/api.js
@@ -1,8 +1,11 @@
// Замени на свой, чтобы получить независимый от других набор данных.
// "боевая" версия инстапро лежит в ключе prod
+import { el } from "date-fns/locale";
+import { getToken, user } from "./index.js";
+
const personalKey = "prod";
const baseHost = "https://webdev-hw-api.vercel.app";
-const postsHost = `${baseHost}/api/v1/${personalKey}/instapro`;
+export const postsHost = `${baseHost}/api/v1/${personalKey}/instapro`;
export function getPosts({ token }) {
return fetch(postsHost, {
@@ -25,20 +28,24 @@ export function getPosts({ token }) {
// https://github.com/GlebkaF/webdev-hw-api/blob/main/pages/api/user/README.md#%D0%B0%D0%B2%D1%82%D0%BE%D1%80%D0%B8%D0%B7%D0%BE%D0%B2%D0%B0%D1%82%D1%8C%D1%81%D1%8F
export function registerUser({ login, password, name, imageUrl }) {
- return fetch(baseHost + "/api/user", {
- method: "POST",
- body: JSON.stringify({
- login,
- password,
- name,
- imageUrl,
- }),
- }).then((response) => {
- if (response.status === 400) {
- throw new Error("Такой пользователь уже существует");
- }
- return response.json();
- });
+ if (login.length > 0 && password.length > 0 && name.length > 0) {
+ return fetch(baseHost + "/api/user", {
+ method: "POST",
+ body: JSON.stringify({
+ login,
+ password,
+ name,
+ imageUrl,
+ }),
+ }).then((response) => {
+ if (response.status === 400) {
+ throw new Error("Такой пользователь уже существует");
+ }
+ return response.json();
+ });
+ } else {
+ alert("Заполните все поля!");
+ }
}
export function loginUser({ login, password }) {
@@ -68,3 +75,78 @@ export function uploadImage({ file }) {
return response.json();
});
}
+
+export function onAddPostClick({ description, imageUrl, token }) {
+ if (description.length > 0) {
+ return fetch(postsHost, {
+ method: "POST",
+ headers: {
+ Authorization: token,
+ },
+ body: JSON.stringify({
+ description,
+ imageUrl,
+ isLiked: false,
+ }),
+ }).then((response) => {
+ if (response.status === 401) {
+ throw new Error("Нет авторизации");
+ }
+ if (response.status === 400) {
+ throw new Error(
+ "Ошибка при добавлении поста. Проверьте фото и описание к нему!"
+ );
+ }
+ return response.json();
+ });
+ } else {
+ alert("Поле с описание не должно быть пустым!");
+ }
+}
+
+export function getUserComments({ user, token }) {
+ return fetch(`${postsHost}/user-posts/${user}`, {
+ method: "GET",
+ headers: {
+ Authorization: token,
+ },
+ })
+ .then((response) => {
+ if (response.status === 401) {
+ throw new Error("Нет авторизации");
+ }
+
+ return response.json();
+ })
+ .then((response) => {
+ return response.posts;
+ });
+}
+
+export function likesApi({ likeId, token, activityLike }) {
+ if (navigator.onLine) {
+ return fetch(
+ !activityLike
+ ? postsHost + "/" + likeId + "/like"
+ : postsHost + "/" + likeId + "/dislike",
+ {
+ method: "POST",
+ headers: {
+ Authorization: token,
+ },
+ }
+ )
+ .then((response) => {
+ if (response.status === 401) {
+ throw new Error("Нет авторизации");
+ }
+
+ return response.json();
+ })
+ .then((data) => {
+ return data.post;
+ });
+ } else {
+ alert('Отсутствует подключение к интернету.');
+ }
+}
diff --git a/components/add-post-page-component.js b/components/add-post-page-component.js
index 59554d86..a17f3478 100644
--- a/components/add-post-page-component.js
+++ b/components/add-post-page-component.js
@@ -1,21 +1,66 @@
-export function renderAddPostPageComponent({ appEl, onAddPostClick }) {
+import { renderHeaderComponent } from "./header-component.js";
+import { renderUploadImageComponent } from "./upload-image-component.js";
+import { onAddPostClick } from "../api.js";
+import { getToken, goToPage } from "../index.js";
+import { POSTS_PAGE } from "../routes.js";
+import { isUploadImage } from "./header-component.js";
+
+let imageUrl = "";
+
+export function renderAddPostPageComponent({ appEl }) {
const render = () => {
// TODO: Реализовать страницу добавления поста
const appHtml = `
- Cтраница добавления поста
-
-
+