mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 16:21:25 +02:00
Track dialogs
This commit is contained in:
@@ -12,28 +12,30 @@ use crate::{is_dev, models};
|
|||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub enum AnalyticsResource {
|
pub enum AnalyticsResource {
|
||||||
App,
|
App,
|
||||||
Sidebar,
|
|
||||||
Workspace,
|
|
||||||
CookieJar,
|
CookieJar,
|
||||||
|
Dialog,
|
||||||
Environment,
|
Environment,
|
||||||
Folder,
|
Folder,
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
KeyValue,
|
KeyValue,
|
||||||
|
Sidebar,
|
||||||
|
Workspace,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnalyticsResource {
|
impl AnalyticsResource {
|
||||||
pub fn from_str(s: &str) -> Option<AnalyticsResource> {
|
pub fn from_str(s: &str) -> Option<AnalyticsResource> {
|
||||||
match s {
|
match s {
|
||||||
"App" => Some(AnalyticsResource::App),
|
"App" => Some(AnalyticsResource::App),
|
||||||
"Sidebar" => Some(AnalyticsResource::Sidebar),
|
"Dialog" => Some(AnalyticsResource::Dialog),
|
||||||
"Workspace" => Some(AnalyticsResource::Workspace),
|
|
||||||
"Environment" => Some(AnalyticsResource::Environment),
|
|
||||||
"CookieJar" => Some(AnalyticsResource::CookieJar),
|
"CookieJar" => Some(AnalyticsResource::CookieJar),
|
||||||
|
"Environment" => Some(AnalyticsResource::Environment),
|
||||||
"Folder" => Some(AnalyticsResource::Folder),
|
"Folder" => Some(AnalyticsResource::Folder),
|
||||||
"HttpRequest" => Some(AnalyticsResource::HttpRequest),
|
"HttpRequest" => Some(AnalyticsResource::HttpRequest),
|
||||||
"HttpResponse" => Some(AnalyticsResource::HttpResponse),
|
"HttpResponse" => Some(AnalyticsResource::HttpResponse),
|
||||||
"KeyValue" => Some(AnalyticsResource::KeyValue),
|
"KeyValue" => Some(AnalyticsResource::KeyValue),
|
||||||
|
"Sidebar" => Some(AnalyticsResource::Sidebar),
|
||||||
|
"Workspace" => Some(AnalyticsResource::Workspace),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,37 +43,41 @@ impl AnalyticsResource {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub enum AnalyticsAction {
|
pub enum AnalyticsAction {
|
||||||
|
Create,
|
||||||
|
Delete,
|
||||||
|
DeleteMany,
|
||||||
|
Duplicate,
|
||||||
|
Export,
|
||||||
|
Hide,
|
||||||
|
Import,
|
||||||
Launch,
|
Launch,
|
||||||
LaunchFirst,
|
LaunchFirst,
|
||||||
LaunchUpdate,
|
LaunchUpdate,
|
||||||
Create,
|
Send,
|
||||||
|
Show,
|
||||||
|
Toggle,
|
||||||
Update,
|
Update,
|
||||||
Upsert,
|
Upsert,
|
||||||
Delete,
|
|
||||||
DeleteMany,
|
|
||||||
Send,
|
|
||||||
Toggle,
|
|
||||||
Duplicate,
|
|
||||||
Import,
|
|
||||||
Export,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnalyticsAction {
|
impl AnalyticsAction {
|
||||||
pub fn from_str(s: &str) -> Option<AnalyticsAction> {
|
pub fn from_str(s: &str) -> Option<AnalyticsAction> {
|
||||||
match s {
|
match s {
|
||||||
|
"Create" => Some(AnalyticsAction::Create),
|
||||||
|
"Delete" => Some(AnalyticsAction::Delete),
|
||||||
|
"DeleteMany" => Some(AnalyticsAction::DeleteMany),
|
||||||
|
"Duplicate" => Some(AnalyticsAction::Duplicate),
|
||||||
|
"Export" => Some(AnalyticsAction::Export),
|
||||||
|
"Hide" => Some(AnalyticsAction::Hide),
|
||||||
|
"Import" => Some(AnalyticsAction::Import),
|
||||||
"Launch" => Some(AnalyticsAction::Launch),
|
"Launch" => Some(AnalyticsAction::Launch),
|
||||||
"LaunchFirst" => Some(AnalyticsAction::LaunchFirst),
|
"LaunchFirst" => Some(AnalyticsAction::LaunchFirst),
|
||||||
"LaunchUpdate" => Some(AnalyticsAction::LaunchUpdate),
|
"LaunchUpdate" => Some(AnalyticsAction::LaunchUpdate),
|
||||||
"Create" => Some(AnalyticsAction::Create),
|
"Send" => Some(AnalyticsAction::Send),
|
||||||
|
"Show" => Some(AnalyticsAction::Show),
|
||||||
|
"Toggle" => Some(AnalyticsAction::Toggle),
|
||||||
"Update" => Some(AnalyticsAction::Update),
|
"Update" => Some(AnalyticsAction::Update),
|
||||||
"Upsert" => Some(AnalyticsAction::Upsert),
|
"Upsert" => Some(AnalyticsAction::Upsert),
|
||||||
"Delete" => Some(AnalyticsAction::Delete),
|
|
||||||
"DeleteMany" => Some(AnalyticsAction::DeleteMany),
|
|
||||||
"Send" => Some(AnalyticsAction::Send),
|
|
||||||
"Duplicate" => Some(AnalyticsAction::Duplicate),
|
|
||||||
"Toggle" => Some(AnalyticsAction::Toggle),
|
|
||||||
"Import" => Some(AnalyticsAction::Import),
|
|
||||||
"Export" => Some(AnalyticsAction::Export),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,32 +86,35 @@ impl AnalyticsAction {
|
|||||||
fn resource_name(resource: AnalyticsResource) -> &'static str {
|
fn resource_name(resource: AnalyticsResource) -> &'static str {
|
||||||
match resource {
|
match resource {
|
||||||
AnalyticsResource::App => "app",
|
AnalyticsResource::App => "app",
|
||||||
AnalyticsResource::Sidebar => "sidebar",
|
|
||||||
AnalyticsResource::Workspace => "workspace",
|
|
||||||
AnalyticsResource::Environment => "environment",
|
|
||||||
AnalyticsResource::CookieJar => "cookie_jar",
|
AnalyticsResource::CookieJar => "cookie_jar",
|
||||||
|
AnalyticsResource::Dialog => "dialog",
|
||||||
|
AnalyticsResource::Environment => "environment",
|
||||||
AnalyticsResource::Folder => "folder",
|
AnalyticsResource::Folder => "folder",
|
||||||
AnalyticsResource::HttpRequest => "http_request",
|
AnalyticsResource::HttpRequest => "http_request",
|
||||||
AnalyticsResource::HttpResponse => "http_response",
|
AnalyticsResource::HttpResponse => "http_response",
|
||||||
AnalyticsResource::KeyValue => "key_value",
|
AnalyticsResource::KeyValue => "key_value",
|
||||||
|
AnalyticsResource::Sidebar => "sidebar",
|
||||||
|
AnalyticsResource::Workspace => "workspace",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn action_name(action: AnalyticsAction) -> &'static str {
|
fn action_name(action: AnalyticsAction) -> &'static str {
|
||||||
match action {
|
match action {
|
||||||
|
AnalyticsAction::Create => "create",
|
||||||
|
AnalyticsAction::Delete => "delete",
|
||||||
|
AnalyticsAction::DeleteMany => "delete_many",
|
||||||
|
AnalyticsAction::Duplicate => "duplicate",
|
||||||
|
AnalyticsAction::Export => "export",
|
||||||
|
AnalyticsAction::Hide => "hide",
|
||||||
|
AnalyticsAction::Import => "import",
|
||||||
AnalyticsAction::Launch => "launch",
|
AnalyticsAction::Launch => "launch",
|
||||||
AnalyticsAction::LaunchFirst => "launch_first",
|
AnalyticsAction::LaunchFirst => "launch_first",
|
||||||
AnalyticsAction::LaunchUpdate => "launch_update",
|
AnalyticsAction::LaunchUpdate => "launch_update",
|
||||||
AnalyticsAction::Create => "create",
|
AnalyticsAction::Send => "send",
|
||||||
|
AnalyticsAction::Show => "show",
|
||||||
|
AnalyticsAction::Toggle => "toggle",
|
||||||
AnalyticsAction::Update => "update",
|
AnalyticsAction::Update => "update",
|
||||||
AnalyticsAction::Upsert => "upsert",
|
AnalyticsAction::Upsert => "upsert",
|
||||||
AnalyticsAction::Delete => "delete",
|
|
||||||
AnalyticsAction::DeleteMany => "delete_many",
|
|
||||||
AnalyticsAction::Send => "send",
|
|
||||||
AnalyticsAction::Duplicate => "duplicate",
|
|
||||||
AnalyticsAction::Toggle => "toggle",
|
|
||||||
AnalyticsAction::Import => "import",
|
|
||||||
AnalyticsAction::Export => "export",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export function CookieDropdown() {
|
|||||||
leftSlot: <Icon icon="pencil" />,
|
leftSlot: <Icon icon="pencil" />,
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
const name = await prompt({
|
const name = await prompt({
|
||||||
|
id: 'rename-cookie-jar',
|
||||||
title: 'Rename Cookie Jar',
|
title: 'Rename Cookie Jar',
|
||||||
description: (
|
description: (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { createContext, useContext, useMemo, useState } from 'react';
|
import React, { createContext, useContext, useMemo, useState } from 'react';
|
||||||
|
import { trackEvent } from '../lib/analytics';
|
||||||
import type { DialogProps } from './core/Dialog';
|
import type { DialogProps } from './core/Dialog';
|
||||||
import { Dialog } from './core/Dialog';
|
import { Dialog } from './core/Dialog';
|
||||||
|
|
||||||
@@ -7,15 +8,13 @@ type DialogEntry = {
|
|||||||
render: ({ hide }: { hide: () => void }) => React.ReactNode;
|
render: ({ hide }: { hide: () => void }) => React.ReactNode;
|
||||||
} & Pick<DialogProps, 'title' | 'description' | 'hideX' | 'className' | 'size'>;
|
} & Pick<DialogProps, 'title' | 'description' | 'hideX' | 'className' | 'size'>;
|
||||||
|
|
||||||
type DialogEntryOptionalId = Omit<DialogEntry, 'id'> & { id?: string };
|
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
dialogs: DialogEntry[];
|
dialogs: DialogEntry[];
|
||||||
actions: Actions;
|
actions: Actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Actions {
|
interface Actions {
|
||||||
show: (d: DialogEntryOptionalId) => void;
|
show: (d: DialogEntry) => void;
|
||||||
toggle: (d: DialogEntry) => void;
|
toggle: (d: DialogEntry) => void;
|
||||||
hide: (id: string) => void;
|
hide: (id: string) => void;
|
||||||
}
|
}
|
||||||
@@ -27,12 +26,11 @@ export const DialogProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
const [dialogs, setDialogs] = useState<State['dialogs']>([]);
|
const [dialogs, setDialogs] = useState<State['dialogs']>([]);
|
||||||
const actions = useMemo<Actions>(
|
const actions = useMemo<Actions>(
|
||||||
() => ({
|
() => ({
|
||||||
show({ id: oid, ...props }: DialogEntryOptionalId) {
|
show({ id, ...props }: DialogEntry) {
|
||||||
const id = oid ?? Math.random().toString(36).slice(2);
|
trackEvent('Dialog', 'Show', { id });
|
||||||
setDialogs((a) => [...a.filter((d) => d.id !== id), { id, ...props }]);
|
setDialogs((a) => [...a.filter((d) => d.id !== id), { id, ...props }]);
|
||||||
},
|
},
|
||||||
toggle({ id: oid, ...props }: DialogEntryOptionalId) {
|
toggle({ id, ...props }: DialogEntry) {
|
||||||
const id = oid ?? Math.random().toString(36).slice(2);
|
|
||||||
if (dialogs.some((d) => d.id === id)) this.hide(id);
|
if (dialogs.some((d) => d.id === id)) this.hide(id);
|
||||||
else this.show({ id, ...props });
|
else this.show({ id, ...props });
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ const EnvironmentEditor = function ({
|
|||||||
leftSlot: <Icon icon="pencil" size="sm" />,
|
leftSlot: <Icon icon="pencil" size="sm" />,
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
const name = await prompt({
|
const name = await prompt({
|
||||||
|
id: 'rename-environment',
|
||||||
title: 'Rename Environment',
|
title: 'Rename Environment',
|
||||||
description: (
|
description: (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ export const RequestMethodDropdown = memo(function RequestMethodDropdown({
|
|||||||
leftSlot: <Icon icon="sparkles" />,
|
leftSlot: <Icon icon="sparkles" />,
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
const newMethod = await prompt({
|
const newMethod = await prompt({
|
||||||
|
id: 'custom-method',
|
||||||
label: 'Http Method',
|
label: 'Http Method',
|
||||||
name: 'httpMethod',
|
name: 'httpMethod',
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
|
|||||||
@@ -4,9 +4,7 @@ import { memo, useCallback, useMemo, useState } from 'react';
|
|||||||
import { createGlobalState } from 'react-use';
|
import { createGlobalState } from 'react-use';
|
||||||
import { useActiveRequest } from '../hooks/useActiveRequest';
|
import { useActiveRequest } from '../hooks/useActiveRequest';
|
||||||
import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey';
|
import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey';
|
||||||
import { useSettings } from '../hooks/useSettings';
|
|
||||||
import { useUpdateRequest } from '../hooks/useUpdateRequest';
|
import { useUpdateRequest } from '../hooks/useUpdateRequest';
|
||||||
import { useUpdateSettings } from '../hooks/useUpdateSettings';
|
|
||||||
import { tryFormatJson } from '../lib/formatters';
|
import { tryFormatJson } from '../lib/formatters';
|
||||||
import type { HttpHeader, HttpRequest, HttpUrlParameter } from '../lib/models';
|
import type { HttpHeader, HttpRequest, HttpUrlParameter } from '../lib/models';
|
||||||
import {
|
import {
|
||||||
@@ -22,13 +20,10 @@ import {
|
|||||||
} from '../lib/models';
|
} from '../lib/models';
|
||||||
import { BasicAuth } from './BasicAuth';
|
import { BasicAuth } from './BasicAuth';
|
||||||
import { BearerAuth } from './BearerAuth';
|
import { BearerAuth } from './BearerAuth';
|
||||||
import { Checkbox } from './core/Checkbox';
|
|
||||||
import { CountBadge } from './core/CountBadge';
|
import { CountBadge } from './core/CountBadge';
|
||||||
import { Editor } from './core/Editor';
|
import { Editor } from './core/Editor';
|
||||||
import { Input } from './core/Input';
|
|
||||||
import { VStack } from './core/Stacks';
|
|
||||||
import { TabContent, Tabs } from './core/Tabs/Tabs';
|
|
||||||
import type { TabItem } from './core/Tabs/Tabs';
|
import type { TabItem } from './core/Tabs/Tabs';
|
||||||
|
import { TabContent, Tabs } from './core/Tabs/Tabs';
|
||||||
import { EmptyStateText } from './EmptyStateText';
|
import { EmptyStateText } from './EmptyStateText';
|
||||||
import { FormMultipartEditor } from './FormMultipartEditor';
|
import { FormMultipartEditor } from './FormMultipartEditor';
|
||||||
import { FormUrlencodedEditor } from './FormUrlencodedEditor';
|
import { FormUrlencodedEditor } from './FormUrlencodedEditor';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { invoke, shell } from '@tauri-apps/api';
|
import { shell } from '@tauri-apps/api';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import type { HttpResponse } from '../lib/models';
|
import type { HttpResponse } from '../lib/models';
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export function SettingsDropdown() {
|
|||||||
leftSlot: <Icon icon="keyboard" />,
|
leftSlot: <Icon icon="keyboard" />,
|
||||||
onSelect: () => {
|
onSelect: () => {
|
||||||
dialog.show({
|
dialog.show({
|
||||||
id: 'hotkey-help',
|
id: 'hotkey',
|
||||||
title: 'Keyboard Shortcuts',
|
title: 'Keyboard Shortcuts',
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
render: () => <KeyboardShortcutsDialog />,
|
render: () => <KeyboardShortcutsDialog />,
|
||||||
@@ -67,6 +67,7 @@ export function SettingsDropdown() {
|
|||||||
leftSlot: <Icon icon="folderInput" />,
|
leftSlot: <Icon icon="folderInput" />,
|
||||||
onSelect: () => {
|
onSelect: () => {
|
||||||
dialog.show({
|
dialog.show({
|
||||||
|
id: 'import',
|
||||||
title: 'Import Data',
|
title: 'Import Data',
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
render: ({ hide }) => {
|
render: ({ hide }) => {
|
||||||
@@ -104,6 +105,7 @@ export function SettingsDropdown() {
|
|||||||
const hasUpdate: boolean = await invoke('check_for_updates');
|
const hasUpdate: boolean = await invoke('check_for_updates');
|
||||||
if (!hasUpdate) {
|
if (!hasUpdate) {
|
||||||
alert({
|
alert({
|
||||||
|
id: 'no-updates',
|
||||||
title: 'No Updates',
|
title: 'No Updates',
|
||||||
body: 'You are currently up to date',
|
body: 'You are currently up to date',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -613,6 +613,7 @@ const SidebarItem = forwardRef(function SidebarItem(
|
|||||||
leftSlot: <Icon icon="pencil" />,
|
leftSlot: <Icon icon="pencil" />,
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
const name = await prompt({
|
const name = await prompt({
|
||||||
|
id: 'rename-folder',
|
||||||
title: 'Rename Folder',
|
title: 'Rename Folder',
|
||||||
description: (
|
description: (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import classNames from 'classnames';
|
|
||||||
import type { EditorView } from 'codemirror';
|
import type { EditorView } from 'codemirror';
|
||||||
import type { FormEvent } from 'react';
|
import type { FormEvent } from 'react';
|
||||||
import { memo, useCallback, useRef, useState } from 'react';
|
import { memo, useCallback, useRef, useState } from 'react';
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
|
|||||||
leftSlot: <Icon icon="pencil" />,
|
leftSlot: <Icon icon="pencil" />,
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
const name = await prompt({
|
const name = await prompt({
|
||||||
|
id: 'rename-workspace',
|
||||||
title: 'Rename Workspace',
|
title: 'Rename Workspace',
|
||||||
description: (
|
description: (
|
||||||
<>
|
<>
|
||||||
@@ -131,6 +132,7 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
|
|||||||
leftSlot: <Icon icon="plus" />,
|
leftSlot: <Icon icon="plus" />,
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
const name = await prompt({
|
const name = await prompt({
|
||||||
|
id: 'new-workspace',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
defaultValue: 'My Workspace',
|
defaultValue: 'My Workspace',
|
||||||
|
|||||||
@@ -5,8 +5,17 @@ import { Alert } from './Alert';
|
|||||||
|
|
||||||
export function useAlert() {
|
export function useAlert() {
|
||||||
const dialog = useDialog();
|
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({
|
dialog.show({
|
||||||
|
id,
|
||||||
title,
|
title,
|
||||||
hideX: true,
|
hideX: true,
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
|
|||||||
@@ -6,16 +6,19 @@ import { Confirm } from './Confirm';
|
|||||||
export function useConfirm() {
|
export function useConfirm() {
|
||||||
const dialog = useDialog();
|
const dialog = useDialog();
|
||||||
return ({
|
return ({
|
||||||
|
id,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
variant,
|
variant,
|
||||||
}: {
|
}: {
|
||||||
|
id: string;
|
||||||
title: DialogProps['title'];
|
title: DialogProps['title'];
|
||||||
description?: DialogProps['description'];
|
description?: DialogProps['description'];
|
||||||
variant: ConfirmProps['variant'];
|
variant: ConfirmProps['variant'];
|
||||||
}) =>
|
}) =>
|
||||||
new Promise((onResult: ConfirmProps['onResult']) => {
|
new Promise((onResult: ConfirmProps['onResult']) => {
|
||||||
dialog.show({
|
dialog.show({
|
||||||
|
id,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
hideX: true,
|
hideX: true,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { invoke } from '@tauri-apps/api';
|
import { invoke } from '@tauri-apps/api';
|
||||||
import { trackEvent } from '../lib/analytics';
|
import { trackEvent } from '../lib/analytics';
|
||||||
import type { CookieJar, HttpRequest } from '../lib/models';
|
import type { HttpRequest } from '../lib/models';
|
||||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||||
import { usePrompt } from './usePrompt';
|
import { usePrompt } from './usePrompt';
|
||||||
import { requestsQueryKey } from './useRequests';
|
import { requestsQueryKey } from './useRequests';
|
||||||
@@ -17,6 +17,7 @@ export function useCreateCookieJar() {
|
|||||||
throw new Error("Cannot create cookie jar when there's no active workspace");
|
throw new Error("Cannot create cookie jar when there's no active workspace");
|
||||||
}
|
}
|
||||||
const name = await prompt({
|
const name = await prompt({
|
||||||
|
id: 'new-cookie-jar',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
title: 'New CookieJar',
|
title: 'New CookieJar',
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ import { trackEvent } from '../lib/analytics';
|
|||||||
import type { Environment } from '../lib/models';
|
import type { Environment } from '../lib/models';
|
||||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||||
import { useAppRoutes } from './useAppRoutes';
|
import { useAppRoutes } from './useAppRoutes';
|
||||||
import { environmentsQueryKey, useEnvironments } from './useEnvironments';
|
import { environmentsQueryKey } from './useEnvironments';
|
||||||
import { usePrompt } from './usePrompt';
|
import { usePrompt } from './usePrompt';
|
||||||
import { useWorkspaces } from './useWorkspaces';
|
|
||||||
|
|
||||||
export function useCreateEnvironment() {
|
export function useCreateEnvironment() {
|
||||||
const routes = useAppRoutes();
|
const routes = useAppRoutes();
|
||||||
@@ -17,6 +16,7 @@ export function useCreateEnvironment() {
|
|||||||
return useMutation<Environment, unknown, void>({
|
return useMutation<Environment, unknown, void>({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const name = await prompt({
|
const name = await prompt({
|
||||||
|
id: 'new-environment',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
title: 'New Environment',
|
title: 'New Environment',
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export function useDeleteAnyRequest() {
|
|||||||
mutationFn: async (id) => {
|
mutationFn: async (id) => {
|
||||||
const request = await getRequest(id);
|
const request = await getRequest(id);
|
||||||
const confirmed = await confirm({
|
const confirmed = await confirm({
|
||||||
|
id: 'delete-request',
|
||||||
title: 'Delete Request',
|
title: 'Delete Request',
|
||||||
variant: 'delete',
|
variant: 'delete',
|
||||||
description: (
|
description: (
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|||||||
import { invoke } from '@tauri-apps/api';
|
import { invoke } from '@tauri-apps/api';
|
||||||
import { InlineCode } from '../components/core/InlineCode';
|
import { InlineCode } from '../components/core/InlineCode';
|
||||||
import { trackEvent } from '../lib/analytics';
|
import { trackEvent } from '../lib/analytics';
|
||||||
import type { CookieJar, Workspace } from '../lib/models';
|
import type { CookieJar } from '../lib/models';
|
||||||
import { useConfirm } from './useConfirm';
|
import { useConfirm } from './useConfirm';
|
||||||
import { cookieJarsQueryKey } from './useCookieJars';
|
import { cookieJarsQueryKey } from './useCookieJars';
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ export function useDeleteCookieJar(cookieJar: CookieJar | null) {
|
|||||||
return useMutation<CookieJar | null, string>({
|
return useMutation<CookieJar | null, string>({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const confirmed = await confirm({
|
const confirmed = await confirm({
|
||||||
|
id: 'delete-cookie-jar',
|
||||||
title: 'Delete CookieJar',
|
title: 'Delete CookieJar',
|
||||||
variant: 'delete',
|
variant: 'delete',
|
||||||
description: (
|
description: (
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export function useDeleteEnvironment(environment: Environment | null) {
|
|||||||
return useMutation<Environment | null, string>({
|
return useMutation<Environment | null, string>({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const confirmed = await confirm({
|
const confirmed = await confirm({
|
||||||
|
id: 'delete-environment',
|
||||||
title: 'Delete Environment',
|
title: 'Delete Environment',
|
||||||
variant: 'delete',
|
variant: 'delete',
|
||||||
description: (
|
description: (
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export function useDeleteFolder(id: string | null) {
|
|||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const folder = await getFolder(id);
|
const folder = await getFolder(id);
|
||||||
const confirmed = await confirm({
|
const confirmed = await confirm({
|
||||||
|
id: 'delete-folder',
|
||||||
title: 'Delete Folder',
|
title: 'Delete Folder',
|
||||||
variant: 'delete',
|
variant: 'delete',
|
||||||
description: (
|
description: (
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export function useDeleteWorkspace(workspace: Workspace | null) {
|
|||||||
return useMutation<Workspace | null, string>({
|
return useMutation<Workspace | null, string>({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const confirmed = await confirm({
|
const confirmed = await confirm({
|
||||||
|
id: 'delete-workspace',
|
||||||
title: 'Delete Workspace',
|
title: 'Delete Workspace',
|
||||||
variant: 'delete',
|
variant: 'delete',
|
||||||
description: (
|
description: (
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export function useExportData() {
|
|||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
onError: (err: string) => {
|
onError: (err: string) => {
|
||||||
alert({ title: 'Export Failed', body: err });
|
alert({ id: 'export-failed', title: 'Export Failed', body: err });
|
||||||
},
|
},
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
if (workspace == null) return;
|
if (workspace == null) return;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export function useImportData() {
|
|||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
onError: (err: string) => {
|
onError: (err: string) => {
|
||||||
alert({ title: 'Import Failed', body: err });
|
alert({ id: 'import-failed', title: 'Import Failed', body: err });
|
||||||
},
|
},
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const selected = await open(openArgs);
|
const selected = await open(openArgs);
|
||||||
@@ -41,6 +41,7 @@ export function useImportData() {
|
|||||||
const importedWorkspace = imported.workspaces[0];
|
const importedWorkspace = imported.workspaces[0];
|
||||||
|
|
||||||
dialog.show({
|
dialog.show({
|
||||||
|
id: 'import-complete',
|
||||||
title: 'Import Complete',
|
title: 'Import Complete',
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
hideX: true,
|
hideX: true,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Prompt } from './Prompt';
|
|||||||
export function usePrompt() {
|
export function usePrompt() {
|
||||||
const dialog = useDialog();
|
const dialog = useDialog();
|
||||||
return ({
|
return ({
|
||||||
|
id,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
name,
|
name,
|
||||||
@@ -13,9 +14,11 @@ export function usePrompt() {
|
|||||||
defaultValue,
|
defaultValue,
|
||||||
placeholder,
|
placeholder,
|
||||||
confirmLabel,
|
confirmLabel,
|
||||||
}: Pick<DialogProps, 'title' | 'description'> & Omit<PromptProps, 'onResult' | 'onHide'>) =>
|
}: Pick<DialogProps, 'title' | 'description'> &
|
||||||
|
Omit<PromptProps, 'onResult' | 'onHide'> & { id: string }) =>
|
||||||
new Promise((onResult: PromptProps['onResult']) => {
|
new Promise((onResult: PromptProps['onResult']) => {
|
||||||
dialog.show({
|
dialog.show({
|
||||||
|
id,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
hideX: true,
|
hideX: true,
|
||||||
|
|||||||
@@ -39,6 +39,6 @@ export function useSendAnyRequest(options: { download?: boolean } = {}) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
onSettled: () => trackEvent('HttpRequest', 'Send'),
|
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 { useMutation } from '@tanstack/react-query';
|
||||||
import { trackEvent } from '../lib/analytics';
|
|
||||||
import { useSendAnyRequest } from './useSendAnyRequest';
|
import { useSendAnyRequest } from './useSendAnyRequest';
|
||||||
|
|
||||||
export function useSendManyRequests() {
|
export function useSendManyRequests() {
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
import { useEffect } from 'react';
|
// import { useEffect } from 'react';
|
||||||
import { fallbackRequestName } from '../lib/fallbackRequestName';
|
// import { fallbackRequestName } from '../lib/fallbackRequestName';
|
||||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
// import { useActiveEnvironment } from './useActiveEnvironment';
|
||||||
import { useActiveRequest } from './useActiveRequest';
|
// import { useActiveRequest } from './useActiveRequest';
|
||||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
// import { useActiveWorkspace } from './useActiveWorkspace';
|
||||||
|
|
||||||
export function useSyncWindowTitle() {
|
export function useSyncWindowTitle() {
|
||||||
const activeRequest = useActiveRequest();
|
// const activeRequest = useActiveRequest();
|
||||||
const activeWorkspace = useActiveWorkspace();
|
// const activeWorkspace = useActiveWorkspace();
|
||||||
const activeEnvironment = useActiveEnvironment();
|
// const activeEnvironment = useActiveEnvironment();
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
let newTitle = activeWorkspace ? activeWorkspace.name : 'Yaak';
|
// let newTitle = activeWorkspace ? activeWorkspace.name : 'Yaak';
|
||||||
if (activeEnvironment) {
|
// if (activeEnvironment) {
|
||||||
newTitle += ` [${activeEnvironment.name}]`;
|
// newTitle += ` [${activeEnvironment.name}]`;
|
||||||
}
|
// }
|
||||||
if (activeRequest) {
|
// if (activeRequest) {
|
||||||
newTitle += ` – ${fallbackRequestName(activeRequest)}`;
|
// newTitle += ` – ${fallbackRequestName(activeRequest)}`;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// TODO: This resets the stoplight position so we can't use it yet
|
// // TODO: This resets the stoplight position so we can't use it yet
|
||||||
// appWindow.setTitle(newTitle).catch(console.error);
|
// // appWindow.setTitle(newTitle).catch(console.error);
|
||||||
}, [activeEnvironment, activeRequest, activeWorkspace]);
|
// }, [activeEnvironment, activeRequest, activeWorkspace]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { invoke } from '@tauri-apps/api';
|
import { invoke } from '@tauri-apps/api';
|
||||||
import type { HttpRequest, Settings } from '../lib/models';
|
import type { Settings } from '../lib/models';
|
||||||
import { requestsQueryKey } from './useRequests';
|
|
||||||
import { settingsQueryKey } from './useSettings';
|
import { settingsQueryKey } from './useSettings';
|
||||||
|
|
||||||
export function useUpdateSettings() {
|
export function useUpdateSettings() {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { invoke } from '@tauri-apps/api';
|
|||||||
export function trackEvent(
|
export function trackEvent(
|
||||||
resource:
|
resource:
|
||||||
| 'App'
|
| 'App'
|
||||||
|
| 'Dialog'
|
||||||
| 'CookieJar'
|
| 'CookieJar'
|
||||||
| 'Sidebar'
|
| 'Sidebar'
|
||||||
| 'Workspace'
|
| 'Workspace'
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
import { invoke } from '@tauri-apps/api';
|
import { invoke } from '@tauri-apps/api';
|
||||||
import type {
|
import type { CookieJar, Environment, Folder, HttpRequest, Settings, Workspace } from './models';
|
||||||
Cookie,
|
|
||||||
CookieJar,
|
|
||||||
Environment,
|
|
||||||
Folder,
|
|
||||||
HttpRequest,
|
|
||||||
Settings,
|
|
||||||
Workspace,
|
|
||||||
} from './models';
|
|
||||||
|
|
||||||
export async function getSettings(): Promise<Settings> {
|
export async function getSettings(): Promise<Settings> {
|
||||||
return invoke('get_settings', {});
|
return invoke('get_settings', {});
|
||||||
|
|||||||
Reference in New Issue
Block a user