Skip to content

Commit

Permalink
fix getting the previous preview
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudutour committed Aug 4, 2017
1 parent 318415e commit ae0944f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
25 changes: 23 additions & 2 deletions app/src/lib/dispatcher/app-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ import { IGitAccount } from '../git/authentication'
import { getGenericHostname, getGenericUsername } from '../generic-git-auth'
import { RetryActionType, RetryAction } from '../retry-actions'

function findNext(
array: ReadonlyArray<string>,
toFind: string
): string | undefined {
let found = false
return array.find((s, i) => {
if (s === toFind) {
found = true
return false
}
if (found) {
return true
}
return false
})
}

const LastSelectedRepositoryIDKey = 'last-selected-repository-id'

const defaultSidebarWidth: number = 250
Expand Down Expand Up @@ -732,12 +749,15 @@ export class AppStore {
}
}

const previousSha = findNext(stateBeforeLoad.historyState.history, sha)

const diff = await getCommitDiff(
this.sketchPath,
repository,
stateBeforeLoad.kactus.files,
file,
sha
sha,
previousSha
)

const stateAfterLoad = this.getRepositoryState(repository)
Expand Down Expand Up @@ -1228,7 +1248,8 @@ export class AppStore {
this.sketchPath,
repository,
stateBeforeLoad.kactus.files,
selectedFileBeforeLoad
selectedFileBeforeLoad,
stateBeforeLoad.historyState.history[0]
)

const stateAfterLoad = this.getRepositoryState(repository)
Expand Down
19 changes: 13 additions & 6 deletions app/src/lib/git/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export async function getCommitDiff(
repository: Repository,
kactusFiles: Array<IKactusFile>,
file: FileChange,
commitish: string
commitish: string,
previousCommitish?: string
): Promise<IDiff> {
const args = [
'log',
Expand Down Expand Up @@ -98,7 +99,8 @@ export async function getCommitDiff(
kactusFiles,
file,
diffText,
commitish
commitish,
previousCommitish
)
}

Expand All @@ -111,7 +113,8 @@ export async function getWorkingDirectoryDiff(
sketchPath: string,
repository: Repository,
kactusFiles: Array<IKactusFile>,
file: WorkingDirectoryFileChange
file: WorkingDirectoryFileChange,
previousCommitish?: string
): Promise<IDiff> {
let successExitCodes: Set<number> | undefined
let args: Array<string>
Expand Down Expand Up @@ -195,6 +198,7 @@ export async function getWorkingDirectoryDiff(
file,
diffText,
'HEAD',
previousCommitish,
lineEndingsChange
)
}
Expand Down Expand Up @@ -263,7 +267,8 @@ async function getSketchDiff(
file: FileChange,
diff: IRawDiff,
kactusFile: IKactusFile,
commitish: string
commitish: string,
previousCommitish?: string
): Promise<ISketchDiff> {
let current: Image | undefined = undefined
let previous: Image | undefined = undefined
Expand Down Expand Up @@ -360,7 +365,7 @@ async function getSketchDiff(
kactusFile,
repository,
file.oldPath || file.path,
`${commitish}`,
previousCommitish || `${commitish}`,
type
)
} catch (e) {
Expand All @@ -387,6 +392,7 @@ export async function convertDiff(
file: FileChange,
diff: IRawDiff,
commitish: string,
previousCommitish?: string,
lineEndingsChange?: LineEndingsChange
): Promise<IDiff> {
if (diff.isBinary) {
Expand All @@ -411,7 +417,8 @@ export async function convertDiff(
file,
diff,
kactusFile,
commitish
commitish,
previousCommitish
)
}

Expand Down

0 comments on commit ae0944f

Please sign in to comment.