Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.72 KB | None | 0 0
  1. import React , { Component } from 'react';
  2. import Logo from './Logo';
  3. import Socials from './Socials';
  4. import '../Styles/Blog.css';
  5. import search_img from '../media/search.png';
  6. import BlogPost from './BlogPost';
  7. import BlogPostMobile from './BlogPostMobile';
  8. import Search_img from '../media/mobile_search.png';
  9. import MobileExit from '../media/mobile_exit.png';
  10. import MobileBlogNav from './MobileBlogNav';
  11. import MobileNav from './MobileNav';
  12. import {Link} from 'react-router-dom';
  13.  
  14. import MetaTags from 'react-meta-tags';
  15. // import Calendar from 'react-calendar/dist/entry.nostyle'
  16. import * as d3 from "d3";
  17. import { withMobileDialog } from '@material-ui/core';
  18.  
  19. export default class extends Component {
  20.  
  21. constructor(props){
  22. super(props);
  23. this.state = {
  24. visibility: window.innerWidth >= 768 ? true : false,
  25. posts: [],
  26. animation_flag : false
  27. }
  28. }
  29.  
  30.  
  31. componentDidMount(){
  32. // fetch('/api/posts')
  33. // .then(res => res.json())
  34. // .then(posts => this.setState({posts}))
  35. // fetch('/api/seo/blog')
  36. // .then(res => res.json())
  37. // .then(meta => this.setState({meta: meta[0]}));
  38.  
  39.  
  40. let first_check = false;
  41. d3.select('.size_posts_custom_selector').style('height', '2vw');
  42.  
  43. d3.select('.size_posts_custom_selector')
  44. .on('click', function(){
  45. let flag = d3.select(this).attr('data-flag');
  46. console.log(flag);
  47. if(flag === 'false'){
  48. d3.select(this)
  49. .transition()
  50. .duration(300)
  51. .ease(d3.easeLinear)
  52. .style('height', '6vw')
  53. .on('end', function(){
  54. d3.select(this).attr('data-flag', 'true');
  55. });
  56. }else{
  57. d3.select(this)
  58. .transition()
  59. .duration(300)
  60. .ease(d3.easeLinear)
  61. .style('height', '2vw')
  62. .on('end', function(){
  63. d3.select(this).attr('data-flag', 'false');
  64. })
  65. }
  66. });
  67.  
  68.  
  69.  
  70. d3.selectAll('.size_posts_custom_selector span')
  71. .on('click', function(){
  72. if(first_check == false){
  73. d3.selectAll('.blog_post').style('height', '10vw');
  74. d3.selectAll('.blog_post_date').style('font-size', '5vw');
  75. d3.selectAll('.blog_post_title').style('line-height', '2vw')
  76. d3.selectAll('.blog_post_title h2').style('font-size', '2vw');;
  77. first_check = true;
  78. }
  79. let current_select = d3.select(this).attr('data-size');
  80. let first_select = d3.select('.size_posts_custom_selector span').attr('data-size');
  81. if(current_select != first_select){
  82. d3.select(this)
  83. .attr('data-size', first_select)
  84. .node().innerHTML = first_select;
  85. d3.select('.size_posts_custom_selector span')
  86. .attr('data-size', current_select)
  87. .node().innerHTML = current_select;
  88. let t = d3.transition().duration(300).ease(d3.easeLinear);
  89. switch(current_select){
  90. case 'Близько':
  91. d3.selectAll('.blog_post').transition(t).style('height', '10vw');
  92. d3.selectAll('.blog_post_date').transition(t).style('font-size', '5vw');
  93. d3.selectAll('.blog_post_title').transition(t).style('line-height', '2vw')
  94. d3.selectAll('.blog_post_title h2').transition(t).style('font-size', '2vw');
  95. break;
  96. case 'Ще ближче':
  97. d3.selectAll('.blog_post').transition(t).style('height', '15vw');
  98. d3.selectAll('.blog_post_date').transition(t).style('font-size', '10vw');
  99. d3.selectAll('.blog_post_title').transition(t).style('line-height', '3vw')
  100. d3.selectAll('.blog_post_title h2').transition(t).style('font-size', '3vw');
  101. break;
  102. case 'Дуже близько':
  103. d3.selectAll('.blog_post').transition(t).style('height', '20vw');
  104. d3.selectAll('.blog_post_date').transition(t).style('font-size', '13vw');
  105. d3.selectAll('.blog_post_title').transition(t).style('line-height', '3.5vw')
  106. d3.selectAll('.blog_post_title h2').transition(t).style('font-size', '3.5vw');
  107. break;
  108. }
  109. }
  110.  
  111. });
  112.  
  113. d3.selectAll('.post_type_selector h3')
  114. .on('click', function(){
  115.  
  116. let type = d3.select(this).attr('data');
  117. d3.selectAll('.post_type_selector h3')
  118. .each(function(){
  119. let e = d3.select(this);
  120. if(e.attr('data') == type){
  121. e.select('span').style('box-shadow', 'none');
  122. e.transition().duration(200).ease(d3.easeLinear)
  123. .style('background', '#FF5D00')
  124. .style('box-shadow', '0.2vw 0.5vw 0vw black')
  125. .style('color', 'black');
  126. }else{
  127. e.select('span').style('box-shadow', '0.2vw 0.5vw 0vw black');
  128. e.transition().duration(200).ease(d3.easeLinear)
  129. .style('background', 'none')
  130. .style('box-shadow', 'none')
  131. .style('color', 'white');
  132. }
  133. })
  134. });
  135.  
  136. if(window.innerWidth < 768){
  137.  
  138. d3.select('.mobile_blog_header h3').style('top', '0vw');
  139. d3.select('.m_search_input').style('bottom', '0vw');
  140. d3.select('.mobile_blog_header img')
  141. .on('click', function(){
  142. let search = d3.select(this).attr('data-search');
  143. console.log(search);
  144. if(search === 'false'){
  145. d3.select('.mobile_blog_header h3')
  146. .transition().duration(300).ease(d3.easeLinear)
  147. .style('top', '-15vw');
  148. d3.select('.m_search_input')
  149. .transition().duration(300).ease(d3.easeLinear)
  150. .style('bottom', '15vw');
  151. d3.select(this).attr('data-search', true);
  152. } else{
  153. d3.select('.mobile_blog_header h3')
  154. .transition().duration(300).ease(d3.easeLinear)
  155. .style('top', '0vw');
  156. d3.select('.m_search_input')
  157. .transition().duration(300).ease(d3.easeLinear)
  158. .style('bottom', '0vw');
  159. d3.select(this).attr('data-search', false);
  160. }
  161. });
  162.  
  163. function setSizes(){
  164. let window = {
  165. top: d3.select('.mobile_blog_content').node().getBoundingClientRect().top,
  166. bottom: d3.select('.mobile_blog_content').node().getBoundingClientRect().bottom
  167. }
  168. let center = window.bottom - (window.bottom - window.top)/2;
  169. let height_section = (window.bottom - window.top)/5;
  170. let scopes = {
  171. section_1: {
  172. top: window.top,
  173. bottom: window.top + height_section
  174. },
  175. section_2: {
  176. top: window.top + height_section,
  177. bottom: window.top + height_section*2
  178. },
  179. section_3: {
  180. top: window.top + height_section*2,
  181. bottom: window.top + height_section*3
  182. },
  183. section_4: {
  184. top: window.top + height_section*3,
  185. bottom: window.top + height_section*4
  186. }
  187. }
  188. return {window, center, scopes}
  189. }
  190.  
  191. scrollAnimation();
  192. d3.select('.mobile_blog_content')
  193. .on('scroll', scrollAnimation);
  194.  
  195. function postTransform(e, w, s_1, s_2){
  196. e
  197. .style('width', `${w}vw`);
  198. e.select('.mobile_blog_post_date')
  199. .style('font-size', `${s_1}vw`);
  200. e.select('h3')
  201. .style('font-size', `${s_2}vw`);
  202. e.select('h2')
  203. .style('line-height', `${s_1}vw`)
  204. .style('font-size', `${s_1}vw`);
  205. }
  206.  
  207. function getOffset(el) {
  208. return el.getBoundingClientRect();
  209. }
  210.  
  211. let section_4 = setSizes().scopes.section_4;
  212. let test_s_4 = document.createElement('div');
  213. d3.select(test_s_4)
  214. .style('width', '100vw')
  215. .style('border', '1vw solid green')
  216. .style('position', 'absolute')
  217. .style('top', `${section_4.top}vw`);
  218.  
  219. d3.select('.mobile_blog').node().appendChild(d3.select(test_s_4).node());
  220.  
  221. function scrollAnimation(){
  222.  
  223. d3.selectAll('.mobile_blog_post_list li')
  224. .each(function(){
  225. let section_2 = setSizes().scopes.section_2;
  226. let section_3 = setSizes().scopes.section_3;
  227. let section_4 = setSizes().scopes.section_4;
  228.  
  229.  
  230. let e = d3.select(this).node(),
  231. e_sizes = getOffset(e),
  232. e_top = e_sizes.top,
  233. e_bottom = e_sizes.bottom,
  234. e_center = e_bottom - (e_bottom - e_top)/2;
  235. console.log(`E_center: ${e_center} ---- Section_2: ${section_2.top} | ${section_2.bottom}`)
  236. if(e_center < section_3.bottom && e_center > section_3.top){
  237. d3.select(this)
  238. .style('box-shadow', 'inset 0vw 0vw 2vw rgba(15, 15, 15, 0.8)');
  239. }else{
  240. d3.select(this)
  241. .style('box-shadow', 'none');
  242. }
  243. // if(e_center < section_3.bottom && e_center > section_3.top){
  244. // d3.select(this).call(postTransform, 40, 6, 5);
  245. // }
  246. // if(e_center < section_4.bottom && e_center > section_4.top){
  247. // d3.select(this).call(postTransform, 55, 4, 3);
  248. // }
  249. // if(e_center <= section_2.top*0.95 || e_center >= section_4.bottom*1.05){
  250. // d3.select(this).call(postTransform, 60, 3, 2);
  251. // }
  252. });
  253. }
  254. }
  255. }
  256.  
  257.  
  258. goBack(){
  259. if(!this.state.map){
  260. this.props.history.goBack();
  261. }
  262. }
  263.  
  264. searchDate = (selectedDate) => {
  265. if(selectedDate){
  266. this.setState({
  267. posts: [],
  268. meta: '',
  269. notFound: false
  270. })
  271. console.log(selectedDate.getHours())
  272. fetch('/api/date-search/' + selectedDate.toISOString()
  273. )
  274. .then(res => res.json())
  275. .then(posts => this.setState({posts}))
  276. }
  277. }
  278.  
  279. searchCategory = (e) => {
  280. fetch('/api/category-search/' + e)
  281. .then(res => res.json())
  282. .then(posts => this.setState({ posts }))
  283. }
  284.  
  285.  
  286.  
  287. searchText = (e) => {
  288. let word = document.getElementById('search_blog').value;
  289. console.log(word);
  290. if(word === ''){
  291. fetch('/api/posts')
  292. .then(res => res.json())
  293. .then(posts => this.setState({posts, notFound: false}))
  294. } else {
  295. fetch('/api/post-search/'+word)
  296. .then(res => res.json())
  297. .then(posts => {
  298. if(posts.length > 0){
  299. this.setState({posts, notFound: false})
  300. } else {
  301. this.setState({ notFound: true });
  302.  
  303. if(this.state.animation_flag == false){
  304. this.state.animation_flag = true;
  305. let that = this;
  306. d3.select('.blog_post_not_found_box')
  307. .style('visibility', 'visible')
  308. .style('opacity', '1');
  309. d3.select('.blog_post_not_found_wrap')
  310. .style('left', '0vw')
  311. .style('width', '0vw')
  312. .transition()
  313. .duration(300)
  314. .ease(d3.easeLinear)
  315. .style('width', '10vw')
  316. .transition()
  317. .duration(300)
  318. .ease(d3.easeLinear)
  319. .style('left', '10vw')
  320. .style('width', '0vw');
  321. d3.select('.blog_post_not_found_text')
  322. .style('left', '-15vw')
  323. .transition()
  324. .duration(300)
  325. .ease(d3.easeLinear)
  326. .style('left', '0vw');
  327. d3.timeout(function(){
  328. d3.select('.blog_post_not_found_box')
  329. .style('opacity', '1')
  330. .transition()
  331. .duration(300)
  332. .ease(d3.easeLinear)
  333. .style('opacity', '0')
  334. .on('end', function(){
  335. that.setState({animation_flag : false});
  336. d3.select(this).style('visibility', 'hidden');
  337. })
  338. },1000);
  339. }
  340. }
  341. })
  342. }
  343.  
  344.  
  345.  
  346. }
  347.  
  348. render(){
  349. let that = this;
  350. window.addEventListener("resize", function(){
  351. let set_visibility = that.state.visibility;
  352. that.setState({visibility: window.innerWidth >= 768 ? true : false});
  353. if(set_visibility != that.state.visibility){
  354. that.render();
  355. that.componentDidMount();
  356. }
  357. });
  358. return(
  359. <div className="Seo">
  360. <MetaTags>
  361. <title>{this.state.meta && this.state.meta.title}</title>
  362. <meta name="description" content={this.state.meta && this.state.meta.description}/>
  363. <meta property="og:title" content={this.state.meta && this.state.meta.title} />
  364. </MetaTags>
  365.  
  366. <div>
  367. {
  368. this.state.visibility ?(
  369. <div className="blog_canvas">
  370. <div className="blog_area">
  371. {
  372. this.state && this.state.posts && this.state.posts.map(post =>
  373. <BlogPost item={post}/>
  374. )
  375. }
  376.  
  377. </div>
  378. <div className="post_delimiter"></div>
  379. <div className="post_controller">
  380.  
  381. <div className="post_type_selector">
  382. <div>
  383. <h3 data="seo" onClick={() => this.searchCategory('SEO')}><span></span>SEO</h3>
  384. <h3 data="design" onClick={() => this.searchCategory('DESIGN')}><span></span>DESIGN</h3>
  385. </div>
  386. <div>
  387. <h3 data="web" onClick={() => this.searchCategory('WEB')}><span></span>WEB</h3>
  388. </div>
  389. <div>
  390. <h3 data="news" onClick={() => this.searchCategory('NEWS')}><span></span>NEWS</h3>
  391. <h3 data="other" onClick={() => this.searchCategory('OTHER')}><span></span>OTHER</h3>
  392. </div>
  393. </div>
  394. <div className="post_search">
  395. {
  396. this.state.notFound &&
  397. <div className="blog_post_not_found_box">
  398. <div className="blog_post_not_found_wrap"></div>
  399. <div className="blog_post_not_found_text">text <span>not</span> found</div>
  400. </div>
  401. }
  402. <input type="text" id="search_blog" placeholder="Пошук" onKeyUp={(e) => e.keyCode === 13 && this.searchText()}/>
  403. <button onClick={this.searchText}><img src={search_img}/></button>
  404. {/* <img src={search_img}/> */}
  405. </div>
  406. {/* <div className="posts_selector">
  407. <span>Show for...</span>
  408. <div className="number_posts_selector">
  409. <div className="selector_circle"></div>
  410. <select>
  411. <option>All time</option>
  412. <option>Recently</option>
  413. </select>
  414. </div>
  415. </div> */}
  416. <div className="posts_selector">
  417. <span>Кількість постів на екрані:</span>
  418. <div className="size_posts_selector">
  419. <div className="selector_circle"></div>
  420. <div className="size_posts_custom_selector" data-flag="false">
  421. <span data-size='Близько'>Близько</span>
  422. <span data-size='Ще ближче'>Ще ближче</span>
  423. <span data-size='Дуже близько'>Дуже близько</span>
  424. </div>
  425. </div>
  426. </div>
  427. {/* <div className="posts_calendar">
  428. <span>Calendar</span>
  429. <h2>1 2 3 4 5 6 7<br/> 8 9 10 11 12 13 14<br/>
  430. 15 16 17 18 19 20 21 <br/>22 23 24 25 26 27 28<br/>29 30</h2>
  431. </div>
  432. <div>
  433. <Calendar onClickDay={this.searchDate}/>
  434. </div>
  435.  
  436. </div> */}
  437. </div>
  438. <Logo/>
  439. <Socials/>
  440. </div>
  441. ):(
  442. <div className="mobile_blog">
  443. <MobileNav isBlog={true}/>
  444. <div className="mobile_blog_header">
  445. <div className="m_search_box">
  446. <h3>BLOG</h3>
  447. <input type="text" className="m_search_input" />
  448. </div>
  449. <img data-search={false} className="m_search_start_button" src={Search_img}/>
  450. </div>
  451. <div className="mobile_blog_circles">
  452. <div className="mobile_blog_left_circle"></div>
  453. <div className="mobile_blog_right_circle"></div>
  454. </div>
  455. <div className="mobile_blog_content">
  456. <div className="mobile_blog_post_list">
  457. <ul>
  458. <li className="mobile_blog_post_correct">
  459. </li>
  460. {/* {
  461. this.state && this.state.posts && this.state.posts.map(post =>
  462. <BlogPostMobile item={post}/>
  463. )
  464. } */}
  465. <li className="mobile_blog_post">
  466. <div className="mobile_blog_post_date">01.04</div>
  467. <div className="mobile_blog_post_data">
  468. <h3>DESIGN</h3>
  469. <h2>Веб-дизайн як метод маніпуляції користувачем </h2>
  470. </div>
  471. </li>
  472. <li className="mobile_blog_post">
  473. <div className="mobile_blog_post_date">01.04</div>
  474. <div className="mobile_blog_post_data">
  475. <h3>DESIGN</h3>
  476. <h2>Веб-дизайн як метод маніпуляції користувачем </h2>
  477. </div>
  478. </li>
  479. <li className="mobile_blog_post">
  480. <div className="mobile_blog_post_date">01.04</div>
  481. <div className="mobile_blog_post_data">
  482. <h3>DESIGN</h3>
  483. <h2>Веб-дизайн як метод маніпуляції користувачем </h2>
  484. </div>
  485. </li>
  486. <li className="mobile_blog_post">
  487. <div className="mobile_blog_post_date">01.04</div>
  488. <div className="mobile_blog_post_data">
  489. <h3>DESIGN</h3>
  490. <h2>Веб-дизайн як метод маніпуляції користувачем </h2>
  491. </div>
  492. </li>
  493. <li className="mobile_blog_post">
  494. <div className="mobile_blog_post_date">01.04</div>
  495. <div className="mobile_blog_post_data">
  496. <h3>DESIGN</h3>
  497. <h2>Веб-дизайн як метод маніпуляції користувачем </h2>
  498. </div>
  499. </li>
  500.  
  501.  
  502. <li className="mobile_blog_post_correct">
  503. </li>
  504. </ul>
  505. </div>
  506. </div>
  507. <MobileBlogNav/>
  508. <img src={MobileExit} onClick={()=>this.goBack()} className="mobile_exit" style={{height: '5vh', width: '5vh'}}/>
  509. </div>
  510. )
  511. }
  512. </div>
  513. </div>
  514. )
  515. }
  516. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement