Skip to content

Commit e69acb6

Browse files
authored
Fix open link in export and UI state (#505)
1 parent 6d35014 commit e69acb6

File tree

6 files changed

+21
-34
lines changed

6 files changed

+21
-34
lines changed

apps/desktop/src-tauri/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,9 @@ async fn create_editor_instance(window: Window) -> Result<SerializedEditorInstan
10161016
#[tauri::command]
10171017
#[specta::specta]
10181018
async fn get_editor_meta(editor: WindowEditorInstance) -> Result<RecordingMeta, String> {
1019-
Ok(editor.meta().clone())
1019+
// Always reload the latest meta from disk using the project path
1020+
let path = editor.project_path.clone();
1021+
RecordingMeta::load_for_project(&path).map_err(|e| e.to_string())
10201022
}
10211023

10221024
#[tauri::command]

apps/desktop/src/routes/editor/Editor.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Button } from "@cap/ui-solid";
22
import { trackDeep } from "@solid-primitives/deep";
33
import { throttle } from "@solid-primitives/scheduled";
4-
import { useSearchParams } from "@solidjs/router";
54
import { createMutation } from "@tanstack/solid-query";
65
import { convertFileSrc } from "@tauri-apps/api/core";
76
import {
@@ -13,7 +12,6 @@ import {
1312
createSignal,
1413
on,
1514
onMount,
16-
untrack,
1715
} from "solid-js";
1816
import { createStore } from "solid-js/store";
1917

@@ -55,7 +53,7 @@ export function Editor() {
5553

5654
return {
5755
editorInstance,
58-
meta: ctx.metaQuery.data,
56+
meta: () => ctx.metaQuery.data,
5957
refetchMeta: async () => {
6058
await ctx.metaQuery.refetch();
6159
},

apps/desktop/src/routes/editor/ExportDialog.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createMutation,
66
createQuery,
77
keepPreviousData,
8+
useQueryClient,
89
} from "@tanstack/solid-query";
910
import { save as saveDialog } from "@tauri-apps/plugin-dialog";
1011
import { cx } from "cva";
@@ -26,6 +27,7 @@ import toast from "solid-toast";
2627
import Tooltip from "~/components/Tooltip";
2728
import { authStore } from "~/store";
2829
import { trackEvent } from "~/utils/analytics";
30+
import { exportVideo } from "~/utils/export";
2931
import {
3032
commands,
3133
events,
@@ -42,7 +44,6 @@ import {
4244
PopperContent,
4345
topSlideAnimateClasses,
4446
} from "./ui";
45-
import { exportVideo } from "~/utils/export";
4647

4748
export const COMPRESSION_OPTIONS: Array<{
4849
label: string;
@@ -96,6 +97,8 @@ export function ExportDialog() {
9697
refetchMeta,
9798
} = useEditorContext();
9899

100+
const queryClient = useQueryClient();
101+
99102
const [settings, setSettings] = makePersisted(
100103
createStore({
101104
format: "mp4" as "mp4" | "gif",
@@ -196,7 +199,7 @@ export function ExportDialog() {
196199

197200
const savePath = await saveDialog({
198201
filters: [{ name: "mp4 filter", extensions: ["mp4"] }],
199-
defaultPath: `~/Desktop/${meta.prettyName}.mp4`,
202+
defaultPath: `~/Desktop/${meta()?.prettyName}.mp4`,
200203
});
201204
if (!savePath) {
202205
setExportState(reconcile({ type: "idle" }));
@@ -297,7 +300,7 @@ export function ExportDialog() {
297300
setExportState({ type: "uploading", progress: 0 });
298301

299302
// Now proceed with upload
300-
const result = meta.sharing
303+
const result = meta()?.sharing
301304
? await commands.uploadExportedVideo(projectPath, "Reupload")
302305
: await commands.uploadExportedVideo(projectPath, {
303306
Initial: { pre_created_video: null },
@@ -794,7 +797,7 @@ export function ExportDialog() {
794797
>
795798
<div class="relative">
796799
<a
797-
href={meta.sharing?.link}
800+
href={meta()?.sharing?.link}
798801
target="_blank"
799802
rel="noreferrer"
800803
class="block"
@@ -805,7 +808,7 @@ export function ExportDialog() {
805808
setTimeout(() => {
806809
setCopyPressed(false);
807810
}, 2000);
808-
navigator.clipboard.writeText(meta.sharing?.link!);
811+
navigator.clipboard.writeText(meta()?.sharing?.link!);
809812
}}
810813
variant="lightdark"
811814
class="flex gap-2 justify-center items-center"

apps/desktop/src/routes/editor/ShareButton.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { Button } from "@cap/ui-solid";
22
import { createMutation } from "@tanstack/solid-query";
3-
import { createEffect, createResource, createSignal, Show } from "solid-js";
3+
import { createSignal, Show } from "solid-js";
44
import { createStore, produce, reconcile } from "solid-js/store";
55

66
import Tooltip from "~/components/Tooltip";
77
import { createProgressBar } from "~/routes/editor/utils";
88
import { authStore } from "~/store";
9+
import { exportVideo } from "~/utils/export";
910
import { commands, events } from "~/utils/tauri";
1011
import { useEditorContext } from "./context";
1112
import { RESOLUTION_OPTIONS } from "./Header";
1213
import { Dialog, DialogContent } from "./ui";
13-
import { exportVideo } from "~/utils/export";
1414

1515
function ShareButton() {
1616
const { editorInstance, meta } = useEditorContext();
@@ -86,7 +86,7 @@ function ShareButton() {
8686
setUploadState({ type: "uploading", progress: 0 });
8787

8888
// Now proceed with upload
89-
const result = meta?.sharing
89+
const result = meta()?.sharing
9090
? await commands.uploadExportedVideo(projectPath, "Reupload")
9191
: await commands.uploadExportedVideo(projectPath, {
9292
Initial: { pre_created_video: null },
@@ -136,7 +136,7 @@ function ShareButton() {
136136

137137
return (
138138
<div class="relative">
139-
<Show when={meta?.sharing}>
139+
<Show when={meta()?.sharing}>
140140
{(sharing) => {
141141
const url = () => new URL(sharing().link);
142142

apps/desktop/src/routes/editor/context.ts

+3-19
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export type RenderState =
5454

5555
export const [EditorContextProvider, useEditorContext] = createContextProvider(
5656
(props: {
57-
meta: TransformedMeta;
57+
meta: () => TransformedMeta | undefined;
5858
editorInstance: SerializedEditorInstance;
5959
refetchMeta(): Promise<void>;
6060
}) => {
@@ -108,21 +108,6 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider(
108108
: undefined
109109
);
110110

111-
// This is used in ShareButton.tsx to notify the component that the metadata has changed, from ExportDialog.tsx
112-
// When a video is uploaded, the metadata is updated
113-
114-
const [lastMetaUpdate, setLastMetaUpdate] = createSignal<{
115-
videoId: string;
116-
timestamp: number;
117-
} | null>(null);
118-
119-
const metaUpdateStore = {
120-
notifyUpdate: (videoId: string) => {
121-
setLastMetaUpdate({ videoId, timestamp: Date.now() });
122-
},
123-
getLastUpdate: lastMetaUpdate,
124-
};
125-
126111
createEffect(
127112
on(
128113
() => editorState.playing,
@@ -221,9 +206,6 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider(
221206
setDialog,
222207
project,
223208
setProject,
224-
metaUpdateStore,
225-
lastMetaUpdate,
226-
setLastMetaUpdate,
227209
projectHistory: createStoreHistory(project, setProject),
228210
editorState,
229211
setEditorState,
@@ -312,6 +294,8 @@ export const [EditorInstanceContextProvider, useEditorInstanceContext] =
312294
queryFn: editorInstance()
313295
? () => commands.getEditorMeta().then(transformMeta)
314296
: skipToken,
297+
cacheTime: 0,
298+
staleTime: 0,
315299
}));
316300

317301
return {

packages/ui/src/components/input/Input.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
1414
"flex px-4 w-full text-sm font-thin transition-all duration-200 text-gray-12 bg-gray-1 border-gray-4 outline-0 focus:bg-gray-3",
1515
"rounded-xl hover:bg-gray-2 hover:border-gray-5 h-[48px] placeholder:text-gray-8 py-[14px] border-[1px] focus:border-gray-5",
1616
"file:border-0 file:bg-transparent file:text-sm file:font-medium",
17-
"disabled:cursor-not-allowed disabled:bg-gray-2 disabled:bg-gray-2 disabled:text-gray-9 placeholder:transition-all",
18-
"ring-0 ring-gray-2 focus:ring-1 focus:ring-gray-12 focus:ring-offset-2 ring-offset-gray-1 placeholder:text-gray-12 placeholder:duration-200",
17+
"disabled:cursor-not-allowed disabled:bg-gray-2 disabled:text-gray-9 placeholder:transition-all",
18+
"ring-0 ring-gray-2 focus:ring-1 focus:ring-gray-12 focus:ring-offset-2 ring-offset-gray-1 hover:placeholder:text-gray-12 placeholder:duration-200",
1919
className
2020
)}
2121
ref={ref}

0 commit comments

Comments
 (0)