mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 23:15:36 +00:00
- Changement de structure de fichier - Ajout des favicons des sites - Suppression et mise à jour de dépendances - Ajout React-Icons pour gérer les icons - Amélioration du l'UI
82 lines
2.0 KiB
TypeScript
82 lines
2.0 KiB
TypeScript
import LinkTag from "next/link";
|
|
import { useState } from "react";
|
|
import {
|
|
AiFillDelete,
|
|
AiFillEdit,
|
|
AiFillStar,
|
|
AiOutlineStar,
|
|
} from "react-icons/ai";
|
|
|
|
import { Link } from "../../types";
|
|
import LinkFavicon from "./LinkFavicon";
|
|
|
|
import styles from "./links.module.scss";
|
|
|
|
export default function LinkItem({ link }: { link: Link }) {
|
|
const { id, name, url, favorite } = link;
|
|
const [isFavorite, setFavorite] = useState(favorite);
|
|
|
|
return (
|
|
<li className={styles["link"]} key={id}>
|
|
<LinkFavicon url={url} />
|
|
<LinkTag href={url} target={"_blank"} rel={"noreferrer"}>
|
|
<span className={styles["link-name"]}>
|
|
{name} {isFavorite && <AiFillStar color="#ffc107" />}
|
|
</span>
|
|
<LinkItemURL url={url} />
|
|
</LinkTag>
|
|
<div className={styles["controls"]}>
|
|
<div onClick={() => setFavorite((v) => !v)} className={styles["edit"]}>
|
|
{isFavorite ? (
|
|
<AiFillStar color="#ffc107" />
|
|
) : (
|
|
<AiOutlineStar color="#ffc107" />
|
|
)}
|
|
</div>
|
|
<LinkTag
|
|
href={`/link/edit/${id}`}
|
|
className={styles["edit"]}
|
|
title="Edit link"
|
|
>
|
|
<AiFillEdit />
|
|
</LinkTag>
|
|
<LinkTag
|
|
href={`/link/remove/${id}`}
|
|
className={styles["remove"]}
|
|
title="Remove link"
|
|
>
|
|
<AiFillDelete color="red" />
|
|
</LinkTag>
|
|
</div>
|
|
</li>
|
|
);
|
|
}
|
|
|
|
function LinkItemURL({ url }: { url: string }) {
|
|
try {
|
|
const { origin, pathname, search } = new URL(url);
|
|
let text = "";
|
|
|
|
if (pathname !== "/") {
|
|
text += pathname;
|
|
}
|
|
|
|
if (search !== "") {
|
|
if (text === "") {
|
|
text += "/";
|
|
}
|
|
text += search;
|
|
}
|
|
|
|
return (
|
|
<span className={styles["link-url"]}>
|
|
{origin}
|
|
<span className={styles["url-pathname"]}>{text}</span>
|
|
</span>
|
|
);
|
|
} catch (error) {
|
|
console.error("error", error);
|
|
return <span className={styles["link-url"]}>{url}</span>;
|
|
}
|
|
}
|