Skip to content

Commit

Permalink
feat: load blocks from url providers
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchezcarlosjr committed Nov 21, 2023
1 parent e92cd44 commit f124fe6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/app/notebook/assistant/assistant.component.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<img (click)="toggleChatbot()" class="chatbot-toggle" ngSrc="../../../assets/avatar.png" alt="avatar.png" height="512" width="512">
<img (click)="toggleChatbot()" priority class="chatbot-toggle" ngSrc="../../../assets/avatar.png" alt="avatar.png" height="512" width="512">
<gradio-app *ngIf="showChatbot" info="false" class="chatbot" src="https://evatutor.sanchezcarlosjr.com/"></gradio-app>
1 change: 0 additions & 1 deletion src/app/notebook/notebook.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</button>
<button mat-menu-item (click)="openRecent()" >Open recent</button>
<button mat-menu-item (click)="saveInUrl()">Save in URL</button>
<button mat-menu-item (click)="removeUrlProviders()">Delete c and u parameter</button>
<button mat-menu-item (click)="shareNotebook()">Share notebook</button>
</mat-menu>
<button mat-button [matMenuTriggerFor]="runtimeMenu">Runtime</button>
Expand Down
5 changes: 1 addition & 4 deletions src/app/notebook/notebook.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,7 @@ export class NotebookComponent implements OnInit {
this.titleService.setTitle(name);
}

removeUrlProviders() {
url.remove("c");
url.remove("u");
}


shareNotebook() {
this.dialog.open(ShareDialogComponent);
Expand Down
6 changes: 4 additions & 2 deletions src/app/notebook/shell/DatabaseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,14 @@ export class DatabaseManager {
async registerUrlProviders() {
if (url.has("c")) {
return this.readBlocksFromURL().then(blocks => {
url.remove('c');
return blocks;
});
}
if (url.has("u")) {
return fetch(url.read("u")).then(response => response.json()).then(blocks => {
return blocks;
return fetch(url.read("u")).then(response => response.json()).then(notebook => {
url.remove('u');
return notebook?.blocks || notebook;
});
}
return [];
Expand Down
6 changes: 3 additions & 3 deletions src/app/notebook/shell/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class Shell {
const blockCollection = await this.databaseManager.start();
const documents = await firstValueFrom(blockCollection);
let blocks: BlockDocument[] = await this.processDocuments(documents);
if (blocks.length === 0 && !url.has("ps") && !url.has("u")) {
if (blocks.length === 0 && !url.has("ps") && !url.has("u")) {
blocks.push(this.databaseManager.generateDefaultBlock());
this.databaseManager.upsert(blocks[0]);
}
Expand Down Expand Up @@ -339,10 +339,10 @@ export class Shell {
private async renderEditor(blocks: BlockDocument[], isMode2: boolean) {
if (url.has("ps") && blocks.length <= 1 && blocks[0]?.data?.text === "")
return;
await this.editor.render({ version: '2.27.0', blocks });
await this.editor.render({ version: '2.29.0-rc.6', blocks });
const newBlocks: OutputBlockData[] = await this.databaseManager.registerUrlProviders();
if (newBlocks.length > 0) {
await this.editor.render({ version: '2.27.0', blocks: newBlocks });
await this.editor.render({ version: '2.29.0-rc.6', blocks: newBlocks });
if (isMode2) {
window.dispatchEvent(new CustomEvent('shell.RunAll'));
} else {
Expand Down

0 comments on commit f124fe6

Please sign in to comment.