mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 23:31:21 +02:00
Better active workspace change notification
This commit is contained in:
16
index.html
16
index.html
@@ -4,20 +4,20 @@
|
|||||||
<meta charset="UTF-8"/>
|
<meta charset="UTF-8"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
<title>Yaak App</title>
|
<title>Yaak App</title>
|
||||||
<!-- <script src="http://localhost:8097"></script>-->
|
<script src="http://localhost:8097"></script>
|
||||||
|
|
||||||
<!-- Certain elements like webview (and maybe <select>?) will use background
|
<!-- Certain elements like webview (and maybe <select>?) will use background
|
||||||
color depending on document background color-->
|
color depending on document background color-->
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
html, body {
|
html, body {
|
||||||
background-color: #1b1a29;
|
background-color: #1b1a29;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import { getCurrent } from '@tauri-apps/api/webviewWindow';
|
import { getCurrent } from '@tauri-apps/api/webviewWindow';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useActiveWorkspace } from '../hooks/useActiveWorkspace';
|
import { useAtiveWorkspaceChangedToast } from '../hooks/useAtiveWorkspaceChangedToast';
|
||||||
import { useClipboardText } from '../hooks/useClipboardText';
|
import { useClipboardText } from '../hooks/useClipboardText';
|
||||||
import { useCommandPalette } from '../hooks/useCommandPalette';
|
import { useCommandPalette } from '../hooks/useCommandPalette';
|
||||||
import { cookieJarsQueryKey } from '../hooks/useCookieJars';
|
import { cookieJarsQueryKey } from '../hooks/useCookieJars';
|
||||||
@@ -33,12 +33,8 @@ import { monokaiProDefault } from '../lib/theme/themes/monokai-pro';
|
|||||||
import { rosePineDefault } from '../lib/theme/themes/rose-pine';
|
import { rosePineDefault } from '../lib/theme/themes/rose-pine';
|
||||||
import { yaakDark } from '../lib/theme/themes/yaak';
|
import { yaakDark } from '../lib/theme/themes/yaak';
|
||||||
import { getThemeCSS } from '../lib/theme/window';
|
import { getThemeCSS } from '../lib/theme/window';
|
||||||
import { InlineCode } from './core/InlineCode';
|
|
||||||
import { useToast } from './ToastContext';
|
|
||||||
|
|
||||||
export function GlobalHooks() {
|
export function GlobalHooks() {
|
||||||
const toast = useToast();
|
|
||||||
|
|
||||||
// Include here so they always update, even if no component references them
|
// Include here so they always update, even if no component references them
|
||||||
useRecentWorkspaces();
|
useRecentWorkspaces();
|
||||||
useRecentEnvironments();
|
useRecentEnvironments();
|
||||||
@@ -48,21 +44,7 @@ export function GlobalHooks() {
|
|||||||
useSyncThemeToDocument();
|
useSyncThemeToDocument();
|
||||||
useCommandPalette();
|
useCommandPalette();
|
||||||
useNotificationToast();
|
useNotificationToast();
|
||||||
|
useAtiveWorkspaceChangedToast();
|
||||||
const activeWorkspace = useActiveWorkspace();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (activeWorkspace == null) return;
|
|
||||||
toast.show({
|
|
||||||
id: 'workspace-changed',
|
|
||||||
timeout: 3000,
|
|
||||||
message: (
|
|
||||||
<>
|
|
||||||
Switched workspace to <InlineCode>{activeWorkspace.name}</InlineCode>
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
});
|
|
||||||
}, [activeWorkspace, toast]);
|
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { wasUpdatedExternally } = useRequestUpdateKey(null);
|
const { wasUpdatedExternally } = useRequestUpdateKey(null);
|
||||||
|
|||||||
30
src-web/hooks/useAtiveWorkspaceChangedToast.tsx
Normal file
30
src-web/hooks/useAtiveWorkspaceChangedToast.tsx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { InlineCode } from '../components/core/InlineCode';
|
||||||
|
import { useToast } from '../components/ToastContext';
|
||||||
|
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||||
|
|
||||||
|
export function useAtiveWorkspaceChangedToast() {
|
||||||
|
const toast = useToast();
|
||||||
|
const activeWorkspace = useActiveWorkspace();
|
||||||
|
const [id, setId] = useState<string | null>(activeWorkspace?.id ?? null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Early return if same or invalid active workspace
|
||||||
|
if (id === activeWorkspace?.id || activeWorkspace == null) return;
|
||||||
|
|
||||||
|
setId(activeWorkspace?.id ?? null);
|
||||||
|
|
||||||
|
// Don't notify on first load
|
||||||
|
if (id === null) return;
|
||||||
|
|
||||||
|
toast.show({
|
||||||
|
id: 'workspace-changed',
|
||||||
|
timeout: 3000,
|
||||||
|
message: (
|
||||||
|
<>
|
||||||
|
Switched workspace to <InlineCode>{activeWorkspace.name}</InlineCode>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}, [activeWorkspace, id, toast]);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user