Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Added search bar

Steven Teye16d4b1e06a1
diff --git a/components/app/links/link-filters/search-bar.tsx b/components/app/links/link-filters/search-bar.tsx
new file mode 100644
index 0000000000..f164fac368
--- /dev/null
+++ b/components/app/links/link-filters/search-bar.tsx
@@ -0,0 +1,72 @@
+import { useRouter } from "next/router";
+import useSWR from "swr";
+import { fetcher } from "@/lib/utils";
+import { useDebounce } from "use-debounce";
+import { LinkProps } from "@/lib/types";
+import { LoadingSpinner, Search } from "@/components/shared/icons";
+import { useState } from "react";
+
+export default function SearchBar() {
+ const router = useRouter();
+ const { page, search } = router.query as { page?: string; search?: string };
+ const [debouncedSearch] = useDebounce(search, 500);
+ // const { data, isValidating } = useSWR<LinkProps[]>(
+ // `/api/conversations?type=${type}${page ? `&page=${page}` : ""}${
+ // debouncedSearch && debouncedSearch.length > 2
+ // ? `&search=${debouncedSearch}`
+ // : ""
+ // }`,
+ // fetcher,
+ // {
+ // keepPreviousData: true,
+ // }
+ // );
+ const isValidating = false;
+ const [focused, setFocused] = useState(false);
+ return (
+ <div className="relative mx-2 mt-10 rounded-md shadow-sm sm:max-w-screen-lg lg:mx-auto">
+ <div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-4">
+ {focused && search && isValidating ? (
+ <LoadingSpinner />
+ ) : (
+ <Search className="h-5 w-5 text-gray-400" />
+ )}
+ </div>
+ <input
+ type="text"
+ name="search"
+ autoComplete="off"
+ onFocus={() => setFocused(true)}
+ onBlur={() => setFocused(false)}
+ value={search || ""}
+ onChange={(e) => {
+ if (e.target.value === "") {
+ delete router.query.search;
+ router.replace(
+ {
+ query: {
+ ...router.query,
+ },
+ },
+ undefined,
+ { shallow: true },
+ );
+ } else {
+ router.replace(
+ {
+ query: {
+ ...router.query,
+ search: e.target.value,
+ },
+ },
+ undefined,
+ { shallow: true },
+ );
+ }
+ }}
+ className="block h-11 w-full rounded-md border-gray-200 pl-11 text-sm text-gray-600 transition-all placeholder:text-gray-400 focus:border-black focus:ring-0"
+ placeholder="Search..."
+ />
+ </div>
+ );
+}
diff --git a/components/shared/icons/index.tsx b/components/shared/icons/index.tsx
index 144a2aa3bc..2500006098 100644
--- a/components/shared/icons/index.tsx
+++ b/components/shared/icons/index.tsx
@@ -2,6 +2,7 @@
export { default as LoadingDots } from "./loading-dots";
export { default as LoadingCircle } from "./loading-circle";
+export { default as LoadingSpinner } from "./loading-spinner";
export { default as ExpandingArrow } from "./expanding-arrow";
export { default as Tick } from "./tick";
export { default as Copy } from "./copy";
diff --git a/components/shared/icons/loading-spinner.module.css b/components/shared/icons/loading-spinner.module.css
new file mode 100644
index 0000000000..8dc5706a2a
--- /dev/null
+++ b/components/shared/icons/loading-spinner.module.css
@@ -0,0 +1,79 @@
+.spinner {
+ color: gray;
+ display: inline-block;
+ position: relative;
+ width: 80px;
+ height: 80px;
+ transform: scale(0.3) translateX(-95px);
+}
+.spinner div {
+ transform-origin: 40px 40px;
+ animation: spinner 1.2s linear infinite;
+}
+.spinner div:after {
+ content: " ";
+ display: block;
+ position: absolute;
+ top: 3px;
+ left: 37px;
+ width: 6px;
+ height: 20px;
+ border-radius: 20%;
+ background: black;
+}
+.spinner div:nth-child(1) {
+ transform: rotate(0deg);
+ animation-delay: -1.1s;
+}
+.spinner div:nth-child(2) {
+ transform: rotate(30deg);
+ animation-delay: -1s;
+}
+.spinner div:nth-child(3) {
+ transform: rotate(60deg);
+ animation-delay: -0.9s;
+}
+.spinner div:nth-child(4) {
+ transform: rotate(90deg);
+ animation-delay: -0.8s;
+}
+.spinner div:nth-child(5) {
+ transform: rotate(120deg);
+ animation-delay: -0.7s;
+}
+.spinner div:nth-child(6) {
+ transform: rotate(150deg);
+ animation-delay: -0.6s;
+}
+.spinner div:nth-child(7) {
+ transform: rotate(180deg);
+ animation-delay: -0.5s;
+}
+.spinner div:nth-child(8) {
+ transform: rotate(210deg);
+ animation-delay: -0.4s;
+}
+.spinner div:nth-child(9) {
+ transform: rotate(240deg);
+ animation-delay: -0.3s;
+}
+.spinner div:nth-child(10) {
+ transform: rotate(270deg);
+ animation-delay: -0.2s;
+}
+.spinner div:nth-child(11) {
+ transform: rotate(300deg);
+ animation-delay: -0.1s;
+}
+.spinner div:nth-child(12) {
+ transform: rotate(330deg);
+ animation-delay: 0s;
+}
+@keyframes spinner {
+ 0% {
+ opacity: 1;
+ }
+ 100% {
+ opacity: 0;
+ }
+}
diff --git a/components/shared/icons/loading-spinner.tsx b/components/shared/icons/loading-spinner.tsx
new file mode 100644
index 0000000000..1c8e704aa4
--- /dev/null
+++ b/components/shared/icons/loading-spinner.tsx
@@ -0,0 +1,20 @@
+import styles from "./loading-spinner.module.css";
+
+export default function LoadingSpinner() {
+ return (
+ <div className={styles.spinner}>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ </div>
+ );
+}