Fix(ish) multiwindow updates

This commit is contained in:
Gregory Schier
2023-03-29 11:15:37 -07:00
parent cd5ae6691c
commit b91d1b8b3c
4 changed files with 59 additions and 35 deletions

View File

@@ -125,8 +125,12 @@ export const RequestPane = memo(function RequestPane({ style, fullHeight, classN
[],
);
const forceUpdateKey =
activeRequest?.updatedBy === appWindow.label ? undefined : activeRequest?.updatedAt;
const forceUpdateKey = useMemo(() => {
if (activeRequest == null) return undefined;
if (activeRequest.updatedBy === appWindow.label) return appWindow.label;
return `${appWindow.label}::${activeRequest?.updatedAt}`;
}, [activeRequest]);
console.log('FORCE UPDATE KEY', forceUpdateKey);
return (
<div

View File

@@ -1,5 +1,6 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { invoke } from '@tauri-apps/api';
import { appWindow } from '@tauri-apps/api/window';
import type { HttpRequest } from '../lib/models';
import { getRequest } from '../lib/store';
import { requestsQueryKey } from './useRequests';
@@ -20,6 +21,9 @@ export function useUpdateRequest(id: string | null) {
const request = await getRequest(id);
if (request === null) return;
// Sync updatedBy so that the UI doesn't think the update is coming from elsewhere
request.updatedBy = appWindow.label;
const newRequest = typeof v === 'function' ? v(request) : { ...request, ...v };
queryClient.setQueryData(
requestsQueryKey(request?.workspaceId),

View File

@@ -2,7 +2,7 @@ export interface BaseModel {
readonly id: string;
readonly createdAt: string;
readonly updatedAt: string;
readonly updatedBy: string;
updatedBy: string;
}
export interface Workspace extends BaseModel {