Skip to content

Commit

Permalink
feat: add environment indicator
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jul 18, 2024
1 parent b99222b commit b833889
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"build": "npm run typecheck && electron-vite build --outDir=dist && electron-forge make",
"build:web": "vite build",
"dev": "electron-vite dev --outDir=dist",
"dev:debug": "export DEBUG=true && vite --debug",
"dev:web": "vite",
"lint": "eslint",
"lint:fix": "eslint --fix",
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { execSync } from "node:child_process"

export const getGitHash = () => {
try {
execSync("git rev-parse HEAD").toString().trim()
return execSync("git rev-parse HEAD").toString().trim()
} catch (e) {
console.error("Failed to get git hash", e)
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/common/ErrorElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function ErrorElement() {
<div className="drag-region fixed inset-x-0 top-0 h-12" />
<div className="center flex flex-col">
<i className="i-mgc-bug-cute-re size-12 text-red-400" />
<h2 className="mt-12 text-2xl">
<h2 className="mb-4 mt-12 text-2xl">
Sorry, the app has encountered an error
</h2>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare global {
export const SENTRY_RELEASE: { id: string }
export const APP_DEV_CWD: string
export const GIT_COMMIT_SHA: string
export const DEBUG: boolean
export interface Window {
SENTRY_RELEASE: typeof SENTRY_RELEASE
}
Expand Down
16 changes: 16 additions & 0 deletions src/renderer/src/modules/app/EnvironmentIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@renderer/components/ui/tooltip"

export const EnvironmentIndicator = () => (
<Tooltip>
<TooltipTrigger>
<div className="fixed bottom-0 left-0 rounded-tr bg-theme-accent px-1 py-0.5 text-xs text-white">
{import.meta.env.MODE}
</div>
</TooltipTrigger>
<TooltipContent>{import.meta.env.BASE_URL}</TooltipContent>
</Tooltip>
)
19 changes: 13 additions & 6 deletions src/renderer/src/modules/feed-column/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ const useBackHome = (active: number) => {

const useUnreadByView = () => {
useAuthQuery(Queries.subscription.byView())
const idByView = useSubscriptionStore((state) =>
state.dataIdByView,
)
const idByView = useSubscriptionStore((state) => state.dataIdByView)
const totalUnread = useFeedUnreadStore((state) => {
const unread = {} as Record<number, number>

for (const view in idByView) {
unread[view] = idByView[view].reduce((acc, feedId) => acc + (state.data[feedId] || 0), 0)
unread[view] = idByView[view].reduce(
(acc, feedId) => acc + (state.data[feedId] || 0),
0,
)
}
return unread
})
Expand Down Expand Up @@ -156,7 +157,7 @@ export function FeedColumn({ children }: PropsWithChildren) {
>
{normalStyle && (
<div
className="flex items-center gap-1 text-xl font-bold"
className="relative flex items-center gap-1 text-xl font-bold"
onClick={(e) => {
e.stopPropagation()
navigateBackHome()
Expand Down Expand Up @@ -201,7 +202,13 @@ export function FeedColumn({ children }: PropsWithChildren) {
}}
>
{item.icon}
<div className="text-[10px] font-medium leading-none">{unreadByView[index] > 99 ? <span className="-mr-0.5">99+</span> : unreadByView[index]}</div>
<div className="text-[10px] font-medium leading-none">
{unreadByView[index] > 99 ? (
<span className="-mr-0.5">99+</span>
) : (
unreadByView[index]
)}
</div>
</ActionButton>
))}
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/src/pages/(main)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DeclarativeModal } from "@renderer/components/ui/modal/stacked/declarat
import { NoopChildren } from "@renderer/components/ui/modal/stacked/utils"
import { RootPortal } from "@renderer/components/ui/portal"
import { preventDefault } from "@renderer/lib/dom"
import { EnvironmentIndicator } from "@renderer/modules/app/EnvironmentIndicator"
import { NetworkStatusIndicator } from "@renderer/modules/app/NetworkStatusIndicator"
import { LoginModalContent } from "@renderer/modules/auth/LoginModalContent"
import { FeedColumn } from "@renderer/modules/feed-column"
Expand All @@ -22,11 +23,14 @@ export function Component() {
{APP_VERSION?.[0] === "0" && (
<div className="pointer-events-none absolute bottom-3 w-full text-center text-xs opacity-20">
Early Access
{" "}
{GIT_COMMIT_SHA ? `(${GIT_COMMIT_SHA.slice(0, 7).toUpperCase()})` : ""}
</div>
)}
<AutoUpdater />

<NetworkStatusIndicator />
{!import.meta.env.PROD && <EnvironmentIndicator />}
</FeedColumn>
</div>
{/* NOTE: tabIndex for main element can get by `document.activeElement` */}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/store/entry/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class EntryActions {
...state,
starIds: newStarIds,
}))

// Update database
runTransactionInScope(() => {
EntryService.upsertMany(entries)
Expand Down
16 changes: 9 additions & 7 deletions src/renderer/src/store/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ export const createZustandStore =
name: string,
) =>
(store: T) => {
const newStore = createWithEqualityFn(
devtools(store, {
enabled: import.meta.env.DEV,
name,
}),
shallow,
)
const newStore = import.meta.env.DEV ?
createWithEqualityFn(
devtools(store, {
enabled: DEBUG,
name,
}),
shallow,
) :
createWithEqualityFn(store, shallow)

storeMap[name] = newStore
window.store =
Expand Down
6 changes: 5 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default defineConfig({
APP_NAME: JSON.stringify(pkg.name),
APP_DEV_CWD: JSON.stringify(process.cwd()),

GIT_COMMIT_SHA: JSON.stringify(process.env.VERCEL_GIT_COMMIT_SHA || getGitHash()),
GIT_COMMIT_SHA: JSON.stringify(
process.env.VERCEL_GIT_COMMIT_SHA || getGitHash(),
),

DEBUG: process.env.DEBUG === "true",
},
})

0 comments on commit b833889

Please sign in to comment.