mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-21 17:09:09 +01:00
Track dialogs
This commit is contained in:
@@ -5,8 +5,17 @@ import { Alert } from './Alert';
|
||||
|
||||
export function useAlert() {
|
||||
const dialog = useDialog();
|
||||
return ({ title, body }: { title: DialogProps['title']; body: AlertProps['body'] }) =>
|
||||
return ({
|
||||
id,
|
||||
title,
|
||||
body,
|
||||
}: {
|
||||
id: string;
|
||||
title: DialogProps['title'];
|
||||
body: AlertProps['body'];
|
||||
}) =>
|
||||
dialog.show({
|
||||
id,
|
||||
title,
|
||||
hideX: true,
|
||||
size: 'sm',
|
||||
|
||||
@@ -6,16 +6,19 @@ import { Confirm } from './Confirm';
|
||||
export function useConfirm() {
|
||||
const dialog = useDialog();
|
||||
return ({
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
variant,
|
||||
}: {
|
||||
id: string;
|
||||
title: DialogProps['title'];
|
||||
description?: DialogProps['description'];
|
||||
variant: ConfirmProps['variant'];
|
||||
}) =>
|
||||
new Promise((onResult: ConfirmProps['onResult']) => {
|
||||
dialog.show({
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
hideX: true,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import type { CookieJar, HttpRequest } from '../lib/models';
|
||||
import type { HttpRequest } from '../lib/models';
|
||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||
import { usePrompt } from './usePrompt';
|
||||
import { requestsQueryKey } from './useRequests';
|
||||
@@ -17,6 +17,7 @@ export function useCreateCookieJar() {
|
||||
throw new Error("Cannot create cookie jar when there's no active workspace");
|
||||
}
|
||||
const name = await prompt({
|
||||
id: 'new-cookie-jar',
|
||||
name: 'name',
|
||||
title: 'New CookieJar',
|
||||
label: 'Name',
|
||||
|
||||
@@ -4,9 +4,8 @@ import { trackEvent } from '../lib/analytics';
|
||||
import type { Environment } from '../lib/models';
|
||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||
import { useAppRoutes } from './useAppRoutes';
|
||||
import { environmentsQueryKey, useEnvironments } from './useEnvironments';
|
||||
import { environmentsQueryKey } from './useEnvironments';
|
||||
import { usePrompt } from './usePrompt';
|
||||
import { useWorkspaces } from './useWorkspaces';
|
||||
|
||||
export function useCreateEnvironment() {
|
||||
const routes = useAppRoutes();
|
||||
@@ -17,6 +16,7 @@ export function useCreateEnvironment() {
|
||||
return useMutation<Environment, unknown, void>({
|
||||
mutationFn: async () => {
|
||||
const name = await prompt({
|
||||
id: 'new-environment',
|
||||
name: 'name',
|
||||
title: 'New Environment',
|
||||
label: 'Name',
|
||||
|
||||
@@ -17,6 +17,7 @@ export function useDeleteAnyRequest() {
|
||||
mutationFn: async (id) => {
|
||||
const request = await getRequest(id);
|
||||
const confirmed = await confirm({
|
||||
id: 'delete-request',
|
||||
title: 'Delete Request',
|
||||
variant: 'delete',
|
||||
description: (
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import type { CookieJar, Workspace } from '../lib/models';
|
||||
import type { CookieJar } from '../lib/models';
|
||||
import { useConfirm } from './useConfirm';
|
||||
import { cookieJarsQueryKey } from './useCookieJars';
|
||||
|
||||
@@ -13,6 +13,7 @@ export function useDeleteCookieJar(cookieJar: CookieJar | null) {
|
||||
return useMutation<CookieJar | null, string>({
|
||||
mutationFn: async () => {
|
||||
const confirmed = await confirm({
|
||||
id: 'delete-cookie-jar',
|
||||
title: 'Delete CookieJar',
|
||||
variant: 'delete',
|
||||
description: (
|
||||
|
||||
@@ -13,6 +13,7 @@ export function useDeleteEnvironment(environment: Environment | null) {
|
||||
return useMutation<Environment | null, string>({
|
||||
mutationFn: async () => {
|
||||
const confirmed = await confirm({
|
||||
id: 'delete-environment',
|
||||
title: 'Delete Environment',
|
||||
variant: 'delete',
|
||||
description: (
|
||||
|
||||
@@ -16,6 +16,7 @@ export function useDeleteFolder(id: string | null) {
|
||||
mutationFn: async () => {
|
||||
const folder = await getFolder(id);
|
||||
const confirmed = await confirm({
|
||||
id: 'delete-folder',
|
||||
title: 'Delete Folder',
|
||||
variant: 'delete',
|
||||
description: (
|
||||
|
||||
@@ -18,6 +18,7 @@ export function useDeleteWorkspace(workspace: Workspace | null) {
|
||||
return useMutation<Workspace | null, string>({
|
||||
mutationFn: async () => {
|
||||
const confirmed = await confirm({
|
||||
id: 'delete-workspace',
|
||||
title: 'Delete Workspace',
|
||||
variant: 'delete',
|
||||
description: (
|
||||
|
||||
@@ -11,7 +11,7 @@ export function useExportData() {
|
||||
|
||||
return useMutation({
|
||||
onError: (err: string) => {
|
||||
alert({ title: 'Export Failed', body: err });
|
||||
alert({ id: 'export-failed', title: 'Export Failed', body: err });
|
||||
},
|
||||
mutationFn: async () => {
|
||||
if (workspace == null) return;
|
||||
|
||||
@@ -22,7 +22,7 @@ export function useImportData() {
|
||||
|
||||
return useMutation({
|
||||
onError: (err: string) => {
|
||||
alert({ title: 'Import Failed', body: err });
|
||||
alert({ id: 'import-failed', title: 'Import Failed', body: err });
|
||||
},
|
||||
mutationFn: async () => {
|
||||
const selected = await open(openArgs);
|
||||
@@ -41,6 +41,7 @@ export function useImportData() {
|
||||
const importedWorkspace = imported.workspaces[0];
|
||||
|
||||
dialog.show({
|
||||
id: 'import-complete',
|
||||
title: 'Import Complete',
|
||||
size: 'sm',
|
||||
hideX: true,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Prompt } from './Prompt';
|
||||
export function usePrompt() {
|
||||
const dialog = useDialog();
|
||||
return ({
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
name,
|
||||
@@ -13,9 +14,11 @@ export function usePrompt() {
|
||||
defaultValue,
|
||||
placeholder,
|
||||
confirmLabel,
|
||||
}: Pick<DialogProps, 'title' | 'description'> & Omit<PromptProps, 'onResult' | 'onHide'>) =>
|
||||
}: Pick<DialogProps, 'title' | 'description'> &
|
||||
Omit<PromptProps, 'onResult' | 'onHide'> & { id: string }) =>
|
||||
new Promise((onResult: PromptProps['onResult']) => {
|
||||
dialog.show({
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
hideX: true,
|
||||
|
||||
@@ -39,6 +39,6 @@ export function useSendAnyRequest(options: { download?: boolean } = {}) {
|
||||
});
|
||||
},
|
||||
onSettled: () => trackEvent('HttpRequest', 'Send'),
|
||||
onError: (err) => alert({ title: 'Export Failed', body: err }),
|
||||
onError: (err) => alert({ id: 'send-failed', title: 'Send Failed', body: err }),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { useSendAnyRequest } from './useSendAnyRequest';
|
||||
|
||||
export function useSendManyRequests() {
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import { useEffect } from 'react';
|
||||
import { fallbackRequestName } from '../lib/fallbackRequestName';
|
||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||
import { useActiveRequest } from './useActiveRequest';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
// import { useEffect } from 'react';
|
||||
// import { fallbackRequestName } from '../lib/fallbackRequestName';
|
||||
// import { useActiveEnvironment } from './useActiveEnvironment';
|
||||
// import { useActiveRequest } from './useActiveRequest';
|
||||
// import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
|
||||
export function useSyncWindowTitle() {
|
||||
const activeRequest = useActiveRequest();
|
||||
const activeWorkspace = useActiveWorkspace();
|
||||
const activeEnvironment = useActiveEnvironment();
|
||||
useEffect(() => {
|
||||
let newTitle = activeWorkspace ? activeWorkspace.name : 'Yaak';
|
||||
if (activeEnvironment) {
|
||||
newTitle += ` [${activeEnvironment.name}]`;
|
||||
}
|
||||
if (activeRequest) {
|
||||
newTitle += ` – ${fallbackRequestName(activeRequest)}`;
|
||||
}
|
||||
|
||||
// TODO: This resets the stoplight position so we can't use it yet
|
||||
// appWindow.setTitle(newTitle).catch(console.error);
|
||||
}, [activeEnvironment, activeRequest, activeWorkspace]);
|
||||
// const activeRequest = useActiveRequest();
|
||||
// const activeWorkspace = useActiveWorkspace();
|
||||
// const activeEnvironment = useActiveEnvironment();
|
||||
// useEffect(() => {
|
||||
// let newTitle = activeWorkspace ? activeWorkspace.name : 'Yaak';
|
||||
// if (activeEnvironment) {
|
||||
// newTitle += ` [${activeEnvironment.name}]`;
|
||||
// }
|
||||
// if (activeRequest) {
|
||||
// newTitle += ` – ${fallbackRequestName(activeRequest)}`;
|
||||
// }
|
||||
//
|
||||
// // TODO: This resets the stoplight position so we can't use it yet
|
||||
// // appWindow.setTitle(newTitle).catch(console.error);
|
||||
// }, [activeEnvironment, activeRequest, activeWorkspace]);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import type { HttpRequest, Settings } from '../lib/models';
|
||||
import { requestsQueryKey } from './useRequests';
|
||||
import type { Settings } from '../lib/models';
|
||||
import { settingsQueryKey } from './useSettings';
|
||||
|
||||
export function useUpdateSettings() {
|
||||
|
||||
Reference in New Issue
Block a user