Skip to content

Commit 2100bfe

Browse files
feat: add disable_favicons option
Signed-off-by: Henry Gressmann <[email protected]>
1 parent 96d56bb commit 2100bfe

File tree

8 files changed

+39
-6
lines changed

8 files changed

+39
-6
lines changed

src/config.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ pub struct Config {
3434
#[serde(default = "default_port")]
3535
pub port: u16,
3636

37+
#[serde(default)]
38+
// don't load favicons from the duckduckgo api
39+
pub disable_favicons: bool,
40+
3741
#[serde(default = "default_data_dir")]
3842
pub data_dir: String,
3943

@@ -49,7 +53,14 @@ pub fn default_maxmind_edition() -> Option<String> {
4953

5054
impl Default for Config {
5155
fn default() -> Self {
52-
Self { base_url: default_base(), port: default_port(), data_dir: default_data_dir(), geoip: None, duckdb: None }
56+
Self {
57+
base_url: default_base(),
58+
port: default_port(),
59+
data_dir: default_data_dir(),
60+
geoip: None,
61+
duckdb: None,
62+
disable_favicons: false,
63+
}
5364
}
5465
}
5566

src/web/routes/dashboard.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,21 @@ struct DimensionTableRow {
6363
icon: Option<String>,
6464
}
6565

66+
#[derive(Object)]
67+
#[oai(rename_all = "camelCase")]
68+
struct ConfigResponse {
69+
disable_favicons: bool,
70+
}
71+
6672
pub struct DashboardAPI;
6773

6874
#[OpenApi]
6975
impl DashboardAPI {
76+
#[oai(path = "/config", method = "get")]
77+
async fn config_handler(&self, Data(app): Data<&Liwan>) -> ApiResult<Json<ConfigResponse>> {
78+
Ok(Json(ConfigResponse { disable_favicons: app.config.disable_favicons }))
79+
}
80+
7081
#[oai(path = "/project/:project_id/earliest", method = "get")]
7182
async fn project_earliest_handler(
7283
&self,

web/src/api/dashboard.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

web/src/api/hooks.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ import type { DateRange } from "./ranges";
1010
export const useMe = () => {
1111
const { data, isLoading } = useQuery({
1212
queryKey: ["me"],
13-
staleTime: 60 * 1000, // 1 minute
13+
refetchOnMount: false,
1414
queryFn: () => api["/api/dashboard/auth/me"].get().json(),
1515
});
1616
return { role: data?.role, username: data?.username, isLoading };
1717
};
1818

19+
export const useConfig = () => {
20+
const { data, isLoading } = useQuery({
21+
queryKey: ["config"],
22+
refetchOnMount: false,
23+
queryFn: () => api["/api/dashboard/config"].get().json(),
24+
});
25+
return { config: data, isLoading };
26+
};
27+
1928
export const useProjects = () => {
2029
const { data, isLoading, error } = useQuery({
2130
queryKey: ["projects"],

web/src/components/icons.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styles from "./icons.module.css";
44
import { SiAndroid, SiBadoo, SiBluesky, SiDouban, SiDribbble, SiDuckduckgo, SiFacebook, SiFirefox, SiFlickr, SiFoursquare, SiGithub, SiGoogle, SiGooglechrome, SiInstagram, SiIos, SiLastdotfm, SiLinkedin, SiLinux, SiLivejournal, SiMacos, SiMaildotru, SiMastodon, SiOdnoklassniki, SiOpera, SiPinterest, SiPixelfed, SiReddit, SiRenren, SiSafari, SiSinaweibo, SiSkyrock, SiSnapchat, SiSourceforge, SiStackoverflow, SiTelegram, SiTencentqq, SiThreads, SiTiktok, SiTumblr, SiTwitch, SiV2ex, SiViadeo, SiVimeo, SiVk, SiWorkplace, SiX, SiXing, SiYcombinator, SiYoutube } from "@icons-pack/react-simple-icons";
55
// biome-ignore format:
66
import { AppWindowIcon, EarthIcon, LayoutGridIcon, MonitorIcon, SearchIcon, SmartphoneIcon, TabletIcon } from "lucide-react";
7+
import { useConfig } from "../api";
78
// biome-ignore format:
89
const brandIcons = { tencentqq: SiTencentqq, foursquare: SiFoursquare, vk: SiVk, sinaweibo: SiSinaweibo, telegram: SiTelegram, pixelfed: SiPixelfed, workplace: SiWorkplace, x: SiX, threads: SiThreads, Ru: SiMaildotru, News: SiYcombinator, tiktok: SiTiktok, facebook: SiFacebook, lastdotfm: SiLastdotfm, linkedin: SiLinkedin, dribbble: SiDribbble, reddit: SiReddit, flickr: SiFlickr, github: SiGithub, pinterest: SiPinterest, skyrock: SiSkyrock, stackoverflow: SiStackoverflow, bluesky: SiBluesky, livejournal: SiLivejournal, v2ex: SiV2ex, douban: SiDouban, renren: SiRenren, tumblr: SiTumblr, snapchat: SiSnapchat, badoo: SiBadoo, youtube: SiYoutube, instagram: SiInstagram, viadeo: SiViadeo, odnoklassniki: SiOdnoklassniki, vimeo: SiVimeo, mastodon: SiMastodon, sourceforge: SiSourceforge, twitch: SiTwitch, xing: SiXing, google: SiGoogle, duckduckgo: SiDuckduckgo,};
910

@@ -98,6 +99,9 @@ export const Favicon = ({
9899
}: IconProps & {
99100
fqdn: string;
100101
}) => {
102+
const config = useConfig();
103+
if (config.isLoading || config.config?.disableFavicons) return <SearchIcon size={size} />;
104+
101105
fqdn = fqdn.replace(/[^a-zA-Z0-9.-]/g, "");
102106
return <img src={`https://icons.duckduckgo.com/ip3/${fqdn}.ico`} alt="favicon" height={size} width={size} />;
103107
};

web/src/components/project.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const Project = () => {
3030
const [filters, setFilters] = useState<DimensionFilter[]>([]);
3131
const [metric, setMetric] = useLocalStorage<Metric>("metric", "views");
3232

33-
const [rangeString, setRangeString] = useLocalStorage<string>("date-range", "yearToDate");
33+
const [rangeString, setRangeString] = useLocalStorage<string>("date-range", "last7Days");
3434
const range = useMemo(() => DateRange.deserialize(rangeString), [rangeString]);
3535

3636
useEffect(() => {

web/src/components/project/range.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export const SelectRange = ({
1818
const detailsRef = useRef<HTMLDetailsElement>(null);
1919

2020
const handleSelect = (range: DateRange) => () => {
21-
console.log("range", range, detailsRef.current);
2221
if (detailsRef.current) detailsRef.current.open = false;
2322
onSelect(range);
2423
};

web/src/components/settings/dialogs.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ export const EditPassword = ({ user, trigger }: { user: UserResponse; trigger: J
471471
e.stopPropagation();
472472
const form = e.target as HTMLFormElement;
473473
const { password, confirm } = Object.fromEntries(new FormData(form)) as { password: string; confirm: string };
474-
console.log(password, confirm);
475474

476475
if (password !== confirm) {
477476
confirmPasswordRef.current?.setCustomValidity("Passwords do not match");

0 commit comments

Comments
 (0)