From 60f83e28ecb672a6482b7eb7cbd2e2554fda1af9 Mon Sep 17 00:00:00 2001 From: lamacchinadesiderante Date: Tue, 10 Jan 2023 23:16:57 +0100 Subject: [PATCH 1/6] re-enabling IPFS Gateway links --- frontend/src/components/BooksDetailsCard.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/BooksDetailsCard.tsx b/frontend/src/components/BooksDetailsCard.tsx index 98ac9ee..295ff7e 100644 --- a/frontend/src/components/BooksDetailsCard.tsx +++ b/frontend/src/components/BooksDetailsCard.tsx @@ -19,12 +19,12 @@ interface IProps { const BookDetailsCard: React.FC = (props) => { - // const downloadLinkFromIPFS = (gateway: string, book: Book) => { - // return ( - // `https://${gateway}/ipfs/${book.ipfs_cid}?filename=` + - // encodeURIComponent(`${book.title}_${book.author}.${book.extension}`) - // ); - // } + const downloadLinkFromIPFS = (gateway: string, book: Book) => { + return ( + `https://${gateway}/ipfs/${book.ipfs_cid}?filename=` + + encodeURIComponent(`${book.title}_${book.author}.${book.extension}`) + ); + } const { t } = useTranslation(); @@ -88,7 +88,7 @@ const BookDetailsCard: React.FC = (props) => { - {/* + {ipfsGateways.map((gateway) => ( ))} - */} + {t('disclaimer.nolink_warning')} From 2dd24c4f89f3a78adac7d9485c8535bc5246894d Mon Sep 17 00:00:00 2001 From: lamacchinadesiderante Date: Tue, 10 Jan 2023 23:19:11 +0100 Subject: [PATCH 2/6] remove readme info --- README.md | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) diff --git a/README.md b/README.md index 149a454..a6e3478 100644 --- a/README.md +++ b/README.md @@ -10,20 +10,6 @@ Il progetto è partito come un fork di [Book Searcher](https://github.com/book-s L'obiettivo è trasformarlo in una piattaforma partecipativa: gli utenti avranno la possibilità di richiedere l'aggiunta di libri, oltre a fare ricerche. -## Copyright e pirateria - -Nessun materiale protetto da copyright è ospitato su questo repo. - -Nessun link a materiale protetto da copyright è ospitato su questo repo. - -Il motore fa ricerche su degli indici, e fornisce dei risultati. - -Non abbiamo nulla contro la pirateria, ma vogliamo evitare di trovarci in situazioni spiacevoli. - -Non riusciamo a capire in quali occasioni la condivisione di link esterni a materiale protetto da copyright sia reato e in quali no. Quindi, per tutelarci, abbiamo disabilitato la generazione automatica di link IPFS alle risorse. Tuttavia è possibile riabilitarla modificando il codice sorgente (spiegato sotto). - -Viene fornita solo un'informazione parziale. Sta all'utente mettere insieme i pezzi. - ## Installazione rapida E' possibile buildare il progetto via Docker. Occorre avere prima installato e configurato sia Docker che il tool `docker-compose`. @@ -48,39 +34,6 @@ npm run build npm run dev ``` -## Riabilitare la generazione dei link IPFS - -Per riabilitare i bottoni/link ai Gateway IPFS, aprire il file `frontend/src/components/BooksDetailsCard.tsx` e de-commentare le seguenti linee di codice: - -(da riga 22) - -``` - // const downloadLinkFromIPFS = (gateway: string, book: Book) => { - // return ( - // `https://${gateway}/ipfs/${book.ipfs_cid}?filename=` + - // encodeURIComponent(`${book.title}_${book.author}.${book.extension}`) - // ); - // } -``` - -(da riga 91) - -``` - {/* - {ipfsGateways.map((gateway) => ( - - ))} - - */} -``` - ## Licenza Book Searcher è rilasciato sotto licenza [BSD-3-Clause](https://github.com/book-searcher-org/book-searcher/blob/master/LICENSE). Millelibri eredita la licenza da Book Searcher. \ No newline at end of file From 9f719568a0fb220fecd0369b08cd4b639ea08d84 Mon Sep 17 00:00:00 2001 From: lamacchinadesiderante Date: Tue, 10 Jan 2023 23:20:22 +0100 Subject: [PATCH 3/6] comment disclaimer msg --- frontend/src/components/BooksDetailsCard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/BooksDetailsCard.tsx b/frontend/src/components/BooksDetailsCard.tsx index 295ff7e..2695966 100644 --- a/frontend/src/components/BooksDetailsCard.tsx +++ b/frontend/src/components/BooksDetailsCard.tsx @@ -102,7 +102,7 @@ const BookDetailsCard: React.FC = (props) => { - {t('disclaimer.nolink_warning')} + {/* {t('disclaimer.nolink_warning')} */} + + + } + + + {show && + + + + + } + + + ); +}; + +export default CopyToClipboardButton; diff --git a/frontend/src/components/Search.tsx b/frontend/src/components/Search.tsx index 0e6f627..498d324 100644 --- a/frontend/src/components/Search.tsx +++ b/frontend/src/components/Search.tsx @@ -1,5 +1,6 @@ -import { GridItem, Icon, SimpleGrid } from '@chakra-ui/react'; -import React, { useState } from 'react'; +import { Button, GridItem, Icon, SimpleGrid, Flex, Box, Card } from '@chakra-ui/react'; +import React, { useEffect, useState } from 'react'; +import MediaQuery from 'react-responsive' import { TbBook2, TbBuilding, @@ -11,10 +12,13 @@ import { import search, { Book } from '../scripts/searcher'; import { IoLanguage } from 'react-icons/io5'; +import { IoShareSocialOutline } from 'react-icons/io5'; import SearchInput from './SearchInput'; import { useDebounceEffect } from 'ahooks'; import { useTranslation } from 'react-i18next'; import SearchLanguage from './SearchLanguage'; +import { MEDIA_QUERY_DESKTOP_STARTS, MEDIA_QUERY_MOBILE_ENDS } from '../constants/mediaquery'; +import CopyToClipboardButton from './CopyToClipboardButton'; function constructQuery(parts: Record): string { return Object.keys(parts) @@ -44,6 +48,27 @@ const Search: React.FC = ({ setBooks }) => { const [complexQuery, setComplexQuery] = useState(''); const [showLanguageDropdown, setShowLanguageDropdown] = useState(true) + useEffect(() => { + const params = new Proxy(new URLSearchParams(window.location.search), { + //@ts-ignore + get: (searchParams, prop) => searchParams.get(prop), + }); + + //@ts-ignore + params.title && setTitle(String(params.title)) + + //@ts-ignore + params.author && setAuthor(String(params.author)) + + //@ts-ignore + if (params.language) { + //@ts-ignore + setLanguage(String(params.language)) + setShowLanguageDropdown(false) + } + + }, []) + const handleLanguageChange = (language: string) => { if (language == 'input') { setShowLanguageDropdown(false) @@ -57,6 +82,27 @@ const Search: React.FC = ({ setBooks }) => { setLanguage('') } + const hasAnySearchBeenMade = () => { + return ( + title !== '' + || author !== '' + || language !== '' + || publisher !== '' + || extension !== '' + || isbn !== '' + ) + } + + const copyToClipboard = () => { + const searchQuery = `${window.location.host}?title=${title}&author=${author}&language=${language}&publisher=${publisher}&isbn=${isbn}&extension=${extension}`; + + navigator.clipboard.writeText(searchQuery).then(() => { + //console.log('Async: Copying to clipboard was successful!'); + }, (err) => { + //console.error('Async: Could not copy text: ', err); + }); + } + useDebounceEffect( () => { const query = complexQuery @@ -72,66 +118,71 @@ const Search: React.FC = ({ setBooks }) => { ); return ( - - } - placeholder={t('book.title')} - value={title} - onChange={setTitle} - /> - } - placeholder={t('book.author')} - value={author} - onChange={setAuthor} - /> - } - placeholder={t('book.publisher')} - value={publisher} - onChange={setPublisher} - /> - } - placeholder={t('book.extension')} - value={extension} - onChange={setExtension} - /> - - {!showLanguageDropdown && (} - placeholder={t('input.select_language')} - value={language} - onChange={handleLanguageChange} - onClear={handleLanguageReset} - />)} - - {showLanguageDropdown && (} - placeholder={t('input.select_language')} - value={language} - onChange={handleLanguageChange} - />)} - - } - placeholder={t('book.isbn')} - value={isbn} - onChange={setISBN} - /> - + <> + } - placeholder={t('search.complex')} - value={complexQuery} - onChange={setComplexQuery} + icon={} + placeholder={t('book.title')} + value={title} + onChange={setTitle} /> - - + } + placeholder={t('book.author')} + value={author} + onChange={setAuthor} + /> + } + placeholder={t('book.publisher')} + value={publisher} + onChange={setPublisher} + /> + } + placeholder={t('book.extension')} + value={extension} + onChange={setExtension} + /> + + {!showLanguageDropdown && (} + placeholder={t('input.select_language')} + value={language} + onChange={handleLanguageChange} + onClear={handleLanguageReset} + />)} + + {showLanguageDropdown && (} + placeholder={t('input.select_language')} + value={language} + onChange={handleLanguageChange} + />)} + + } + placeholder={t('book.isbn')} + value={isbn} + onChange={setISBN} + /> + + } + placeholder={t('search.complex')} + value={complexQuery} + onChange={setComplexQuery} + /> + + + + ); }; diff --git a/frontend/src/i18n.json b/frontend/src/i18n.json index 9ea1ccd..e76b92a 100644 --- a/frontend/src/i18n.json +++ b/frontend/src/i18n.json @@ -39,7 +39,9 @@ "collapse": "Collapse" }, "search": { - "complex": "Complex search" + "complex": "Complex search", + "copy_search_link": "Copy to clipboard", + "copy_success": "Copied!" }, "settings": { "title": "Settings", @@ -205,7 +207,9 @@ "collapse": "Richiudi" }, "search": { - "complex": "Ricerca dettagliata" + "complex": "Ricerca dettagliata", + "copy_search_link": "Copia link ricerca", + "copy_success": "Copiato negli appunti!" }, "settings": { "title": "Impostazioni", From 5272e13f4574ea84e546f24b3f6239b414b33cdb Mon Sep 17 00:00:00 2001 From: lamacchinadesiderante Date: Wed, 11 Jan 2023 00:41:33 +0100 Subject: [PATCH 5/6] remove duplicate code --- .../src/components/CopyToClipboardButton.tsx | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/frontend/src/components/CopyToClipboardButton.tsx b/frontend/src/components/CopyToClipboardButton.tsx index 294058a..19e2cf7 100644 --- a/frontend/src/components/CopyToClipboardButton.tsx +++ b/frontend/src/components/CopyToClipboardButton.tsx @@ -29,28 +29,14 @@ const CopyToClipboardButton: React.FC = (props) => { return ( <> - - {show && - - - - - - - } - - - {show && - - - - - } - + {show && + + + + + } ); }; From 9f01f6332608ce740243a06d14eb8779e95d168b Mon Sep 17 00:00:00 2001 From: lamacchinadesiderante Date: Wed, 11 Jan 2023 13:02:28 +0100 Subject: [PATCH 6/6] add encode/decode uri component --- frontend/src/components/Search.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/Search.tsx b/frontend/src/components/Search.tsx index 498d324..aa214ac 100644 --- a/frontend/src/components/Search.tsx +++ b/frontend/src/components/Search.tsx @@ -49,7 +49,7 @@ const Search: React.FC = ({ setBooks }) => { const [showLanguageDropdown, setShowLanguageDropdown] = useState(true) useEffect(() => { - const params = new Proxy(new URLSearchParams(window.location.search), { + const params = new Proxy(new URLSearchParams(decodeURIComponent(window.location.search)), { //@ts-ignore get: (searchParams, prop) => searchParams.get(prop), }); @@ -94,9 +94,10 @@ const Search: React.FC = ({ setBooks }) => { } const copyToClipboard = () => { - const searchQuery = `${window.location.host}?title=${title}&author=${author}&language=${language}&publisher=${publisher}&isbn=${isbn}&extension=${extension}`; + const searchBase = `${window.location.host}/?`; + const searchQuery = encodeURIComponent(`title=${title}&author=${author}&language=${language}&publisher=${publisher}&isbn=${isbn}&extension=${extension}`) - navigator.clipboard.writeText(searchQuery).then(() => { + navigator.clipboard.writeText(`${searchBase}${searchQuery}`).then(() => { //console.log('Async: Copying to clipboard was successful!'); }, (err) => { //console.error('Async: Could not copy text: ', err);