Skip to content

Commit

Permalink
team: Extract script to run to its own file.
Browse files Browse the repository at this point in the history
  • Loading branch information
amanagr committed Oct 11, 2023
1 parent e232b50 commit 65a6ba3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 53 deletions.
2 changes: 1 addition & 1 deletion templates/corporate/team.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "zerver/portico.html" %}
{% set entrypoint = "landing-page" %}
{% set entrypoint = "teams-page" %}

{% set PAGE_TITLE = "The Zulip team" %}

Expand Down
3 changes: 3 additions & 0 deletions web/src/page_params.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import $ from "jquery";

import type {Contributor} from "./portico/team_page_params_types";

const t1 = performance.now();
export const page_params: {
apps_page_url: string;
Expand All @@ -9,6 +11,7 @@ export const page_params: {
name: string;
allowed: boolean;
}[];
contributors: Contributor[] | undefined;
corporate_enabled: boolean;
delivery_email: string;
development_environment: boolean;
Expand Down
12 changes: 0 additions & 12 deletions web/src/portico/landing-page.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import $ from "jquery";

import {page_params} from "../page_params";

import render_tabs from "./team";

export function path_parts() {
return window.location.pathname.split("/").filter((chunk) => chunk !== "");
}

$(() => {
if (window.location.pathname === "/team/") {
const contributors = page_params.contributors;
delete page_params.contributors;
render_tabs(contributors);
}
});

// Scroll to anchor link when clicked. Note that help.js has a similar
// function; this file and help.js are never included on the same
// page.
Expand Down
33 changes: 33 additions & 0 deletions web/src/portico/team_page_params_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export const all_repository_names = [
"zulip",
"zulip-desktop",
"zulip-mobile",
"python-zulip-api",
"zulip-js",
"zulipbot",
"zulip-terminal",
"zulip-ios-legacy",
"zulip-android",
] as const;
type RepositoryName = (typeof all_repository_names)[number];

export const repo_name_to_tab_name: Record<RepositoryName, string> = {
zulip: "server",
"zulip-desktop": "desktop",
"zulip-mobile": "mobile",
"python-zulip-api": "python-zulip-api",
"zulip-js": "zulip-js",
zulipbot: "zulipbot",
"zulip-terminal": "terminal",
"zulip-ios-legacy": "",
"zulip-android": "",
};

export type Contributor = {
avatar: string;
email?: string;
github_username?: string;
name: string;
} & {
[K in RepositoryName]?: number;
};
52 changes: 12 additions & 40 deletions web/src/portico/team.ts → web/src/portico/teams_page.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,10 @@
import $ from "jquery";
import _ from "lodash";

// The list of repository names is duplicated here in order to provide
// a clear type for Contributor objects.
//
// TODO: We can avoid this if we introduce a `contributions` object
// referenced from Contributor, rather than having repository names be
// direct keys in the namespace that also has `email`.
const all_repository_names = [
"zulip",
"zulip-desktop",
"zulip-mobile",
"python-zulip-api",
"zulip-js",
"zulipbot",
"zulip-terminal",
"zulip-ios-legacy",
"zulip-android",
] as const;
type RepositoryName = (typeof all_repository_names)[number];

const repo_name_to_tab_name: Record<RepositoryName, string> = {
zulip: "server",
"zulip-desktop": "desktop",
"zulip-mobile": "mobile",
"python-zulip-api": "python-zulip-api",
"zulip-js": "zulip-js",
zulipbot: "zulipbot",
"zulip-terminal": "terminal",
"zulip-ios-legacy": "",
"zulip-android": "",
};

export type Contributor = {
avatar: string;
email?: string;
github_username?: string;
name: string;
} & {
[K in RepositoryName]?: number;
};
import {page_params} from "../page_params";

import type {Contributor} from "./team_page_params_types";
import {all_repository_names, repo_name_to_tab_name} from "./team_page_params_types";

// Remember the loaded repositories so that HTML is not redundantly edited
// if a user leaves and then revisits the same tab.
Expand Down Expand Up @@ -90,7 +55,10 @@ function exclude_bot_contributors(contributor: Contributor): boolean {
// TODO (for v2 of /team/ contributors):
// - Make tab header responsive.
// - Display full name instead of GitHub username.
export default function render_tabs(contributors: Contributor[]): void {
export default function render_tabs(contributors: Contributor[] | undefined): void {
if (!contributors) {
return;
}
const template = _.template($("#contributors-template").html());
const count_template = _.template($("#count-template").html());
const total_count_template = _.template($("#total-count-template").html());
Expand Down Expand Up @@ -171,3 +139,7 @@ export default function render_tabs(contributors: Contributor[]): void {
});
}
}

const contributors = page_params.contributors;
delete page_params.contributors;
render_tabs(contributors);
5 changes: 5 additions & 0 deletions web/webpack.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
"./src/portico/apps_download",
"./styles/portico/landing_page.css"
],
"teams-page": [
"./src/bundles/portico",
"./src/portico/teams_page",
"./styles/portico/landing_page.css"
],
"landing-page-hello": [
"./src/bundles/hello",
"./src/portico/hello",
Expand Down

0 comments on commit 65a6ba3

Please sign in to comment.