🐛 FIX: randomQuote + backup fixes
This commit is contained in:
parent
015b0be11f
commit
aca93676e9
2
.github/backup.sql
vendored
2
.github/backup.sql
vendored
File diff suppressed because one or more lines are too long
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.github/backup
|
@ -6,10 +6,10 @@ import api from '../../utils/api';
|
|||||||
import useAPI from '../../hooks/useAPI';
|
import useAPI from '../../hooks/useAPI';
|
||||||
import './FunctionsList.css';
|
import './FunctionsList.css';
|
||||||
|
|
||||||
|
let pageFunctions = 1;
|
||||||
const FunctionsList = (props) => {
|
const FunctionsList = (props) => {
|
||||||
|
|
||||||
const { categoryId } = useRouter().query;
|
const { categoryId } = useRouter().query;
|
||||||
let pageFunctions = 1;
|
|
||||||
|
|
||||||
// State de recherche et de catégories
|
// State de recherche et de catégories
|
||||||
const [, categories] = useAPI('/categories');
|
const [, categories] = useAPI('/categories');
|
||||||
@ -56,13 +56,13 @@ const FunctionsList = (props) => {
|
|||||||
const getFunctionsData = async () => {
|
const getFunctionsData = async () => {
|
||||||
setLoadingFunctions(true);
|
setLoadingFunctions(true);
|
||||||
const URL = `${(props.isAdmin) ? "/admin/functions" : "/functions"}?page=${pageFunctions}&limit=10&categoryId=${inputSearch.selectedCategory}&search=${inputSearch.search}`;
|
const URL = `${(props.isAdmin) ? "/admin/functions" : "/functions"}?page=${pageFunctions}&limit=10&categoryId=${inputSearch.selectedCategory}&search=${inputSearch.search}`;
|
||||||
const result = await api.get(URL, {
|
const { data } = await api.get(URL, {
|
||||||
headers: {
|
headers: {
|
||||||
...(props.isAdmin && props.token != undefined) && { 'Authorization': props.token }
|
...(props.isAdmin && props.token != undefined) && { 'Authorization': props.token }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setLoadingFunctions(false);
|
setLoadingFunctions(false);
|
||||||
return result.data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
|
@ -36,7 +36,7 @@ const GenerateQuote = () => {
|
|||||||
const notyf = new Notyf.Notyf({
|
const notyf = new Notyf.Notyf({
|
||||||
duration: 5000
|
duration: 5000
|
||||||
});
|
});
|
||||||
copyToClipboard(`"${quote.quote}" - ${quote.author}`);
|
copyToClipboard(`"${quote?.quote}" - ${quote?.author}`);
|
||||||
notyf.success('Citation copiée dans le presse-papier!');
|
notyf.success('Citation copiée dans le presse-papier!');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,15 +50,15 @@ const GenerateQuote = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div style={{ marginTop: '20px' }} className="row justify-content-center">
|
<div style={{ marginTop: '20px' }} className="row justify-content-center">
|
||||||
<div className="col-24 text-center">
|
<div className="col-24 text-center">
|
||||||
<p>" {quote.quote} "</p>
|
<p>" {quote?.quote} "</p>
|
||||||
<p>- {quote.author}</p>
|
<p>- {quote?.author}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ marginBottom: '20px' }} className="row justify-content-center">
|
<div style={{ marginBottom: '20px' }} className="row justify-content-center">
|
||||||
<a
|
<a
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
href={`https://twitter.com/intent/tweet?text="${quote.quote}" - ${quote.author}&via=Divlo_FR&hashtags=citation,FunctionProject&url=https://function.divlo.fr/functions/randomQuote`}
|
href={`https://twitter.com/intent/tweet?text="${quote?.quote}" - ${quote?.author}&via=Divlo_FR&hashtags=citation,FunctionProject&url=https://function.divlo.fr/functions/randomQuote`}
|
||||||
className="btn btn-lg btn-primary"
|
className="btn btn-lg btn-primary"
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faTwitter} style={{ width: '1em' }} /> Twitter
|
<FontAwesomeIcon icon={faTwitter} style={{ width: '1em' }} /> Twitter
|
||||||
@ -68,26 +68,22 @@ const GenerateQuote = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pageQuotes = 1;
|
||||||
const QuoteList = () => {
|
const QuoteList = () => {
|
||||||
|
|
||||||
const [quotesData, setQuotesData] = useState({ hasMore: true, rows: [], totalItems: 0 });
|
const [quotesData, setQuotesData] = useState({ hasMore: true, rows: [], totalItems: 0 });
|
||||||
const [isLoadingQuotes, setLoadingQuotes] = useState(true);
|
const [isLoadingQuotes, setLoadingQuotes] = useState(true);
|
||||||
const [pageQuotes, setPageQuotes] = useState(1);
|
|
||||||
|
|
||||||
// Récupère les citations si la page change
|
// Récupère les citations initiales
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getQuotesData();
|
getQuotesData().then((data) => setQuotesData(data));
|
||||||
}, [pageQuotes]);
|
}, []);
|
||||||
|
|
||||||
const getQuotesData = async () => {
|
const getQuotesData = async () => {
|
||||||
setLoadingQuotes(true);
|
setLoadingQuotes(true);
|
||||||
const { data } = await api.get(`/quotes?limit=20page=${pageQuotes}`);
|
const { data } = await api.get(`/quotes?page=${pageQuotes}&limit=20`);
|
||||||
setQuotesData({
|
|
||||||
hasMore: data.hasMore,
|
|
||||||
rows: [...quotesData.rows, ...data.rows],
|
|
||||||
totalItems: data.totalItems
|
|
||||||
});
|
|
||||||
setLoadingQuotes(false);
|
setLoadingQuotes(false);
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Permet la pagination au scroll
|
// Permet la pagination au scroll
|
||||||
@ -97,7 +93,16 @@ const QuoteList = () => {
|
|||||||
if (observer.current) observer.current.disconnect();
|
if (observer.current) observer.current.disconnect();
|
||||||
observer.current = new IntersectionObserver((entries) => {
|
observer.current = new IntersectionObserver((entries) => {
|
||||||
if (entries[0].isIntersecting && quotesData.hasMore) {
|
if (entries[0].isIntersecting && quotesData.hasMore) {
|
||||||
setPageQuotes(pageQuotes + 1);
|
pageQuotes += 1;
|
||||||
|
getQuotesData().then((data) => {
|
||||||
|
setQuotesData((oldData) => {
|
||||||
|
return {
|
||||||
|
hasMore: data.hasMore,
|
||||||
|
rows: [...oldData.rows, ...data.rows],
|
||||||
|
totalItems: data.totalItems
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, { threshold: 1 });
|
}, { threshold: 1 });
|
||||||
if (node) observer.current.observe(node);
|
if (node) observer.current.observe(node);
|
||||||
|
Reference in New Issue
Block a user