fix the recent list (#13770)

This commit is contained in:
Alan Ren
2020-12-10 18:35:31 -08:00
committed by GitHub
parent 95d22a03ae
commit 4ab0f729e1
2 changed files with 13 additions and 20 deletions

View File

@@ -86,7 +86,7 @@ export default () => `
<div class="flex list-header-container"> <div class="flex list-header-container">
<i class="icon-document themed-icon"></i> <i class="icon-document themed-icon"></i>
<span class="list-header">${escape(localize('welcomePage.name', "Name"))}</span> <span class="list-header">${escape(localize('welcomePage.name', "Name"))}</span>
<span class="list-header-last-opened">${escape(localize('welcomePage.lastOpened', "Last Opened"))}</span> <span class="list-header-last-opened">${escape(localize('welcomePage.location', "Location"))}</span>
</div> </div>
<ul class="list"> <ul class="list">
<!-- Filled programmatically --> <!-- Filled programmatically -->

View File

@@ -335,7 +335,7 @@ class WelcomePage extends Disposable {
} }
const workspacesToShow = workspaces.slice(0, 5); const workspacesToShow = workspaces.slice(0, 5);
clearNode(ul); clearNode(ul);
await this.mapListEntries(workspacesToShow, fileService, container, ul); await this.mapListEntries(workspacesToShow, container, ul);
}).then(undefined, onUnexpectedError); }).then(undefined, onUnexpectedError);
this.addExtensionList(container, '.extension-list'); this.addExtensionList(container, '.extension-list');
this.addExtensionPack(container, '.extensionPack'); this.addExtensionPack(container, '.extensionPack');
@@ -469,21 +469,16 @@ class WelcomePage extends Disposable {
}, 3000); }, 3000);
} }
private async createListEntries(container: HTMLElement, fileService: IFileService, fullPath: URI, windowOpenable: IWindowOpenable, relativePath: string): Promise<HTMLElement[]> { private async createListEntries(container: HTMLElement, fullPath: string, windowOpenable: IWindowOpenable): Promise<HTMLElement[]> {
let result: HTMLElement[] = []; let result: HTMLElement[] = [];
const value = await fileService.resolve(fullPath); const { name, parentPath } = splitName(fullPath);
let date = new Date(value.mtime);
let mtime: Date = date;
const options = { weekday: 'short', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit' };
const lastOpened: string = mtime.toLocaleDateString(undefined, options);
const { name, parentPath } = splitName(relativePath);
const li = document.createElement('li'); const li = document.createElement('li');
const icon = document.createElement('i'); const icon = document.createElement('i');
const a = document.createElement('a'); const a = document.createElement('a');
const span = document.createElement('span'); const span = document.createElement('span');
icon.title = relativePath; icon.title = fullPath;
a.innerText = name; a.innerText = name;
a.title = relativePath; a.title = fullPath;
a.setAttribute('aria-label', localize('welcomePage.openFolderWithPath', "Open folder {0} with path {1}", name, parentPath)); a.setAttribute('aria-label', localize('welcomePage.openFolderWithPath', "Open folder {0} with path {1}", name, parentPath));
a.setAttribute('role', 'button'); a.setAttribute('role', 'button');
a.href = 'javascript:void(0)'; a.href = 'javascript:void(0)';
@@ -503,8 +498,8 @@ class WelcomePage extends Disposable {
li.appendChild(a); li.appendChild(a);
span.classList.add('path'); span.classList.add('path');
span.classList.add('detail'); span.classList.add('detail');
span.innerText = lastOpened; span.innerText = parentPath;
span.title = relativePath; span.title = parentPath;
li.appendChild(span); li.appendChild(span);
const ul = container.querySelector('.list'); const ul = container.querySelector('.list');
ul.appendChild(li); ul.appendChild(li);
@@ -512,22 +507,20 @@ class WelcomePage extends Disposable {
return result; return result;
} }
private async mapListEntries(recents: (IRecentWorkspace | IRecentFolder)[], fileService: IFileService, container: HTMLElement, ul: HTMLElement): Promise<HTMLElement[]> { private async mapListEntries(recents: (IRecentWorkspace | IRecentFolder)[], container: HTMLElement, ul: HTMLElement): Promise<HTMLElement[]> {
const result: HTMLElement[] = []; const result: HTMLElement[] = [];
for (let i = 0; i < recents.length; i++) { for (let i = 0; i < recents.length; i++) {
const recent = recents[i]; const recent = recents[i];
let relativePath: string; let fullPath: string;
let fullPath: URI;
let windowOpenable: IWindowOpenable; let windowOpenable: IWindowOpenable;
if (isRecentFolder(recent)) { if (isRecentFolder(recent)) {
windowOpenable = { folderUri: recent.folderUri }; windowOpenable = { folderUri: recent.folderUri };
relativePath = recent.label || this.labelService.getWorkspaceLabel(recent.folderUri, { verbose: true }); fullPath = recent.label || this.labelService.getWorkspaceLabel(recent.folderUri, { verbose: true });
fullPath = recent.folderUri;
} else { } else {
relativePath = recent.label || this.labelService.getWorkspaceLabel(recent.workspace, { verbose: true }); fullPath = recent.label || this.labelService.getWorkspaceLabel(recent.workspace, { verbose: true });
windowOpenable = { workspaceUri: recent.workspace.configPath }; windowOpenable = { workspaceUri: recent.workspace.configPath };
} }
const elements = await this.createListEntries(container, fileService, fullPath, windowOpenable, relativePath); const elements = await this.createListEntries(container, fullPath, windowOpenable);
result.push(...elements); result.push(...elements);
} }
return result; return result;