Skip to content

Commit

Permalink
add browser tab indicator for coding and update favicon images
Browse files Browse the repository at this point in the history
  • Loading branch information
abi committed Mar 14, 2024
1 parent 87cf6f4 commit cdbb78e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
6 changes: 1 addition & 5 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link
rel="icon"
type="image/svg+xml"
href="https://picoapps.xyz/favicon.png"
/>
<link rel="icon" type="image/png" href="/favicon/main.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<!-- Google Fonts -->
Expand Down
Binary file added frontend/public/favicon/coding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/favicon/main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { Stack } from "./lib/stacks";
import { CodeGenerationModel } from "./lib/models";
import ModelSettingsSection from "./components/ModelSettingsSection";
import { extractHtml } from "./components/preview/extractHtml";
import useBrowserTabIndicator from "./hooks/useBrowserTabIndicator";

const IS_OPENAI_DOWN = false;

Expand Down Expand Up @@ -83,6 +84,9 @@ function App() {

const wsRef = useRef<WebSocket>(null);

// Indicate coding state using the browser tab's favicon and title
useBrowserTabIndicator(appState === AppState.CODING);

// When the user already has the settings in local storage, newly added keys
// do not get added to the settings so if it's falsy, we populate it with the default
// value
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/hooks/useBrowserTabIndicator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useEffect } from "react";

const CODING_SETTINGS = {
title: "Coding...",
favicon: "/favicon/coding.png",
};
const DEFAULT_SETTINGS = {
title: "Screenshot to Code",
favicon: "/favicon/main.png",
};

const useBrowserTabIndicator = (isCoding: boolean) => {
useEffect(() => {
const settings = isCoding ? CODING_SETTINGS : DEFAULT_SETTINGS;

// Set favicon
const faviconEl = document.querySelector(
"link[rel='icon']"
) as HTMLLinkElement | null;
if (faviconEl) {
faviconEl.href = settings.favicon;
}

// Set title
document.title = settings.title;
}, [isCoding]);
};

export default useBrowserTabIndicator;

0 comments on commit cdbb78e

Please sign in to comment.