Skip to content

Commit

Permalink
improve readiablity
Browse files Browse the repository at this point in the history
  • Loading branch information
ylc395 committed Oct 16, 2021
1 parent fc9f25c commit cad122d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/domain/service/PublishService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ export class PublishService {
}

private async init() {
this.outputDir.value = await this.generator.getOutputDir();
this.git.on(GitEvents.PROGRESS, (e) => this.refreshPublishingProgress(e));
this.git.on(GitEvents.MESSAGE, (message) => this.refreshPublishingProgress({ message }));
this.git.on(GitEvents.INIT_REPO_STATUS_CHANGED, (e) => {
this.gitRepoStatus = e;

if (this.gitRepoStatus === 'initializing') {
this.refreshPublishingProgress({
phase: 'Repo initializing...',
phase: 'Local repository initializing...',
message: '',
});
}
Expand All @@ -92,7 +93,6 @@ export class PublishService {
token: (await this.joplinDataRepository.getGithubToken()) || '',
...(await this.pluginDataRepository.getGithubInfo()),
};
this.outputDir.value = await this.generator.getOutputDir();

if (this.isGithubInfoValid.value) {
this.git.init(toRaw(this.githubInfo.value), this.outputDir.value).catch(noop);
Expand Down
9 changes: 4 additions & 5 deletions src/driver/git/webviewApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Git extends EventEmitter<GitEvents> {
});
}

async push(files: string[], init: boolean) {
async push(files: string[], needToInit: boolean) {
if (this.isPushing) {
throw new Error('pushing!');
}
Expand All @@ -164,11 +164,10 @@ class Git extends EventEmitter<GitEvents> {
});

try {
if (init) {
await Promise.race([this.initRepo(), terminatePromise]);
} else {
await Promise.race([this.initRepoPromise, terminatePromise]);
if (needToInit) {
this.initRepo();
}
await Promise.race([this.initRepoPromise, terminatePromise]);
} catch (error) {
this.isPushing = false;

Expand Down
97 changes: 48 additions & 49 deletions src/driver/webview/app/Publisher/PublishingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,54 +46,53 @@ export default defineComponent({
<Button @click="stopPublishing">Stop</Button>
</div>
</template>
<div v-if="progress.result">
<Result
class="py-3 px-4"
:status="progress.result !== PublishResults.SUCCESS ? 'error' : 'success'"
:title="
progress.result !== PublishResults.SUCCESS ? 'Fail to publish' : 'Published Successfully'
"
>
<template #subTitle>
<div v-if="progress.result !== PublishResults.SUCCESS" class="text-left">
<p>{{ progress.message }}</p>
<p>
<template v-if="progress.result === PublishResults.FAIL"
>This is an unexpected error, you can retry, and report it as a Github issue.
</template>
Or if you are a Git user, you can use Git manually to continue publishing.
<a
href="https://github.com/ylc395/joplin-plugin-pages-publisher/wiki/How-to-use-git-manually"
target="_blank"
>See this docs for details</a
>
</p>
</div>
<div v-else-if="githubInfo">
Please Check:
<ul class="text-gray-400 text-left list-disc">
<li class="mt-2">
https://github.com/{{ githubInfo.userName }}/{{
githubInfo.repositoryName || `${githubInfo.userName}.github.io`
}}{{ githubInfo.branch ? `/tree/${githubInfo.branch}` : '' }}
</li>
<li v-if="githubInfo.cname">https://{{ githubInfo.cname }}</li>
<li v-if="isDefaultRepository && !githubInfo.cname">
https://{{ githubInfo.userName }}.github.io
</li>
</ul>
</div>
</template>
<template #extra>
<Button v-if="progress.result" @click="reset">Confirm</Button>
<Button
v-if="[PublishResults.FAIL, PublishResults.GITHUB_INFO_ERROR].includes(progress.result)"
type="primary"
@click="publish(true)"
>Retry</Button
>
</template>
</Result>
</div>
<Result
v-if="progress.result"
class="py-3 px-4"
:status="progress.result !== PublishResults.SUCCESS ? 'error' : 'success'"
:title="
progress.result !== PublishResults.SUCCESS ? 'Fail to publish' : 'Published Successfully'
"
>
<template #subTitle>
<div v-if="progress.result !== PublishResults.SUCCESS" class="text-left">
<p>{{ progress.message }}</p>
<p>
<template v-if="progress.result === PublishResults.FAIL"
>This is an unexpected error, you can retry, and report it as a Github issue.
</template>
Or if you are a Git user, you can use Git manually to continue publishing.
<a
href="https://github.com/ylc395/joplin-plugin-pages-publisher/wiki/How-to-use-git-manually"
target="_blank"
>See this docs for details</a
>
</p>
</div>
<div v-else-if="githubInfo">
Please Check:
<ul class="text-gray-400 text-left list-disc">
<li class="mt-2">
https://github.com/{{ githubInfo.userName }}/{{
githubInfo.repositoryName || `${githubInfo.userName}.github.io`
}}{{ githubInfo.branch ? `/tree/${githubInfo.branch}` : '' }}
</li>
<li v-if="githubInfo.cname">https://{{ githubInfo.cname }}</li>
<li v-if="isDefaultRepository && !githubInfo.cname">
https://{{ githubInfo.userName }}.github.io
</li>
</ul>
</div>
</template>
<template #extra>
<Button v-if="progress.result" @click="reset">Confirm</Button>
<Button
v-if="[PublishResults.FAIL, PublishResults.GITHUB_INFO_ERROR].includes(progress.result)"
type="primary"
@click="publish(true)"
>Retry</Button
>
</template>
</Result>
</Modal>
</template>

0 comments on commit cad122d

Please sign in to comment.