Commit 1a806572 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[fix] Refactoring the popup UI

parent ce13413860c6
......@@ -126,7 +126,7 @@ export interface LDBrowser {
* Sets the new user command for the current resouce
* @param command The new user command
*/
setCommand(command: ResourceUserCommand): void;
setCommand(command: ResourceUserCommand): Promise<any>;
}
/**
......@@ -508,9 +508,14 @@ class LDBrowserImpl implements LDBrowser {
/**
* Refreshes the current page
*/
public refresh(): void {
if (this.currentData == null) return;
this.onReachedUri(this.currentData.resource.uri);
public refresh(): Promise<any> {
if (this.currentData == null)
return new Promise<any>(
(resolve: (result: any) => void, reject: (reason: any) => void) => {
reject("no data");
}
);
return this.onReachedUri(this.currentData.resource.uri);
}
/**
......@@ -524,7 +529,7 @@ class LDBrowserImpl implements LDBrowser {
* Sets the new user command for the current resouce
* @param command The new user command
*/
public setCommand(command: ResourceUserCommand): void {
public setCommand(command: ResourceUserCommand): Promise<any> {
if (this.currentData == null) return;
let mustRefresh = false;
if (this.currentData.command.selectedTopic != command.selectedTopic)
......@@ -537,6 +542,14 @@ class LDBrowserImpl implements LDBrowser {
)
mustRefresh = true;
this.currentData.command = command;
if (mustRefresh) this.refresh();
if (mustRefresh) {
return this.refresh();
} else {
return new Promise<any>(
(resolve: (result: any) => void, reject: (reason: any) => void) => {
resolve(null);
}
);
}
}
}
......@@ -135,7 +135,7 @@ export class CurrentTabConfig extends React.Component<
</label>
</div>
</div>
<div className="row">
<div className="row" style={{ marginTop: "5pt" }}>
<div className="col-4">
<label>Primary topic</label>
</div>
......@@ -172,7 +172,7 @@ export class CurrentTabConfig extends React.Component<
</div>
</div>
</div>
<div className="row">
<div className="row" style={{ marginTop: "5pt" }}>
<div className="col-4">
<label>View</label>
</div>
......@@ -206,7 +206,20 @@ export class CurrentTabConfig extends React.Component<
</select>
</div>
</div>
<div className="row">
<div className="row" style={{ marginTop: "5pt" }}>
<div className="col-4" />
<div className="col-8">
<span>{"\u25BA"}</span>
<span style={{ marginLeft: "5pt" }}>
{this.props.data.rendering.viewId
? this.props.registry.descriptors[
this.props.data.rendering.viewId
].name
: ""}
</span>
</div>
</div>
<div className="row" style={{ marginTop: "5pt" }}>
<div className="col-4">
<label>Language</label>
</div>
......@@ -235,6 +248,26 @@ export class CurrentTabConfig extends React.Component<
</select>
</div>
</div>
<div className="row" style={{ marginTop: "5pt" }}>
<div className="col-4" />
<div className="col-8">
<span>{"\u25BA"}</span>
<span style={{ marginLeft: "5pt" }}>
{this.props.data.rendering.languages ? (
this.props.data.rendering.languages.map(
(language: application.Language, index: number) => (
<span key={"used-lang" + index} title={language.iso639_2}>
{index != 0 ? ", " : ""}
{language.name}
</span>
)
)
) : (
<span />
)}
</span>
</div>
</div>
</div>
);
}
......
......@@ -300,11 +300,24 @@ export function getCurrentResource(tabId: number): Promise<ResourceData> {
export function updateCurrentCommand(
tabId: number,
command: ResourceUserCommand
): void {
chrome.tabs.sendMessage(tabId, {
requestType: "UpdateCurrentCommand",
payload: command
});
): Promise<ResourceData> {
return new Promise<ResourceData>(
(
resolve: (observable: ResourceData) => void,
reject: (reason: any) => void
) => {
chrome.tabs.sendMessage(
tabId,
{
requestType: "UpdateCurrentCommand",
payload: command
},
(resource: ResourceData) => {
resolve(resource);
}
);
}
);
}
/**
......
......@@ -73,7 +73,16 @@ function initializeBrowser(): LDBrowser {
} else if (request.requestType == "GetCurrentResource") {
sendResponse(browser.getCurrentResource());
} else if (request.requestType == "UpdateCurrentCommand") {
browser.setCommand(request.payload);
browser
.setCommand(request.payload)
.then((result: any) => {
sendResponse(browser.getCurrentResource());
})
.catch((reason: any) => {
console.log(reason);
sendResponse(browser.getCurrentResource());
});
return true;
}
});
return browser;
......
......@@ -56,7 +56,16 @@ function initializeBrowser() {
if (request.requestType == "GetCurrentResource") {
sendResponse(browser.getCurrentResource());
} else if (request.requestType == "UpdateCurrentCommand") {
browser.setCommand(request.payload);
browser
.setCommand(request.payload)
.then((result: any) => {
sendResponse(browser.getCurrentResource());
})
.catch((reason: any) => {
console.log(reason);
sendResponse(browser.getCurrentResource());
});
return true;
}
});
browser.navigateTo(getParameterByName("target"));
......
......@@ -102,8 +102,12 @@ class Popup extends React.Component<{}, State> {
}
onUpdateTabCommand() {
updateCurrentCommand(this.state.tabId, this.state.data.command);
this.setState(this.state);
updateCurrentCommand(this.state.tabId, this.state.data.command).then(
(data: ResourceData) => {
this.state.data = data;
this.setState(this.state);
}
);
}
onTabCommandAutomatic(event: React.FormEvent<HTMLInputElement>) {
......
......@@ -326,6 +326,10 @@ export interface RenderingResult {
* The evaluations of the possible views
*/
evaluations: RenderingEvaluation[];
/**
* The used languages
*/
languages: Language[];
}
/**
......
......@@ -277,7 +277,8 @@ class ViewRendererImpl implements CachingViewRenderer {
dom: null,
viewId: null,
evaluations: evaluations,
suggestedResources: null
suggestedResources: null,
languages: null
};
}
let result = view.render(this, context, target);
......@@ -287,7 +288,8 @@ class ViewRendererImpl implements CachingViewRenderer {
evaluations: evaluations,
suggestedResources: result.suggestedResources
? result.suggestedResources
: null
: null,
languages: this.getLanguagesFor(context, target)
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment