Skip to content

Commit

Permalink
Add ticks for loading projects
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed Sep 20, 2024
1 parent e755114 commit 9207098
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions teachertool/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { SignedOutPanel } from "./components/SignedOutPanel";
import * as authClient from "./services/authClient";
import { ErrorCode } from "./types/errorCode";
import { loadProjectMetadataAsync } from "./transforms/loadProjectMetadataAsync";
import { Ticks } from "./constants";

export const App = () => {
const { state, dispatch } = useContext(AppStateContext);
Expand Down Expand Up @@ -47,6 +48,7 @@ export const App = () => {
const decoded = decodeURIComponent(projectParam);
const shareId = pxt.Cloud.parseScriptId(decoded);
if (!!shareId) {
pxt.tickEvent(Ticks.LoadProjectFromUrl);
await loadProjectMetadataAsync(decoded, shareId);
}
}
Expand Down
12 changes: 11 additions & 1 deletion teachertool/src/components/ShareLinkInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { AppStateContext } from "../state/appStateContext";
import { classList } from "react-common/components/util";
import { Input } from "react-common/components/controls/Input";
import { loadProjectMetadataAsync } from "../transforms/loadProjectMetadataAsync";
import { Strings, Ticks } from "../constants";
import { getChecklistHash, makeToast } from "../utils";
import { showToast } from "../transforms/showToast";

interface IProps {}

Expand All @@ -26,7 +29,14 @@ export const ShareLinkInput: React.FC<IProps> = () => {

const onEnterKey = useCallback(() => {
const shareId = pxt.Cloud.parseScriptId(text);
if (!!shareId && !(shareId === projectMetadata?.shortid || shareId === projectMetadata?.persistId)) {
if (!shareId) {
pxt.tickEvent(Ticks.LoadProjectInvalid);
showToast(makeToast("error", lf(Strings.InvalidShareLink)));
return;
}

if (shareId !== projectMetadata?.shortid && shareId !== projectMetadata?.persistId) {
pxt.tickEvent(Ticks.LoadProjectFromInput, { checklistHash: getChecklistHash(teacherTool.checklist) });
loadProjectMetadataAsync(text, shareId);
}
}, [text, projectMetadata?.shortid, projectMetadata?.persistId]);
Expand Down
4 changes: 4 additions & 0 deletions teachertool/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export namespace Strings {
export const BelowMin = lf("Below minimum value");
export const ExceedsMax = lf("Exceeds maximum value");
export const InvalidValue = lf("Invalid value");
export const InvalidShareLink = lf("Invalid share link");
}

export namespace Ticks {
Expand Down Expand Up @@ -89,6 +90,9 @@ export namespace Ticks {
export const ParamErrorMissingMessage = "teachertool.paramerrormissingmessage";
export const SetEvalResultOutcome = "teachertool.setevalresultoutcome";
export const SetEvalResultNotes = "teachertool.setevalresultnotes";
export const LoadProjectFromInput = "teachertool.loadproject.frominput";
export const LoadProjectFromUrl = "teachertool.loadproject.fromurl";
export const LoadProjectInvalid = "teachertool.loadproject.invalid";
}

namespace Misc {
Expand Down
2 changes: 1 addition & 1 deletion teachertool/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function getReadableBlockString(name: string) {
export function getChecklistHash(checklist: Checklist): string {
// We only hash the criteria (not the name), since the name doesn't really matter in our scenarios,
// and it could be translated, etc for built-in checklists.
return pxt.Util.sha256(JSON.stringify(checklist.criteria));
return checklist.criteria.length == 0 ? "empty" : pxt.Util.sha256(JSON.stringify(checklist.criteria));
}

export function getObfuscatedProjectId(projectId: string | undefined): string {
Expand Down

0 comments on commit 9207098

Please sign in to comment.