import {LayoutProps} from "./Layout.props"; import styles from "./Layout.module.css" import styles_post from "./Post/Post.module.css" import {Post} from "./Post/Post"; import cn from "classnames"; import {Component, FunctionComponent} from "react"; import {useContext, useEffect, useState} from "react"; import Cookie from 'js-cookie'; import axios from "axios"; import {Post_int, Blog_int} from "../interfaces/blog_interface" import blog from "../pages/blog"; import {Button, Form, Input} from "reactstrap"; const Layout = ({ children }: LayoutProps): JSX.Element => { const [data, setData] = useState(<>); const [file, setFile] = useState() function handleChange(event) { setFile(event.target.files[0]) } useEffect(() => { //get_posts() get_blog() }, []); function get_blog(){ if (localStorage.getItem("blog_url") == null){ axios.get('http://10.50.20.5:13377/api/blog', {withCredentials: true}).then(response => { localStorage.setItem('blog_url', response.data.url); get_posts(response.data.url) }) } else{ get_posts(localStorage.getItem("blog_url")) } } function get_posts(blog_url: string){ axios.get('http://10.50.20.5:13377/api/blog/'.concat(blog_url), {withCredentials: true}).then(response => { let jsonDataPosts = JSON.parse(JSON.stringify(response.data.posts)) let mydata: JSX.Element jsonDataPosts.forEach((post: Post_int) => { mydata = ( <> {mydata} ) setData(mydata) } ) }) } function sign_out(){ localStorage.removeItem("blog_url") Cookie.remove('sessions') window.location.href = "/auth" } function create_post(){ axios.post("http://10.50.20.5:13377/api/blog/".concat(localStorage.getItem("blog_url")).concat("/").concat("create_post"), {"title": "test", "body":"test"}, {withCredentials: true}).then( response => {window.location.reload()}) } function blog_list(){ axios.get("http://10.50.20.5:13377/api/blogs", {withCredentials: true}).then( response => { let jsonDataBlogs = JSON.parse(JSON.stringify(response.data)) let mydata: JSX.Element jsonDataBlogs.forEach((post: Blog_int) => { mydata = ( <>
post.url
post.is_private
{mydata} ) setData(mydata) } ) }) } function upload_file(){ } function handleSubmit() { event.preventDefault() const url = 'http://10.50.20.5:13377/file/upload?path=file_storage'; const formData = new FormData(); formData.append('file', file); const config = { withCredentials: true, headers: { 'content-type': 'multipart/form-data', }, }; axios.post(url, formData, config).then((response) => { console.log(response.data); }); } function read_post(){ let num_post = prompt("Input id your post") axios.get("http://10.50.20.5:13377/api/blog/".concat(localStorage.getItem("blog_url")).concat("/").concat("post").concat("/").concat(num_post), {withCredentials: true}).then( response => { let jsonDataBlogs = JSON.parse(JSON.stringify(response.data)) let mydata: JSX.Element jsonDataBlogs.forEach((post: Blog_int) => { mydata = ( <>
{mydata}
) setData(mydata) } ) }) } return(

Upload

Test Header

{children}
); }; export const withLayout = >(Component: FunctionComponent) => { return function withLayoutComponent(props: T): JSX.Element { return( ); }; };