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

🚧 Added link-previews #143

Open
wants to merge 1 commit into
base: main
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.5.3",
"private": true,
"dependencies": {
"@dhaiwat10/react-link-preview": "^1.12.2",
"@fortawesome/fontawesome-svg-core": "^1.2.34",
"@fortawesome/free-solid-svg-icons": "^5.15.2",
"@fortawesome/react-fontawesome": "^0.1.14",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Feed/FeedCreatePostForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './style.scss'
import { Card, Input, Modal, Button, TextArea, Form, Popup } from 'semantic-ui-react'
import PropTypes from 'prop-types'
let linkify = require('linkifyjs')
require('linkifyjs/plugins/hashtag')(linkify) // optional
require('linkifyjs/plugins/hashtag')(linkify)
let linkifyHtml = require('linkifyjs/html')

import convertToMarkup from './convertToMarkup'
Expand Down
48 changes: 34 additions & 14 deletions src/components/Feed/FeedPostItem/index.jsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
import React, { useEffect, useState } from 'react'
import './style.scss'
import { Feed, Modal, Loader, Button, Pagination } from 'semantic-ui-react'
import { Feed } from 'semantic-ui-react'
import { BrowserRouter as Router, Switch, Route, Link, Redirect } from 'react-router-dom'
import { ThumbsUp, MessageCircle, FileText, Flag, CornerDownRight, Share2 } from 'react-feather'
import PropTypes from 'prop-types'
import getFriendlyDate from '../../../utils/getFriendlyDate'
import loadPosts from '../../../utils/loadPosts'
import likePost from '../../../utils/likePost'
import toggleComment from '../../../utils/toggleComment'
import VirtualScroll from 'react-dynamic-virtual-scroll'
import { LinkPreview } from '@dhaiwat10/react-link-preview';
let linkify = require('linkifyjs')
require('linkifyjs/plugins/hashtag')(linkify)
let linkifyHtml = require('linkifyjs/html')

import unknownAvatar from '../../../static/unknown.png'

import CommentSection from '../FeedCommentSection'

export default function PostItem(props) {
const [items, setItems] = useState([])
const [isLoading, setIsLoading] = useState(true)
const [paginationPage, setPaginationPage] = useState(1)
const [totalPaginationPages, setTotalPagionationPages] = useState(1)
const [isLoadingMore, setIsLoadingMore] = useState(false)
const [visibleCommentSections, setVisibleCommentSections] = useState([])
const [emptyStates, setEmptyStates] = useState(["It's empty here. Start sharing something about your thoughts!", 'Your friends are shy. Get started and write your first post.'])
const [imageModalVisible, setImageModalVisible] = useState(false)
const [imageModalUrl, setImageModalUrl] = useState('')
const [reportModalVisible, setReportModalVisible] = useState(false)
const [reportModalPostId, setReportModalPostId] = useState(0)
const [reportSuccessVisible, setReportSuccessVisible] = useState(false)
const [reportErrorVisible, setReportErrorVisible] = useState(false)
const [postUrls, setPostUrls] = useState([]);

useEffect(() => {
let links = linkify.find(props.post.post_content.replace(/<[^>]+>/g, ''));

let urls = [];

links.forEach(link => {
if(link.type == "url") {
urls.push(link.href)
}
});

let uniqueUrls = [...new Set(urls)];

console.log(uniqueUrls);
setPostUrls(uniqueUrls);
}, [])

const toggleLongText = (postId) => {
document.querySelector('#post_' + postId + ' div.text').classList.toggle('collapsed')
Expand Down Expand Up @@ -75,8 +85,15 @@ export default function PostItem(props) {
setVisibleCommentSections(toggleComment(e, visibleCommentSections))
}

const linkFetcher = async (url) => {
const response = await fetch(`https://rlp-proxy.herokuapp.com/v2?url=${url}&test=true`);
const json = await response.json();
console.log(json);
return json.metadata;
};

return (
<React.Fragment key={props.post.id}>
<React.Fragment>
<Feed.Event id={'post_' + props.post.id} className={visibleCommentSections.includes(props.post.id) == 0 ? 'event--no-comments-visible' : ''}>
<Feed.Label className="user-avatar">
<Link to={'/app/user/' + props.post.email}>
Expand All @@ -100,6 +117,9 @@ export default function PostItem(props) {
</Feed.Summary>
<Feed.Extra className={props.post.post_content.length > 465 ? 'collapsed' : ''} text>
<div dangerouslySetInnerHTML={{ __html: props.post.post_content }}></div>
{postUrls.map((postUrl, index) =>
<LinkPreview key={index} width='100%' margin='10px 0' borderColor='rgba(34,36,38,.1)' imageHeight='100px' fetcher={linkFetcher} url={postUrl} />
)}
{props.post.post_content.length > 465 && (
<a
href="#"
Expand Down
112 changes: 107 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,49 @@
resolved "https://registry.npmjs.org/@csstools/normalize.css/-/normalize.css-10.1.0.tgz"
integrity sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg==

"@dhaiwat10/react-link-preview@^1.12.2":
version "1.12.2"
resolved "https://registry.yarnpkg.com/@dhaiwat10/react-link-preview/-/react-link-preview-1.12.2.tgz#426b8496681e9506eaa5ebfec085aecf71725179"
integrity sha512-g7mybM7SxLlPsuielwEIr+7hC0uk+x9+/M9PhBXVd/x6zLf3ncHVkzMZrpYrSgx3sNd4G0fH9D6oV1eocO+kTw==
dependencies:
react-loading-skeleton "^2.2.0"

"@emotion/cache@^10.0.27":
version "10.0.29"
resolved "https://registry.yarnpkg.com/@emotion/cache/-/cache-10.0.29.tgz#87e7e64f412c060102d589fe7c6dc042e6f9d1e0"
integrity sha512-fU2VtSVlHiF27empSbxi1O2JFdNWZO+2NFHfwO0pxgTep6Xa3uGb+3pVKfLww2l/IBGLNEZl5Xf/++A4wAYDYQ==
dependencies:
"@emotion/sheet" "0.9.4"
"@emotion/stylis" "0.8.5"
"@emotion/utils" "0.11.3"
"@emotion/weak-memoize" "0.2.5"

"@emotion/core@^10.0.22":
version "10.3.1"
resolved "https://registry.yarnpkg.com/@emotion/core/-/core-10.3.1.tgz#4021b6d8b33b3304d48b0bb478485e7d7421c69d"
integrity sha512-447aUEjPIm0MnE6QYIaFz9VQOHSXf4Iu6EWOIqq11EAPqinkSZmfymPTmlOE3QjLv846lH4JVZBUOtwGbuQoww==
dependencies:
"@babel/runtime" "^7.5.5"
"@emotion/cache" "^10.0.27"
"@emotion/css" "^10.0.27"
"@emotion/serialize" "^0.11.15"
"@emotion/sheet" "0.9.4"
"@emotion/utils" "0.11.3"

"@emotion/css@^10.0.27":
version "10.0.27"
resolved "https://registry.yarnpkg.com/@emotion/css/-/css-10.0.27.tgz#3a7458198fbbebb53b01b2b87f64e5e21241e14c"
integrity sha512-6wZjsvYeBhyZQYNrGoR5yPMYbMBNEnanDrqmsqS1mzDm1cOTu12shvl2j4QHNS36UaTE0USIJawCH9C8oW34Zw==
dependencies:
"@emotion/serialize" "^0.11.15"
"@emotion/utils" "0.11.3"
babel-plugin-emotion "^10.0.27"

"@emotion/[email protected]":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.8.0.tgz#bbbff68978fefdbe68ccb533bc8cbe1d1afb5413"
integrity sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==

"@emotion/is-prop-valid@^0.8.8":
version "0.8.8"
resolved "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-0.8.8.tgz"
Expand All @@ -1238,16 +1281,42 @@
resolved "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.4.tgz"
integrity sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==

"@emotion/stylis@^0.8.4":
"@emotion/serialize@^0.11.15", "@emotion/serialize@^0.11.16":
version "0.11.16"
resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.11.16.tgz#dee05f9e96ad2fb25a5206b6d759b2d1ed3379ad"
integrity sha512-G3J4o8by0VRrO+PFeSc3js2myYNOXVJ3Ya+RGVxnshRYgsvErfAOglKAiy1Eo1vhzxqtUvjCyS5gtewzkmvSSg==
dependencies:
"@emotion/hash" "0.8.0"
"@emotion/memoize" "0.7.4"
"@emotion/unitless" "0.7.5"
"@emotion/utils" "0.11.3"
csstype "^2.5.7"

"@emotion/[email protected]":
version "0.9.4"
resolved "https://registry.yarnpkg.com/@emotion/sheet/-/sheet-0.9.4.tgz#894374bea39ec30f489bbfc3438192b9774d32e5"
integrity sha512-zM9PFmgVSqBw4zL101Q0HrBVTGmpAxFZH/pYx/cjJT5advXguvcgjHFTCaIO3enL/xr89vK2bh0Mfyj9aa0ANA==

"@emotion/[email protected]", "@emotion/stylis@^0.8.4":
version "0.8.5"
resolved "https://registry.npmjs.org/@emotion/stylis/-/stylis-0.8.5.tgz"
integrity sha512-h6KtPihKFn3T9fuIrwvXXUOwlx3rfUvfZIcP5a6rh8Y7zjE3O06hT5Ss4S/YI1AYhuZ1kjaE/5EaOOI2NqSylQ==

"@emotion/unitless@^0.7.4":
"@emotion/unitless@0.7.5", "@emotion/unitless@^0.7.4":
version "0.7.5"
resolved "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz"
integrity sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==

"@emotion/[email protected]":
version "0.11.3"
resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-0.11.3.tgz#a759863867befa7e583400d322652a3f44820924"
integrity sha512-0o4l6pZC+hI88+bzuaX/6BgOvQVhbt2PfmxauVaYOGgbsAw14wdKyvMCZXnsnsHys94iadcF+RG/wZyx6+ZZBw==

"@emotion/[email protected]":
version "0.2.5"
resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.2.5.tgz#8eed982e2ee6f7f4e44c253e12962980791efd46"
integrity sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA==

"@eslint/eslintrc@^0.4.2":
version "0.4.2"
resolved "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.2.tgz"
Expand Down Expand Up @@ -3146,6 +3215,22 @@ babel-plugin-dynamic-import-node@^2.3.3:
dependencies:
object.assign "^4.1.0"

babel-plugin-emotion@^10.0.27:
version "10.2.2"
resolved "https://registry.yarnpkg.com/babel-plugin-emotion/-/babel-plugin-emotion-10.2.2.tgz#a1fe3503cff80abfd0bdda14abd2e8e57a79d17d"
integrity sha512-SMSkGoqTbTyUTDeuVuPIWifPdUGkTk1Kf9BWRiXIOIcuyMfsdp2EjeiiFvOzX8NOBvEh/ypKYvUh2rkgAJMCLA==
dependencies:
"@babel/helper-module-imports" "^7.0.0"
"@emotion/hash" "0.8.0"
"@emotion/memoize" "0.7.4"
"@emotion/serialize" "^0.11.16"
babel-plugin-macros "^2.0.0"
babel-plugin-syntax-jsx "^6.18.0"
convert-source-map "^1.5.0"
escape-string-regexp "^1.0.5"
find-root "^1.1.0"
source-map "^0.5.7"

babel-plugin-istanbul@^6.0.0:
version "6.0.0"
resolved "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-6.0.0.tgz"
Expand All @@ -3167,7 +3252,7 @@ babel-plugin-jest-hoist@^26.6.2:
"@types/babel__core" "^7.0.0"
"@types/babel__traverse" "^7.0.6"

[email protected]:
[email protected], babel-plugin-macros@^2.0.0:
version "2.8.0"
resolved "https://registry.npmjs.org/babel-plugin-macros/-/babel-plugin-macros-2.8.0.tgz"
integrity sha512-SEP5kJpfGYqYKpBrj5XU3ahw5p5GOHJ0U5ssOSQ/WBVdwkD2Dzlce95exQTs3jOVWPPKLBN2rlEWkCK7dSmLvg==
Expand Down Expand Up @@ -4115,7 +4200,7 @@ convert-source-map@^0.3.3:
resolved "https://registry.npmjs.org/convert-source-map/-/convert-source-map-0.3.5.tgz"
integrity sha1-8dgClQr33SYxof6+BZZVDIarMZA=

convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
convert-source-map@^1.4.0, convert-source-map@^1.5.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
version "1.8.0"
resolved "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.8.0.tgz"
integrity sha512-+OQdjP49zViI/6i7nIJpA8rAl4sV/JdPfU9nZs3VqOwGIgizICvuN2ru6fMd+4llL0tar18UYJXfZ/TWtmhUjA==
Expand Down Expand Up @@ -4570,6 +4655,11 @@ cssstyle@^2.3.0:
dependencies:
cssom "~0.3.6"

csstype@^2.5.7:
version "2.6.19"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.19.tgz#feeb5aae89020bb389e1f63669a5ed490e391caa"
integrity sha512-ZVxXaNy28/k3kJg0Fou5MiYpp88j7H9hLZp8PDC3jV0WFjfH5E9xHb56L0W59cPbKbcHXeP4qyT8PrHp8t6LcQ==

cyclist@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz"
Expand Down Expand Up @@ -5768,6 +5858,11 @@ find-cache-dir@^3.3.1:
make-dir "^3.0.2"
pkg-dir "^4.1.0"

find-root@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/find-root/-/find-root-1.1.0.tgz#abcfc8ba76f708c42a97b3d685b7e9450bfb9ce4"
integrity sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==

[email protected], find-up@^4.0.0, find-up@^4.1.0:
version "4.1.0"
resolved "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz"
Expand Down Expand Up @@ -10551,6 +10646,13 @@ react-lifecycles-compat@^3.0.4:
resolved "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz"
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==

react-loading-skeleton@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/react-loading-skeleton/-/react-loading-skeleton-2.2.0.tgz#b8ce516f9a2471e90d7d9ead35d61425367e3340"
integrity sha512-HH37uj9aobrUJSqFglHqO9KQt5zGQe+Svutv8LIq7Iq6gpJqCwIzJOsEVfkQy7ReirbI2uLhCtKloBGQIDP0BQ==
dependencies:
"@emotion/core" "^10.0.22"

react-markdown@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/react-markdown/-/react-markdown-7.1.1.tgz#cb4d2c2fa3bc1292c889b068a5bf064ae4be1c60"
Expand Down Expand Up @@ -11645,7 +11747,7 @@ [email protected], source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, sourc
resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

source-map@^0.5.0, source-map@^0.5.6:
source-map@^0.5.0, source-map@^0.5.6, source-map@^0.5.7:
version "0.5.7"
resolved "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz"
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
Expand Down