Skip to content

Commit

Permalink
fixes #143, fixes #95
Browse files Browse the repository at this point in the history
  • Loading branch information
reiterbene committed Jun 19, 2023
1 parent 2d48b77 commit b8df676
Show file tree
Hide file tree
Showing 9 changed files with 19,619 additions and 576 deletions.
54 changes: 23 additions & 31 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="description" content="WikiDaheim ist ein Projekt von Freiwilligen der Wikimedia-Projekte wie Wikipedia, das sich mit dem Sammeln von Informationen über Gemeinden in ganz Österreich beschäftigt.">
<meta name="theme-color" content="#000000" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>WikiDaheim: deine Heimat in der Wikipedia</title>
</head>
<body>
<noscript>
WikiDaheim ist ein Projekt von Freiwilligen der Wikimedia-Projekte wie Wikipedia, das sich mit dem Sammeln von Informationen über Gemeinden in ganz Österreich beschäftigt.
WikiDaheim ist eine Webapplikation und benötigt daher JavaScript. Bitte aktiviere JavaScript für diese Webseite.
</noscript>
<div id="root"></div>

<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//wikilovesmonuments.at/piwik/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', '4']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
</body>
</html>
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="description"
content="WikiDaheim ist ein Projekt von Freiwilligen der Wikimedia-Projekte wie Wikipedia, das sich mit dem Sammeln von Informationen über Gemeinden in ganz Österreich beschäftigt.">
<meta name="theme-color" content="#000000" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>WikiDaheim: deine Heimat in der Wikipedia</title>
</head>

<body>
<noscript>
WikiDaheim ist ein Projekt von Freiwilligen der Wikimedia-Projekte wie Wikipedia, das sich mit dem Sammeln von
Informationen über Gemeinden in ganz Österreich beschäftigt.
WikiDaheim ist eine Webapplikation und benötigt daher JavaScript. Bitte aktiviere JavaScript für diese Webseite.
</noscript>
<div id="root"></div>
</body>

</html>
132 changes: 72 additions & 60 deletions src/api/wikidaheim.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,100 @@
import { WIKIDAHEIM_ENDPOINT, WIKIDAHEIM_FEEDBACK_ENDPOINT } from 'config';
import boundaries from '../config/boundaries.json';
import towns from '../config/wikidata-gkz.json';
import { WIKIDAHEIM_ENDPOINT, WIKIDAHEIM_FEEDBACK_ENDPOINT } from "config";
import boundaries from "../config/boundaries.json";
import towns from "../config/wikidata-gkz.json";

const listCategories = () => {
return fetch(`${ WIKIDAHEIM_ENDPOINT }?format=json&action=query&type=structure`, {
method: 'get',
}).then((res) => {
if (!res.ok) throw Error(res.statusText);
return res.json();
}).then(json => {
return json;
});
return fetch(
`${WIKIDAHEIM_ENDPOINT}?format=json&action=query&type=structure`,
{
method: "get",
}
)
.then((res) => {
if (!res.ok) throw Error(res.statusText);
return res.json();
})
.then((json) => {
return json;
});
};

const getTownData = (location, categories, getWikiData) => {
const categoriesString = categories.join('|');
const categoriesString = categories.join("|");

let locationQuery = '';
let locationQuery = "";

if (location.wikidata) {
locationQuery = `wikidata=${ location.wikidata }`;
} else if (location.iso && !location.name.includes('Wien')) {
locationQuery = `gemeindekennzahl=${ location.iso }`;
locationQuery = `wikidata=${location.wikidata}`;
} else if (location.iso && !location.name.includes("Wien")) {
locationQuery = `gemeindekennzahl=${location.iso}`;
} else {
locationQuery = `latitude=${ location.latitude }&longitude=${ location.longitude }`;
locationQuery = `latitude=${location.latitude}&longitude=${location.longitude}`;
}

return fetch(`${ WIKIDAHEIM_ENDPOINT }?format=json&action=query&type=data&${ locationQuery }&categories=${ categoriesString }&wiki=${ +getWikiData }`, {
method: 'get',
}).then((res) => {
if (!res.ok) throw Error(res.statusText);
return res.json();
}).then(json => {
const res = json;
const mod = {
selectedCats: categories,
};
return fetch(
`${WIKIDAHEIM_ENDPOINT}?format=json&action=query&type=data&${locationQuery}&categories=${categoriesString}&wiki=${+getWikiData}`,
{
method: "get",
}
)
.then((res) => {
if (!res.ok) throw Error(res.statusText);
return res.json();
})
.then((json) => {
const res = json;
const mod = {
selectedCats: categories,
};

// check if there were categories returned. if yes fix an API bug
if ('categories' in json) {
// check if the deep-nesting bug exists
if (json.categories.length === 1 && Array.isArray(json.categories[0])) {
mod.categories = json.categories[0];
// check if there were categories returned. if yes fix an API bug
if ("categories" in json) {
// check if the deep-nesting bug exists
if (json.categories.length === 1 && Array.isArray(json.categories[0])) {
mod.categories = json.categories[0];
}
}
}

return Object.assign({}, res, mod);
});
return Object.assign({}, res, mod);
});
};

const getFeedbackFormToken = () => {
return fetch(`${ WIKIDAHEIM_FEEDBACK_ENDPOINT }?token=new`, {
method: 'get',
}).then((res) => {
if (!res.ok) throw Error(res.statusText);
return res.json();
}).then(json => {
return json.token;
});
return fetch(`${WIKIDAHEIM_FEEDBACK_ENDPOINT}?token=new`, {
method: "get",
})
.then((res) => {
if (!res.ok) throw Error(res.statusText);
return res.json();
})
.then((json) => {
return json.token;
});
};

const submitFeedbackForm = (token, subject, message) => {
const formData = new FormData();
formData.append('token', token);
formData.append('subject', subject);
formData.append('message', message);
formData.append("token", token);
formData.append("subject", subject);
formData.append("message", message);

return fetch(`${ WIKIDAHEIM_FEEDBACK_ENDPOINT }`, {
method: 'post',
body: formData
}).then((res) => {
if (!res.ok) throw Error(res.statusText);
return res.json();
}).then(json => {
return json;
});
return fetch(`${WIKIDAHEIM_FEEDBACK_ENDPOINT}`, {
method: "post",
body: formData,
})
.then((res) => {
if (!res.ok) throw Error(res.statusText);
return res.json();
})
.then((json) => {
return json;
});
};

const search = (query, lang, gkzPrefix, maxResults = 7) => {
const search = (query, lang, maxResults = 7) => {
const filtered = towns
.filter(
(town) =>
town.gemeinde.toLowerCase().startsWith(query.toLowerCase()) &&
String(town.gemeindekennzahl).startsWith(gkzPrefix)
.filter((town) =>
town.gemeinde.toLowerCase().startsWith(query.toLowerCase())
)
.slice(0, maxResults)
.map((town) => ({
Expand Down
104 changes: 57 additions & 47 deletions src/components/Dashboard/Sidebar/CityInfo/ExternalLinkOverlay.jsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,64 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import React from "react";
import PropTypes from "prop-types";
import { FormattedMessage } from "react-intl";

class ExternalLinkOverlay extends Component {
static propTypes = {
title: PropTypes.object,
text: PropTypes.object,
link: PropTypes.string,
closeAction: PropTypes.func,
};
render() {
const { title, text, link, closeAction } = this.props;

return (
const ExternalLinkOverlay = ({
titleId,
textId,
link,
onClick,
closeAction,
}) => {
return (
<div // eslint-disable-line jsx-a11y/no-static-element-interactions
className="ExternalLink-Overlay"
onClick={closeAction}
>
<div // eslint-disable-line jsx-a11y/no-static-element-interactions
className='ExternalLink-Overlay'
onClick={ closeAction }
className="ExternalLink-Overlay-Inner"
onClick={(e) => e.stopPropagation()}
>
<div // eslint-disable-line jsx-a11y/no-static-element-interactions
className='ExternalLink-Overlay-Inner'
onClick={ (e) => e.stopPropagation() }
<button className="ExternalLink-Close" onClick={closeAction}>
<FormattedMessage
id="cancel"
description="Text for Cancel-Buttons"
defaultMessage="Abbrechen"
/>
</button>
<h1>
<FormattedMessage id={titleId} />
</h1>
<p>
<FormattedMessage id={textId} />
</p>
<a
href={link || "#"}
target="_blank"
rel="noopener noreferrer"
onClick={(e) => {
if (onClick) {
e.preventDefault();
onClick();
}
closeAction();
}}
>
<button
className='ExternalLink-Close'
onClick={ closeAction }
>
<FormattedMessage
id='cancel'
description='Text for Cancel-Buttons'
defaultMessage='Abbrechen'
/>
</button>
<h1>{ title }</h1>
<p>{ text }</p>
<a
href={ link }
target='_blank'
rel='noopener noreferrer'
onClick={ closeAction }
>
<FormattedMessage
id='cityinfo.openLink'
description='Text for External Link-Buttons (from City Details View)'
defaultMessage='Seite öffnen'
/>
</a>
</div>
<FormattedMessage
id="cityinfo.openLink"
description="Text for External Link-Buttons (from City Details View)"
defaultMessage="Seite öffnen"
/>
</a>
</div>
);
}
}
</div>
);
};

ExternalLinkOverlay.propTypes = {
title: PropTypes.string,
text: PropTypes.string,
link: PropTypes.string,
closeAction: PropTypes.func,
};

export default ExternalLinkOverlay;

0 comments on commit b8df676

Please sign in to comment.