-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from aidenpwnz/main
Feature/Searchbar
- Loading branch information
Showing
9 changed files
with
172 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import useSWR from "swr"; | ||
|
||
import Widget from "../widget"; | ||
import Block from "../block"; | ||
|
||
export default function Npm({ service }) { | ||
const config = service.widget; | ||
const { url } = config; | ||
|
||
const fetcher = async (reqUrl) => { | ||
const { url, username, password } = config; | ||
const loginUrl = `${url}/api/tokens`; | ||
const body = { identity: username, secret: password }; | ||
|
||
const res = await fetch(loginUrl, { | ||
method: "POST", | ||
body: JSON.stringify(body), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}) | ||
.then((response) => response.json()) | ||
.then( | ||
async (data) => | ||
await fetch(reqUrl, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: "Bearer " + data.token, | ||
}, | ||
}) | ||
); | ||
return res.json(); | ||
}; | ||
|
||
const { data: infoData, error: infoError } = useSWR(`${url}/api/nginx/proxy-hosts`, fetcher); | ||
|
||
console.log(infoData); | ||
|
||
if (infoError) { | ||
return <Widget error="NGINX Proxy Manager API Error" />; | ||
} | ||
|
||
if (!infoData) { | ||
return ( | ||
<Widget> | ||
<Block label="Running" /> | ||
<Block label="Stopped" /> | ||
<Block label="Total" /> | ||
</Widget> | ||
); | ||
} | ||
|
||
const enabled = infoData.filter((c) => c.enabled === 1).length; | ||
const disabled = infoData.filter((c) => c.enabled === 0).length; | ||
const total = infoData.length; | ||
|
||
return ( | ||
<Widget> | ||
<Block label="Enabled" value={enabled} /> | ||
<Block label="Disabled" value={disabled} /> | ||
<Block label="Total" value={total} /> | ||
</Widget> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useState } from "react"; | ||
import { FiSearch } from "react-icons/fi"; | ||
import { FcGoogle } from "react-icons/fc"; | ||
import { SiDuckduckgo } from "react-icons/si"; | ||
import { SiMicrosoftbing } from "react-icons/si"; | ||
|
||
export default function Search({ options, classN }) { | ||
const providers = ["google", "bing", "duckduckgo", "custom"]; | ||
const targets = ["_blank", "_parent", "_top"]; | ||
|
||
const [query, setQuery] = useState(""); | ||
|
||
function search() { | ||
if (!providers.includes(options.provider)) { | ||
return; | ||
} else { | ||
if (options.provider === "custom") { | ||
if (targets.includes(options.target)) { | ||
window.open(options.customdata.url + query, options.target); | ||
} else window.open(options.customdata.url + query, "_self"); | ||
} else { | ||
if (targets.includes(options.target)) { | ||
window.open(`https://www.${options.provider}.com/search?q=` + query, `${options.target}`); | ||
} else window.open(`https://www.${options.provider}.com/search?q=` + query, "_self"); | ||
} | ||
} | ||
|
||
setQuery(""); | ||
} | ||
|
||
if (!options || (options.provider === "custom" && !options.customdata)) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<form className={`grow flex-col relative h-8 my-4 md:my-0 min-w-full md:min-w-fit ${classN}`}> | ||
<div className="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none w-full text-theme-800 dark:text-theme-200"> | ||
{options.provider == "google" ? ( | ||
<FcGoogle className="text-theme-800 dark:text-theme-200 w-3 h-3" /> | ||
) : options.provider == "duckduckgo" ? ( | ||
<SiDuckduckgo className="text-theme-800 dark:text-theme-200 w-3 h-3" /> | ||
) : options.provider == "bing" ? ( | ||
<SiMicrosoftbing className="text-theme-800 dark:text-theme-200 w-3 h-3" /> | ||
) : options.provider == "custom" ? ( | ||
options.customdata.abbr.length > 2 ? ( | ||
options.customdata.abbr.substring(0, 2) | ||
) : ( | ||
options.customdata.abbr | ||
) | ||
) : ( | ||
"" | ||
)} | ||
</div> | ||
<input | ||
type="search" | ||
autoFocus | ||
className={`block ${ | ||
options.customdata && options.customdata.abbr && options.customdata.abbr.length > 1 ? "pl-12" : "pl-10" | ||
} w-full text-sm text-gray-900 bg-gray-50 rounded-full border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 h-full`} | ||
placeholder="Search..." | ||
onChange={(s) => setQuery(s.currentTarget.value)} | ||
required | ||
/> | ||
<button | ||
type="submit" | ||
onClick={search} | ||
className="text-white absolute right-0.5 bottom-0.5 bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-r-full text-sm px-4 py-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" | ||
> | ||
<FiSearch className="text-theme-200 dark:text-theme-200 w-3 h-3" /> | ||
</button> | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters