Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New comments functionality #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions frontend/zulu/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ label {
padding: 40px 40px;
}

.buttons-container {
position: absolute;
z-index: 2;
pointer-events: auto !important;
}

.card {
background-color: #f7f7f7;
padding: 20px 25px 30px;
Expand Down
90 changes: 90 additions & 0 deletions frontend/zulu/src/components/CardComponent/CardComponent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React from "react";
import Card from "../Card/Card";
import * as PropTypes from "prop-types";
import axios from "axios";
import StoryService from '../../services/story.service'
import storyService from "../../services/story.service";
const API_URL = "http://localhost:8342/api";

export class CommentComponent extends React.Component {
constructor(props) {
super(props);}
render() {
return (<div>
<p><strong>comments:</strong></p>
{this.props.comments.map(comment => (<p style={{
backgroundColor: "#3BD8FF",
marginLeft: "auto",
marginRight: "auto"
}}>{comment.user_name} : {comment.comment}</p>))}
</div>)
}
}

export class CardComponent extends React.Component {
constructor(props) {
super(props);
this.state = {value: '',comments:[]};

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
componentDidMount() {
storyService.GetStoryComments(this.props.f.pageid).then(response => this.setState({comments:response.data}));


}

handleChange(event) {
this.setState({value: event.target.value});
}

async handleSubmit(event) {
storyService.PostUserComment(this.props.f.pageid,this.state.value,true);
}

parseImagePath(thumbnailPath) {
const lastSlashIndex = thumbnailPath.lastIndexOf("/");
var path = thumbnailPath.slice(0, lastSlashIndex);
path = path.replace("thumb/", "");
return path
}

render() {
return <Card background='#2980B9' height="200">
<div style={{marginLeft: "auto", marginRight: "auto", height: "200px", overflowY: "scroll"}}>
<a href={"https://en.wikipedia.org/?curid=" + this.props.f.pageid}
style={{color: "black", textDecoration: "none"}}>
<h3>{this.props.f.title}</h3>
</a>
{this.props.f.hasOwnProperty("thumbnail") ?
<img display="inline-block" src={this.parseImagePath(this.props.f.thumbnail.source)}
style={{maxHeight: "200px", maxWidth: "200px"}}></img>
:
<p></p>
}

<p id="desc"
style={{float: "left", dir: "rtl", color: "black", fontWeight: "bold", lineHeight: "18px"}}>

{this.props.f.extract}
</p>
<div>

<CommentComponent comments={this.state.comments}/>
<form onSubmit={this.handleSubmit}>
<label>
comment:
<input type="text" value={this.state.value} onChange={this.handleChange}/>
</label>
<input type="submit" value="Submit"/>
</form>
</div>
</div>


</Card>;
}
}

CardComponent.propTypes = {f: PropTypes.any};
49 changes: 14 additions & 35 deletions frontend/zulu/src/components/Map/GeoWikipediaLayerFunc.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React, {useState, useEffect} from 'react';
import {Marker, FeatureGroup, Popup} from 'react-leaflet';
import React, {useEffect, useState} from 'react';
import {FeatureGroup, Marker, Popup} from 'react-leaflet';
import MarkerClusterGroup from "react-leaflet-markercluster";
import Card from '../Card/Card'
import { iconWiki } from '../../Icons/Icon.Wiki';
import {iconWiki} from '../../Icons/Icon.Wiki';
import "./GeoWiki.css";
import {CardComponent} from "../CardComponent/CardComponent";


var fetchData = function fetchData(lat, lng, maxDist, options) {
const url = "https://en.wikipedia.org/w/api.php?action=query&generator=geosearch&prop=coordinates%7C" +
"pageimages%7Cextracts&exintro=&explaintext=true&ggscoord=" + lat + "%7C" + lng + "&ggsradius=" + maxDist + "&format=json"
"pageimages%7Cextracts&exintro=&explaintext=true&ggscoord=" + lat + "%7C" + lng + "&ggsradius=" + maxDist + "&format=json"
var request = fetch(url, options).then(r => r.json());

return request.then(r => {

if (r.hasOwnProperty("query")){
Expand All @@ -19,26 +19,23 @@ var fetchData = function fetchData(lat, lng, maxDist, options) {
else{
return [];
}
});
});
}


function parseImagePath(thumbnailPath) {
const lastSlashIndex = thumbnailPath.lastIndexOf("/");
var path = thumbnailPath.slice(0, lastSlashIndex);
path = path.replace("thumb/", "");
return path
function get_comments(){
return ["thats amazing!","unbelivable!"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? should probably be removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

}



export default function GeoWikipediaLayer({lat, lng, maxDist, cluster}) {
const [data, setData] = useState([]);

useEffect(() => {
if (lat && lng && maxDist) {
const abortController = new AbortController();

fetchData(lat,lng, maxDist, {signal: abortController.signal}).then(data => {
fetchData(lat,lng, maxDist, {signal: abortController.signal}).then(data => {
setData(data);
});

Expand All @@ -62,29 +59,11 @@ export default function GeoWikipediaLayer({lat, lng, maxDist, cluster}) {
icon={iconWiki}
>

<Popup minWidth={300} closeButton={true} closeOnClick={false} autoClose={false}>

<Card background='#2980B9' height="200" >
<div style={{marginLeft:"auto" ,marginRight:"auto", height: "200px", overflowY: "scroll"} }>
<a href={"https://en.wikipedia.org/?curid="+f.pageid} style={{color:"black",textDecoration:"none"}}>

<h3>{f.title}</h3>
</a>
{ f.hasOwnProperty('thumbnail') ?
<img display="inline-block" src={parseImagePath(f.thumbnail.source)} style={{maxHeight: "200px", maxWidth: "200px"}}></img>
:
<p ></p>
}

<p id="desc" style={{float:"left",dir:"rtl",color: "black",fontWeight: "bold" ,lineHeight: "18px"}}>

{f.extract}
</p>
</div>
<Popup minWidth={300} closeButton={true} closeOnClick={false} autoClose={false}>

</Card>
<CardComponent f={f}/>

</Popup>
</Popup>


</Marker>
Expand Down
8 changes: 4 additions & 4 deletions frontend/zulu/src/components/Map/GeojsonLayerFunc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import StoryService from '../../services/story.service'


function parseImagePath(imageId) {
// TODO: use the StoryService
return "http://localhost:8342/api/story/image?id=" + imageId;
// TODO: use the StoryService
return "http://localhost:8342/api/story/image?image_id=" + imageId;
}


Expand Down Expand Up @@ -42,8 +42,8 @@ export default function GeojsonLayer({lat, lng, maxDist, cluster}) {
<Popup minWidth={400} closeButton={true} closeOnClick={false} autoClose={false}>

<Card background='#2980B9' height="400">
<h1>{f.story.title}</h1>
<h2>Added by {f.user_id} </h2>
<h3>{f.story.title}</h3>
<h5>Added by {f.user_id} </h5>
{ f.story.hasOwnProperty('image_id') && f.story.image_id != null ?
<img src={parseImagePath(f.story.image_id)} style={{maxHeight: "430px", maxWidth: "430px"}}></img>
:
Expand Down
Loading