-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into dev/riknoll/new-blo…
…ckly-comments
- Loading branch information
Showing
86 changed files
with
33,904 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { ErrorCode } from "./constants"; | ||
import { logError } from "./loggingService"; | ||
|
||
export async function fetchJsonDocAsync<T = any>(url: string): Promise<T | undefined> { | ||
try { | ||
const response = await fetch(url, { | ||
cache: "no-cache", | ||
}); | ||
if (!response.ok) { | ||
throw new Error("Unable to fetch the json file"); | ||
} else { | ||
const json = await response.json(); | ||
return json; | ||
} | ||
} catch (e) { | ||
logError(ErrorCode.fetchJsonDocAsync, e); | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
export async function getProjectTextAsync(projectId: string): Promise<pxt.Cloud.JsonText | undefined> { | ||
try { | ||
const projectTextUrl = `${pxt.Cloud.apiRoot}/${projectId}/text`; | ||
const response = await fetch(projectTextUrl); | ||
if (!response.ok) { | ||
throw new Error("Unable to fetch the project details"); | ||
} else { | ||
const projectText = await response.json(); | ||
return projectText; | ||
} | ||
} catch (e) { | ||
logError(ErrorCode.getProjectTextAsync, e); | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
export async function getProjectMetaAsync(projectId: string): Promise<pxt.Cloud.JsonScript | undefined> { | ||
try { | ||
const projectMetaUrl = `${pxt.Cloud.apiRoot}/${projectId}`; | ||
const response = await fetch(projectMetaUrl); | ||
if (!response.ok) { | ||
throw new Error("Unable to fetch the project meta information"); | ||
} else { | ||
const projectMeta = await response.json(); | ||
return projectMeta; | ||
} | ||
} catch (e) { | ||
logError(ErrorCode.getProjectMetaAsync, e); | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
export async function downloadTargetConfigAsync(): Promise<pxt.TargetConfig | undefined> { | ||
try { | ||
return await pxt.targetConfigAsync(); | ||
} catch (e) { | ||
logError(ErrorCode.downloadTargetConfigAsync, e); | ||
} | ||
|
||
return undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum ErrorCode { | ||
downloadTargetConfigAsync = "downloadTargetConfigAsync", | ||
fetchJsonDocAsync = "fetchJsonDocAsync", | ||
getProjectTextAsync = "getProjectTextAsync", | ||
getProjectMetaAsync = "getProjectMetaAsync", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
let tickEvent = "pxt.error"; | ||
|
||
const timestamp = () => { | ||
const time = new Date(); | ||
const hours = padTime(time.getHours()); | ||
const minutes = padTime(time.getMinutes()); | ||
const seconds = padTime(time.getSeconds()); | ||
|
||
return `[${hours}:${minutes}:${seconds}]`; | ||
}; | ||
|
||
const padTime = (time: number) => ("0" + time).slice(-2); | ||
|
||
export const logError = (errorCode: string, message?: any, data: pxt.Map<string | number> = {}) => { | ||
let dataObj = { ...data }; | ||
if (message) { | ||
if (typeof message === "object") { | ||
dataObj = { ...dataObj, ...message }; | ||
// Look for non-enumerable properties found on Error objects | ||
["message", "stack", "name"].forEach(key => { | ||
if (message[key]) { | ||
dataObj[key] = message[key]; | ||
} | ||
}); | ||
} else { | ||
dataObj.message = message; | ||
} | ||
} | ||
pxt.tickEvent(tickEvent, { | ||
...dataObj, | ||
errorCode, | ||
}); | ||
console.error(timestamp(), errorCode, dataObj); | ||
}; | ||
|
||
export const logInfo = (message: any) => { | ||
console.log(timestamp(), message); | ||
}; | ||
|
||
export const logDebug = (message: any, data?: any) => { | ||
if (pxt.BrowserUtils.isLocalHost() || pxt.options.debug) { | ||
console.log(timestamp(), message, data); | ||
} | ||
}; | ||
|
||
|
||
export const setTickEvent = (event: string) => { | ||
tickEvent = event; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as React from "react"; | ||
import { Button } from "../controls/Button"; | ||
import { classList } from "../util"; | ||
|
||
interface IProps { | ||
onSignInClick: () => void; | ||
className?: string; | ||
} | ||
|
||
export const SignInButton: React.FC<IProps> = ({ onSignInClick, className }) => { | ||
return ( | ||
<Button | ||
className={classList(className, "sign-in-button")} | ||
rightIcon="xicon cloud-user large" | ||
title={lf("Sign In")} | ||
label={lf("Sign In")} | ||
onClick={onSignInClick} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as React from "react"; | ||
import { MenuDropdown, MenuItem } from "../controls/MenuDropdown"; | ||
import { classList } from "../util"; | ||
|
||
interface IProps { | ||
userProfile: pxt.auth.UserProfile; | ||
title: string; | ||
|
||
onSignOutClick?: () => void; | ||
className?: string; | ||
items?: MenuItem[]; | ||
} | ||
|
||
export const UserAvatarDropdown: React.FC<IProps> = (props) => { | ||
const { userProfile, title, items, onSignOutClick, className } = props; | ||
|
||
const avatarUrl = userProfile?.idp?.pictureUrl ?? encodedAvatarPic(userProfile); | ||
|
||
const avatarElem = <UserAvatar avatarPicUrl={avatarUrl} />; | ||
const initialsElem = <UserInitials userProfile={userProfile} />; | ||
|
||
const allItems = items ? items.slice() : []; | ||
|
||
if (onSignOutClick) { | ||
allItems.unshift({ | ||
id: "signout", | ||
title: lf("Sign Out"), | ||
label: lf("Sign Out"), | ||
onClick: onSignOutClick | ||
}); | ||
} | ||
|
||
return ( | ||
<MenuDropdown | ||
className={classList("user-avatar-dropdown", className)} | ||
title={title} | ||
label={avatarUrl ? avatarElem : initialsElem} | ||
items={allItems} | ||
/> | ||
); | ||
}; | ||
|
||
const UserInitials = (props: { userProfile: pxt.auth.UserProfile }) => ( | ||
<span> | ||
<div className="user-avatar-initials" aria-hidden="true">{pxt.auth.userInitials(props.userProfile)}</div> | ||
</span> | ||
); | ||
|
||
const UserAvatar = (props: { avatarPicUrl: string }) => ( | ||
<div className="user-avatar-image"> | ||
<img src={props.avatarPicUrl} alt={lf("Profile Image")} referrerPolicy="no-referrer" aria-hidden="true" /> | ||
</div> | ||
); | ||
|
||
function encodedAvatarPic(user: pxt.auth.UserProfile): string { | ||
const type = user?.idp?.picture?.mimeType; | ||
const encodedImg = user?.idp?.picture?.encoded; | ||
return type && encodedImg ? `data:${type};base64,${encodedImg}` : ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.common-button.sign-in-button { | ||
padding-left: 0.75rem; | ||
padding-right: 0.75rem; | ||
|
||
.common-button-label { | ||
font-family: Segoe UI, Tahoma, Geneva, Verdana; | ||
font-weight: 500; | ||
} | ||
} | ||
|
||
@media @tabletAndBelow { | ||
.common-button.sign-in-button { | ||
padding-left: 0.25rem; | ||
|
||
.common-button-label { | ||
display: none; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.user-avatar-image { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100%; | ||
|
||
img { | ||
border: solid 2px @buttonMenuTextColor; | ||
border-radius: 100%; | ||
width: 2.5rem; | ||
height: 2.5rem; | ||
} | ||
} | ||
|
||
.user-avatar-initials { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
border: solid 2px @buttonMenuTextColor; | ||
border-radius: 100%; | ||
width: 2.5rem; | ||
height: 2.5rem; | ||
|
||
background-color: var(--pxt-headerbar-accent); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.