From 4e465ce39f912fb884680904aa16a9379c71de44 Mon Sep 17 00:00:00 2001 From: Nix13 Date: Wed, 24 Jun 2020 21:25:01 +0300 Subject: [PATCH] many new --- src/api/api.ts | 5 ++- src/api/news.ts | 11 +++--- src/pages/AdminPanel/News/APModifyPost.tsx | 42 ++++++++++++++++++---- src/pages/AdminPanel/News/APNews.tsx | 2 ++ src/pages/App/App.tsx | 2 +- 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/api/api.ts b/src/api/api.ts index 56ad08e..c94b5f8 100755 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -1,7 +1,6 @@ - const baseUrl = process.env.NODE_ENV === "development" ? 'http://localhost:8080/v1' : 'https://api.unmei.nix13.pw/v1'; -export const response = async (url: string, method: string, body?: string | FormData) => { +const response = async (url: string, method: string, body?: string | FormData) => { let bUrl = baseUrl; if(baseUrl.endsWith('/')) bUrl = bUrl.slice(0, baseUrl.length-1); if(url.startsWith('/')) url = url.slice(1, baseUrl.length); @@ -40,6 +39,6 @@ const TranslateStatus: { [id: string]: string } = { }; export const getVersion = () => get('version'); -export const version = '0.9'; +export const version = '0.10'; export { get, post, put, del, TranslateStatus }; \ No newline at end of file diff --git a/src/api/news.ts b/src/api/news.ts index 5f643bd..168bef3 100755 --- a/src/api/news.ts +++ b/src/api/news.ts @@ -1,8 +1,7 @@ -import {get, put} from './api'; +import {del, get, put} from './api'; -const fetchNews = () => get('news'); +export const fetchNews = () => get('news'); -const fetchPost = (id: number) => get(`news/${id}`); -const updatePost = (post: PostType) => put(`news/${post.id}`, post); - -export { fetchNews, fetchPost, updatePost } \ No newline at end of file +export const fetchPost = (id: number) => get(`news/${id}`); +export const updatePost = (post: PostType) => put(`news/${post.id}`, post); +export const deletePost = (id: number) => del(`news/${id}`); \ No newline at end of file diff --git a/src/pages/AdminPanel/News/APModifyPost.tsx b/src/pages/AdminPanel/News/APModifyPost.tsx index d4cd602..6174ff1 100755 --- a/src/pages/AdminPanel/News/APModifyPost.tsx +++ b/src/pages/AdminPanel/News/APModifyPost.tsx @@ -1,7 +1,7 @@ import React, {ChangeEvent, FormEvent} from "react"; import Group from "../../../ui/Group/Group"; import NotFoundError from "../../NotFoundError"; -import {fetchPost, updatePost} from "../../../api/news"; +import {deletePost, fetchPost, updatePost} from "../../../api/news"; import './APNews.sass'; import '../../../ui/TextField/TextField.sass' import Input from "../../../ui/Input/Input"; @@ -10,10 +10,15 @@ import BBEditor from "../../../ui/BBEditor/BBEditor"; // @ts-ignore import parser from 'bbcode-to-react'; import Title from "../../../ui/Title/Title"; +import {connect} from "react-redux"; +import {addNotification, setModal} from "../../../store/actions"; +import ConfirmPopout from "../../../ui/ConfirmPopout/ConfirmPopout"; +import NotificationMessage from "../../../ui/Notifications/NotificationMessage"; type Props = { postId: number - //addNotification: (notification: React.ReactNode) => void + setPopout: (modal: React.ReactNode | null) => void + addNotification: (notification: React.ReactNode) => void }; type State = { @@ -49,8 +54,16 @@ class APModifyPost extends React.Component { post.short_post = this.shortPost.current.value; post.full_post = this.fullPost.current.value; + const { addNotification } = this.props; - await updatePost(post); + updatePost(post).then(() => { + const notification = ( + + Успешно! + + ) + addNotification(notification) + }); } componentDidUpdate(prevProps: Readonly, prevState: Readonly) { @@ -78,6 +91,18 @@ class APModifyPost extends React.Component { this.setState({ post }); } + deletePost = () => { + const { postId, setPopout } = this.props; + + const popout = ( + deletePost(postId)}> + Вы уверены? + + ); + + setPopout(popout); + } + render() { const { post, title, previewShort, previewFull } = this.state; @@ -108,8 +133,8 @@ class APModifyPost extends React.Component {
- - + +
@@ -117,4 +142,9 @@ class APModifyPost extends React.Component { } } -export default APModifyPost; \ No newline at end of file +export default connect(null, + dispatch => ({ + setPopout: (modal: React.ReactNode | null) => dispatch(setModal(modal)), + addNotification: (notification: React.ReactNode) => dispatch(addNotification(notification)) + }) +)(APModifyPost); \ No newline at end of file diff --git a/src/pages/AdminPanel/News/APNews.tsx b/src/pages/AdminPanel/News/APNews.tsx index 8688e13..19acd88 100755 --- a/src/pages/AdminPanel/News/APNews.tsx +++ b/src/pages/AdminPanel/News/APNews.tsx @@ -2,6 +2,7 @@ import React from "react"; import {fetchNews} from "../../../api/news"; import Group from "../../../ui/Group/Group"; import {Link} from "react-router-dom"; +import Button from "../../../ui/Button/Button"; type Props = { path: string @@ -26,6 +27,7 @@ class APNews extends React.Component { return ( + {news.map(post => (
diff --git a/src/pages/App/App.tsx b/src/pages/App/App.tsx index f611320..2b4d3ab 100755 --- a/src/pages/App/App.tsx +++ b/src/pages/App/App.tsx @@ -55,7 +55,7 @@ class App extends React.Component { getVersion().then(res => { if(version !== res.version) { - console.debug(`Current back-end version: ${res.version}. Clearing cache`); + console.log(`Current back-end version: ${res.version}. Clearing cache`); caches.keys().then(names => { names.forEach(name => caches.delete(name).catch(console.error))