Skip to content

Fix open link in export and UI state #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,9 @@ async fn create_editor_instance(window: Window) -> Result<SerializedEditorInstan
#[tauri::command]
#[specta::specta]
async fn get_editor_meta(editor: WindowEditorInstance) -> Result<RecordingMeta, String> {
Ok(editor.meta().clone())
// Always reload the latest meta from disk using the project path
let path = editor.project_path.clone();
RecordingMeta::load_for_project(&path).map_err(|e| e.to_string())
}

#[tauri::command]
Expand Down
4 changes: 1 addition & 3 deletions apps/desktop/src/routes/editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Button } from "@cap/ui-solid";
import { trackDeep } from "@solid-primitives/deep";
import { throttle } from "@solid-primitives/scheduled";
import { useSearchParams } from "@solidjs/router";
import { createMutation } from "@tanstack/solid-query";
import { convertFileSrc } from "@tauri-apps/api/core";
import {
Expand All @@ -13,7 +12,6 @@ import {
createSignal,
on,
onMount,
untrack,
} from "solid-js";
import { createStore } from "solid-js/store";

Expand Down Expand Up @@ -55,7 +53,7 @@ export function Editor() {

return {
editorInstance,
meta: ctx.metaQuery.data,
meta: () => ctx.metaQuery.data,
refetchMeta: async () => {
await ctx.metaQuery.refetch();
},
Expand Down
13 changes: 8 additions & 5 deletions apps/desktop/src/routes/editor/ExportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createMutation,
createQuery,
keepPreviousData,
useQueryClient,
} from "@tanstack/solid-query";
import { save as saveDialog } from "@tauri-apps/plugin-dialog";
import { cx } from "cva";
Expand All @@ -26,6 +27,7 @@ import toast from "solid-toast";
import Tooltip from "~/components/Tooltip";
import { authStore } from "~/store";
import { trackEvent } from "~/utils/analytics";
import { exportVideo } from "~/utils/export";
import {
commands,
events,
Expand All @@ -42,7 +44,6 @@ import {
PopperContent,
topSlideAnimateClasses,
} from "./ui";
import { exportVideo } from "~/utils/export";

export const COMPRESSION_OPTIONS: Array<{
label: string;
Expand Down Expand Up @@ -96,6 +97,8 @@ export function ExportDialog() {
refetchMeta,
} = useEditorContext();

const queryClient = useQueryClient();

const [settings, setSettings] = makePersisted(
createStore({
format: "mp4" as "mp4" | "gif",
Expand Down Expand Up @@ -196,7 +199,7 @@ export function ExportDialog() {

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

// Now proceed with upload
const result = meta.sharing
const result = meta()?.sharing
? await commands.uploadExportedVideo(projectPath, "Reupload")
: await commands.uploadExportedVideo(projectPath, {
Initial: { pre_created_video: null },
Expand Down Expand Up @@ -794,7 +797,7 @@ export function ExportDialog() {
>
<div class="relative">
<a
href={meta.sharing?.link}
href={meta()?.sharing?.link}
target="_blank"
rel="noreferrer"
class="block"
Expand All @@ -805,7 +808,7 @@ export function ExportDialog() {
setTimeout(() => {
setCopyPressed(false);
}, 2000);
navigator.clipboard.writeText(meta.sharing?.link!);
navigator.clipboard.writeText(meta()?.sharing?.link!);
}}
variant="lightdark"
class="flex gap-2 justify-center items-center"
Expand Down
8 changes: 4 additions & 4 deletions apps/desktop/src/routes/editor/ShareButton.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Button } from "@cap/ui-solid";
import { createMutation } from "@tanstack/solid-query";
import { createEffect, createResource, createSignal, Show } from "solid-js";
import { createSignal, Show } from "solid-js";
import { createStore, produce, reconcile } from "solid-js/store";

import Tooltip from "~/components/Tooltip";
import { createProgressBar } from "~/routes/editor/utils";
import { authStore } from "~/store";
import { exportVideo } from "~/utils/export";
import { commands, events } from "~/utils/tauri";
import { useEditorContext } from "./context";
import { RESOLUTION_OPTIONS } from "./Header";
import { Dialog, DialogContent } from "./ui";
import { exportVideo } from "~/utils/export";

function ShareButton() {
const { editorInstance, meta } = useEditorContext();
Expand Down Expand Up @@ -86,7 +86,7 @@ function ShareButton() {
setUploadState({ type: "uploading", progress: 0 });

// Now proceed with upload
const result = meta?.sharing
const result = meta()?.sharing
? await commands.uploadExportedVideo(projectPath, "Reupload")
: await commands.uploadExportedVideo(projectPath, {
Initial: { pre_created_video: null },
Expand Down Expand Up @@ -136,7 +136,7 @@ function ShareButton() {

return (
<div class="relative">
<Show when={meta?.sharing}>
<Show when={meta()?.sharing}>
{(sharing) => {
const url = () => new URL(sharing().link);

Expand Down
22 changes: 3 additions & 19 deletions apps/desktop/src/routes/editor/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type RenderState =

export const [EditorContextProvider, useEditorContext] = createContextProvider(
(props: {
meta: TransformedMeta;
meta: () => TransformedMeta | undefined;
editorInstance: SerializedEditorInstance;
refetchMeta(): Promise<void>;
}) => {
Expand Down Expand Up @@ -108,21 +108,6 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider(
: undefined
);

// This is used in ShareButton.tsx to notify the component that the metadata has changed, from ExportDialog.tsx
// When a video is uploaded, the metadata is updated

const [lastMetaUpdate, setLastMetaUpdate] = createSignal<{
videoId: string;
timestamp: number;
} | null>(null);

const metaUpdateStore = {
notifyUpdate: (videoId: string) => {
setLastMetaUpdate({ videoId, timestamp: Date.now() });
},
getLastUpdate: lastMetaUpdate,
};

createEffect(
on(
() => editorState.playing,
Expand Down Expand Up @@ -221,9 +206,6 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider(
setDialog,
project,
setProject,
metaUpdateStore,
lastMetaUpdate,
setLastMetaUpdate,
projectHistory: createStoreHistory(project, setProject),
editorState,
setEditorState,
Expand Down Expand Up @@ -312,6 +294,8 @@ export const [EditorInstanceContextProvider, useEditorInstanceContext] =
queryFn: editorInstance()
? () => commands.getEditorMeta().then(transformMeta)
: skipToken,
cacheTime: 0,
staleTime: 0,
}));

return {
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
"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",
"rounded-xl hover:bg-gray-2 hover:border-gray-5 h-[48px] placeholder:text-gray-8 py-[14px] border-[1px] focus:border-gray-5",
"file:border-0 file:bg-transparent file:text-sm file:font-medium",
"disabled:cursor-not-allowed disabled:bg-gray-2 disabled:bg-gray-2 disabled:text-gray-9 placeholder:transition-all",
"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",
"disabled:cursor-not-allowed disabled:bg-gray-2 disabled:text-gray-9 placeholder:transition-all",
"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",
className
)}
ref={ref}
Expand Down
Loading