many new
This commit is contained in:
+2
-3
@@ -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 };
|
||||
+5
-6
@@ -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 }
|
||||
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}`);
|
||||
@@ -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<Props, State> {
|
||||
|
||||
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 = (
|
||||
<NotificationMessage level={"success"}>
|
||||
Успешно!
|
||||
</NotificationMessage>
|
||||
)
|
||||
addNotification(notification)
|
||||
});
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<State>) {
|
||||
@@ -78,6 +91,18 @@ class APModifyPost extends React.Component<Props, State> {
|
||||
this.setState({ post });
|
||||
}
|
||||
|
||||
deletePost = () => {
|
||||
const { postId, setPopout } = this.props;
|
||||
|
||||
const popout = (
|
||||
<ConfirmPopout onConfirm={() => deletePost(postId)}>
|
||||
Вы уверены?
|
||||
</ConfirmPopout>
|
||||
);
|
||||
|
||||
setPopout(popout);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { post, title, previewShort, previewFull } = this.state;
|
||||
|
||||
@@ -108,8 +133,8 @@ class APModifyPost extends React.Component<Props, State> {
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button>Сохранить</Button>
|
||||
<Button type={"button"} style={{ color: 'var(--error) '}}>Удалить</Button>
|
||||
<Button style={{ marginRight: '1rem' }}>Сохранить</Button>
|
||||
<Button type={"button"} style={{ color: 'var(--error-bg-color)'}} onClick={this.deletePost}>Удалить</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Group>
|
||||
@@ -117,4 +142,9 @@ class APModifyPost extends React.Component<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
export default APModifyPost;
|
||||
export default connect(null,
|
||||
dispatch => ({
|
||||
setPopout: (modal: React.ReactNode | null) => dispatch(setModal(modal)),
|
||||
addNotification: (notification: React.ReactNode) => dispatch(addNotification(notification))
|
||||
})
|
||||
)(APModifyPost);
|
||||
@@ -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<Props, State> {
|
||||
|
||||
return (
|
||||
<Group title={'Новости'}>
|
||||
<Button>Добавить новость</Button>
|
||||
{news.map(post => (
|
||||
<Link to={`${path}/${post.id}`} key={post.id}>
|
||||
<div style={{ display: "flex" }}>
|
||||
|
||||
@@ -55,7 +55,7 @@ class App extends React.Component<Props, State> {
|
||||
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user