|
2 | 2 | import React, { useEffect, useState } from 'react';
|
3 | 3 | import '@src/Popup.css';
|
4 | 4 | import { Library } from './types';
|
5 |
| -import { format } from 'timeago.js'; |
6 | 5 | const siteLink = 'https://mrpmohiburrahman.github.io/similar-react-native-libraries/';
|
7 |
| -const metadataCDN_Url = |
8 |
| - 'https://cdn.jsdelivr.net/gh/mrpmohiburrahman/similar-react-native-libraries@main/category-selector/data/metadata.json'; |
9 | 6 |
|
10 |
| -const MatchedItemsList: React.FC<{ lastUpdated: string; numLibraries: number; siteLink: string }> = ({ |
11 |
| - lastUpdated, |
12 |
| - numLibraries, |
13 |
| - siteLink, |
14 |
| -}) => { |
| 7 | +const MatchedItemsList: React.FC<{ siteLink: string }> = ({ siteLink }) => { |
15 | 8 | const [items, setItems] = useState<Library[]>([]);
|
16 | 9 | const [loading, setLoading] = useState(true);
|
17 | 10 |
|
@@ -44,22 +37,16 @@ const MatchedItemsList: React.FC<{ lastUpdated: string; numLibraries: number; si
|
44 | 37 |
|
45 | 38 | return (
|
46 | 39 | <>
|
47 |
| - <div className="info-button-container"> |
48 |
| - <div className="additional-info"> |
49 |
| - <p>{lastUpdated}</p> |
50 |
| - <p> |
51 |
| - Number of Sorted Libraries:<strong> {numLibraries}</strong> |
52 |
| - </p> |
53 |
| - </div> |
54 |
| - <button className="visit-site-button" onClick={() => window.open(siteLink, '_blank')}> |
55 |
| - Visit Site |
56 |
| - </button> |
57 |
| - </div> |
58 | 40 | <div className="header-button-container">
|
59 | 41 | <h1 className="text-xl">Matched Libraries</h1>
|
60 |
| - <button className="open-all-button" onClick={openAllLinks}> |
61 |
| - Open All Links |
62 |
| - </button> |
| 42 | + <div className="button-group"> |
| 43 | + <button className="visit-site-button" onClick={() => window.open(siteLink, '_blank')}> |
| 44 | + Visit Site |
| 45 | + </button> |
| 46 | + <button className="open-all-button" onClick={openAllLinks}> |
| 47 | + Open All Links |
| 48 | + </button> |
| 49 | + </div> |
63 | 50 | </div>
|
64 | 51 | <div className="item-list">
|
65 | 52 | {items.map((item, index) => (
|
@@ -87,40 +74,12 @@ const MatchedItemsList: React.FC<{ lastUpdated: string; numLibraries: number; si
|
87 | 74 | </>
|
88 | 75 | );
|
89 | 76 | };
|
90 |
| -const renderLastUpdatedMessage = (message: string) => { |
91 |
| - const parts = message.split('Last updated: '); |
92 |
| - if (parts.length > 1) { |
93 |
| - return ( |
94 |
| - <p> |
95 |
| - Last updated: <strong>{parts[1]}</strong> |
96 |
| - </p> |
97 |
| - ); |
98 |
| - } |
99 |
| - return <p>{message}</p>; |
100 |
| -}; |
101 | 77 |
|
102 | 78 | const Popup: React.FC = () => {
|
103 |
| - const [lastUpdated, setLastUpdated] = useState<string>(''); |
104 |
| - const [numLibraries, setNumLibraries] = useState<number>(0); |
105 |
| - |
106 |
| - useEffect(() => { |
107 |
| - fetch(metadataCDN_Url) |
108 |
| - .then(response => response.json()) |
109 |
| - .then(data => { |
110 |
| - setLastUpdated(`Last updated: ${format(new Date(data.lastUpdated))}`); |
111 |
| - setNumLibraries(data.numLibraries); |
112 |
| - }) |
113 |
| - .catch(error => console.error('Error fetching metadata:', error)); |
114 |
| - }, []); |
115 |
| - |
116 | 79 | return (
|
117 | 80 | <div className="App">
|
118 | 81 | <header className="App-header">
|
119 |
| - <MatchedItemsList |
120 |
| - lastUpdated={renderLastUpdatedMessage(lastUpdated)} |
121 |
| - numLibraries={numLibraries} |
122 |
| - siteLink={siteLink} |
123 |
| - /> |
| 82 | + <MatchedItemsList siteLink={siteLink} /> |
124 | 83 | </header>
|
125 | 84 | </div>
|
126 | 85 | );
|
|
0 commit comments