Skip to content

Commit f697619

Browse files
authored
Don't add forumExample card if forumUrl has otherActions (microsoft#7793)
1 parent 948d9d3 commit f697619

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

pxtlib/discourse.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace pxt.discourse {
5353

5454
export function topicsByTag(apiUrl: string, tag: string): Promise<pxt.CodeCard[]> {
5555
apiUrl = apiUrl.replace(/\/$/, '');
56-
const q = `${apiUrl}/tags/${tag}.json`;
56+
const q = `${apiUrl}/tag/${tag}.json`;
5757
return pxt.Util.httpGetJsonAsync(q)
5858
.then((json: TagsResponse) => {
5959
const users = pxt.Util.toDictionary(json.users, u => u.id.toString());

pxtlib/gallery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ ${(cards || []).map(
253253
return md;
254254

255255
function otherActionsToMd(oas: pxt.CodeCardAction[]): string {
256-
return oas.map(oa => `* otherAction: ${oa.url} ${oa.editor || "ts"} ${oa.cardType || ""}`)
256+
return oas.map(oa => `* otherAction: ${oa.url}, ${oa.editor || ""}, ${oa.cardType || ""}`)
257257
.join('\n');
258258
}
259259
}

webapp/src/projects.tsx

+24-14
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ export class Projects extends auth.Component<ISettingsProps, ProjectsState> {
105105
chgGallery(scr: pxt.CodeCard, action?: pxt.CodeCardAction) {
106106
let editor: string = (action && action.editor) || "blocks";
107107
if (editor == "js") editor = "ts";
108-
pxt.tickEvent("projects.gallery", { name: scr.name, cardType: scr.cardType, editor });
109108
const url = action ? action.url : scr.url;
109+
const type = action?.cardType || scr.cardType
110110
const editorPref = editor + "prj";
111-
switch (scr.cardType) {
111+
pxt.tickEvent("projects.gallery", { name: scr.name, cardType: type, editor });
112+
switch (type) {
112113
case "template":
113114
const prj = pxt.Util.clone(pxt.appTarget.blocksprj);
114115
prj.config.dependencies = {}; // clear all dependencies
@@ -122,6 +123,7 @@ export class Projects extends auth.Component<ISettingsProps, ProjectsState> {
122123
this.props.parent.startActivity("tutorial", url, scr.name, editorPref);
123124
break;
124125
case "sharedExample":
126+
console.log("shared example")
125127
let id = pxt.github.normalizeRepoId(url) || pxt.Cloud.parseScriptId(url);
126128
if (!id) {
127129
core.errorNotification(lf("Sorry, the project url looks invalid."));
@@ -863,12 +865,13 @@ export class ProjectsDetail extends data.Component<ProjectsDetailProps, Projects
863865
this.linkRef = React.createRef<HTMLAnchorElement>();
864866
}
865867

866-
protected isLink() {
868+
protected isLink(actionType?: pxt.CodeCardType) {
867869
const { cardType, url, youTubeId, youTubePlaylistId } = this.props;
870+
const type = actionType || cardType;
868871

869-
return isCodeCardWithLink(cardType) && (youTubeId || youTubePlaylistId || url);
872+
return isCodeCardWithLink(type) && (youTubeId || youTubePlaylistId || url);
870873

871-
function isCodeCardWithLink(value: string) {
874+
function isCodeCardWithLink(value: pxt.CodeCardType) {
872875
switch (value) {
873876
case "file":
874877
case "example":
@@ -899,10 +902,12 @@ export class ProjectsDetail extends data.Component<ProjectsDetailProps, Projects
899902
let clickLabel = lf("Show Instructions");
900903
if (cardType == "tutorial")
901904
clickLabel = lf("Start Tutorial");
902-
else if (cardType == "codeExample" || cardType == "example" || cardType == "sharedExample")
905+
else if (cardType == "codeExample" || cardType == "example")
903906
clickLabel = lf("Open Example");
904907
else if (cardType == "forumUrl")
905908
clickLabel = lf("Open in Forum");
909+
else if (cardType == "sharedExample")
910+
clickLabel = lf("Open in Editor");
906911
else if (cardType == "template")
907912
clickLabel = lf("New Project");
908913
else if (youTubeId)
@@ -916,30 +921,34 @@ export class ProjectsDetail extends data.Component<ProjectsDetailProps, Projects
916921
switch (type) {
917922
case "tutorial":
918923
case "example":
919-
case "sharedExample":
920924
if (action && action.editor) return action.editor;
921925
return "blocks";
922926
case "codeExample":
923927
if (action && action.editor) return action.editor;
924928
return "js";
929+
case "sharedExample":
930+
return action?.editor;
925931
default:
926932
return null;
927933
}
928934
}
929935

930-
protected getActionIcon(onClick: any, type: string, editor?: pxt.CodeCardEditorType): JSX.Element {
936+
protected getActionIcon(onClick: any, type: pxt.CodeCardType, editor?: pxt.CodeCardEditorType): JSX.Element {
931937
const { youTubeId, youTubePlaylistId } = this.props;
932938
let icon = "file text";
933939
switch (type) {
934940
case "tutorial":
935941
case "example":
936-
case "sharedExample":
937942
icon = "xicon blocks"
938943
if (editor) icon = `xicon ${editor}`;
939944
break;
940945
case "codeExample":
941946
icon = `xicon ${editor || "js"}`;
942947
break;
948+
case "sharedExample":
949+
icon = "pencil"
950+
if (editor) icon = `xicon ${editor}`;
951+
break;
943952
case "forumUrl":
944953
icon = "comments"
945954
break;
@@ -951,7 +960,7 @@ export class ProjectsDetail extends data.Component<ProjectsDetailProps, Projects
951960
if (youTubeId || youTubePlaylistId) icon = "youtube";
952961
break;
953962
}
954-
return this.isLink() && type != "forumExample" // TODO (shakao) migrate forumurl to otherAction json in md
963+
return this.isLink(type) && type != "forumExample" // TODO (shakao) migrate forumurl to otherAction json in md
955964
? <sui.Link role="button" className="link button attached" icon={icon} href={this.getUrl()} target="_blank" tabIndex={-1} />
956965
: <sui.Item role="button" className="button attached" icon={icon} onClick={onClick} tabIndex={-1} />
957966
}
@@ -969,7 +978,7 @@ export class ProjectsDetail extends data.Component<ProjectsDetailProps, Projects
969978
}
970979
}
971980

972-
protected getActionCard(text: string, type: string, onClick: any, autoFocus?: boolean, action?: pxt.CodeCardAction, key?: string): JSX.Element {
981+
protected getActionCard(text: string, type: pxt.CodeCardType, onClick: any, autoFocus?: boolean, action?: pxt.CodeCardAction, key?: string): JSX.Element {
973982
const editor = this.getActionEditor(type, action);
974983
const title = this.getActionTitle(editor);
975984
return <div className={`card-action ui items ${editor || ""}`} key={key}>
@@ -991,7 +1000,7 @@ export class ProjectsDetail extends data.Component<ProjectsDetailProps, Projects
9911000
onClick={onClick}
9921001
onKeyDown={sui.fireClickOnEnter}
9931002
autoFocus={autoFocus}
994-
title={lf("Open in {0}", title)}
1003+
title={lf("Open in {0}", title || lf("Editor"))}
9951004
/>}
9961005
</div>
9971006
}
@@ -1092,9 +1101,10 @@ export class ProjectsDetail extends data.Component<ProjectsDetailProps, Projects
10921101
{this.getActionCard(clickLabel, cardType, this.handleDetailClick, true)}
10931102
{otherActions && otherActions.map((el, i) => {
10941103
let onClick = this.handleActionClick(el);
1095-
return this.getActionCard(clickLabel, el.cardType || cardType, onClick, false, el, `action${i}`);
1104+
let label = el.cardType ? this.getClickLabel(el.cardType) : clickLabel;
1105+
return this.getActionCard(label, el.cardType || cardType, onClick, false, el, `action${i}`);
10961106
})}
1097-
{cardType === "forumUrl" &&
1107+
{cardType === "forumUrl" && (!otherActions || otherActions.length == 0) &&
10981108
// TODO (jwunderl) temporarily disabled in electron re: https://github.com/microsoft/pxt-arcade/issues/2346;
10991109
// reenable CORS issue is fixed.
11001110
!pxt.BrowserUtils.isPxtElectron() &&

0 commit comments

Comments
 (0)