Skip to content
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

Prevent null selectedDraft from breaking render #219

Merged
merged 7 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 2 additions & 4 deletions src/view/compile/CompileView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
allWorkflowNames.length > 0
) {
// shadowed here to prevent circular reference
const _currentDraftIndex = $drafts.findIndex(
(d) => d.vaultPath === $selectedDraft.vaultPath
);
const _currentDraftIndex = $drafts.findIndex((d) => d.vaultPath === $selectedDraft.vaultPath);
$drafts[_currentDraftIndex].workflow = allWorkflowNames[0];
}
}
Expand Down Expand Up @@ -329,7 +327,7 @@
>
<CompileStepView
ordinal={item.index + 1}
bind:step={$workflows[currentWorkflowName].steps[item.index]}
step={$workflows[currentWorkflowName].steps[item.index]}
on:removeStep={() => {
const newWorkflow = {
...$currentWorkflow,
Expand Down
13 changes: 7 additions & 6 deletions src/view/explorer/SceneList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
import { selectElementContents } from "../utils";
import { addAll, addScene, ignoreAll, ignoreScene } from "./scene-menu-items";

let currentDraftIndex: number;
$: {
currentDraftIndex = $drafts.findIndex(
(d) => d.vaultPath === $selectedDraft.vaultPath
);
let currentDraftIndex: number = -1;
$: if($selectedDraft) {
currentDraftIndex = $drafts.findIndex((d) => d.vaultPath === $selectedDraft.vaultPath);
}

// Function to make paths from scene names
Expand Down Expand Up @@ -231,6 +229,7 @@
}

function doWithUnknown(fileName: string, action: "add" | "ignore") {
if (!$selectedDraft) return;
if (action === "add") {
addScene(fileName);
} else {
Expand All @@ -239,6 +238,7 @@
}

function doWithAll(action: "add" | "ignore") {
if (!$selectedDraft) return;
if (action === "add") {
addAll();
} else {
Expand Down Expand Up @@ -270,6 +270,7 @@
if (
oldIndex !== undoIndex &&
newValue &&
currentDraftIndex >= 0 &&
newValue.draftVaultPath === $drafts[currentDraftIndex].vaultPath &&
$drafts[currentDraftIndex].format === "scenes"
) {
Expand Down Expand Up @@ -361,7 +362,7 @@
</div>
</SortableList>
</div>
{#if $selectedDraft.format === "scenes" && $selectedDraft.unknownFiles.length > 0}
{#if $selectedDraft && $selectedDraft.format === "scenes" && $selectedDraft.unknownFiles.length > 0}
<div id="longform-unknown-files-wizard">
<div class="longform-unknown-inner">
<p class="longform-unknown-explanation">
Expand Down
5 changes: 5 additions & 0 deletions src/view/explorer/scene-menu-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { get } from "svelte/store";

const getSelectedDraftWithIndex = () => {
const draft = get(selectedDraft) as MultipleSceneDraft;
if (draft == null) return { index: -1, draft };
b-camphart marked this conversation as resolved.
Show resolved Hide resolved
const index = get(drafts).findIndex(
(d) => d.vaultPath === draft.vaultPath
);
Expand All @@ -13,6 +14,7 @@ const getSelectedDraftWithIndex = () => {

export const addScene = (fileName: string) => {
const { index, draft } = getSelectedDraftWithIndex()
if (draft == null) return;
b-camphart marked this conversation as resolved.
Show resolved Hide resolved
if (index >= 0 && draft.format === "scenes") {
drafts.update((d) => {
const targetDraft = d[index] as MultipleSceneDraft;
Expand All @@ -29,6 +31,7 @@ export const addScene = (fileName: string) => {

export const ignoreScene = (fileName: string) => {
const { index, draft } = getSelectedDraftWithIndex()
if (draft == null) return;
b-camphart marked this conversation as resolved.
Show resolved Hide resolved
if (index >= 0 && draft.format === "scenes") {
drafts.update((d) => {
const targetDraft = d[index] as MultipleSceneDraft;
Expand All @@ -46,6 +49,7 @@ export const ignoreScene = (fileName: string) => {

export const addAll = () => {
const { index, draft } = getSelectedDraftWithIndex()
if (draft == null) return;
b-camphart marked this conversation as resolved.
Show resolved Hide resolved
if (index >= 0 && draft.format === "scenes") {
drafts.update((d) => {
const targetDraft = d[index] as MultipleSceneDraft;
Expand All @@ -61,6 +65,7 @@ export const addAll = () => {

export const ignoreAll = () => {
const { index, draft } = getSelectedDraftWithIndex()
if (draft == null) return;
b-camphart marked this conversation as resolved.
Show resolved Hide resolved
if (index >= 0 && draft.format === "scenes") {
drafts.update((d) => {
const targetDraft = d[index] as MultipleSceneDraft;
Expand Down