Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
feat: Clean data.json file when repo is excluded
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Apr 15, 2022
1 parent 2f88808 commit f23844c
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions Snippet-downloader/modals/updateSnippets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {App, FuzzySuggestModal, Notice} from "obsidian";
import {App, FuzzySuggestModal} from "obsidian";
import {snippetDownloaderSettings, snippetRepo} from "../settings";
import {updateSnippet, checkLastUpdate, downloadSnippet, grabLastCommitDate} from "../downloader";
import {updateRepo, updateSpecificSnippet} from "../addSnippets";
import snippetDownloader from "../main";
import {basename, searchExcluded} from "../utils";

Expand All @@ -9,33 +9,11 @@ interface repoUpdate {
repoUrl: string;
}

interface snippetUpdate {
export interface snippetUpdate {
repo: string;
snippetPath: string;
}

async function updateSpecificSnippet(item: snippetUpdate, settings: snippetDownloaderSettings) {
const listSnippet = settings.snippetList
const excludedSnippet = settings.errorSnippet
const snippet = listSnippet.find(snippet => snippet.repo === item.repo);
const snippetsRep = snippet.snippetsContents.find(snippet => snippet.name === item.snippetPath);
if (await checkLastUpdate(snippetsRep, item.repo)) {
const successDownload = await downloadSnippet(item.repo, snippetsRep.name, this.app.vault);
if (successDownload) {
snippetsRep.lastUpdate = await grabLastCommitDate(item.repo, snippetsRep.name);
new Notice(`${basename(item.snippetPath)} has been updated 🎉`);
return [listSnippet,
excludedSnippet];
} else {
return [listSnippet,
excludedSnippet + item.snippetPath.replace('.css', '')] + ', ';
}
}
new Notice (`${basename(item.snippetPath)} is already up to date 💡`);
return [listSnippet,
excludedSnippet];
}

function getAllRepo(settings: snippetDownloaderSettings){
const repoAll=[];
for(const repo of settings.snippetList){
Expand Down Expand Up @@ -81,9 +59,9 @@ export class repoDownloader extends FuzzySuggestModal<repoUpdate> {
}

async onChooseItem(item: repoUpdate, evt: MouseEvent | KeyboardEvent) {
const allSettings = await updateSnippet(item.repoName, this.settings.snippetList, this.app.vault, this.settings.excludedSnippet, this.settings.errorSnippet);
this.settings.snippetList =<snippetRepo[]>allSettings[0];
this.settings.errorSnippet=<string>allSettings[1];
const allSettings = await updateRepo(item.repoName, this.settings.snippetList, this.app.vault, this.settings.excludedSnippet, this.settings.errorSnippet);
this.settings.snippetList =<snippetRepo[]>allSettings[1];
this.settings.errorSnippet=<string>allSettings[0];
await this.plugin.saveSettings();
}

Expand Down

0 comments on commit f23844c

Please sign in to comment.