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 10, 2023
1 parent 3e16203 commit dfaa6b9
Show file tree
Hide file tree
Showing 5 changed files with 51 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
35 changes: 35 additions & 0 deletions web/src/page_params.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
import $ from "jquery";

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;
};

const t1 = performance.now();
export const page_params: {
apps_page_url: string;
Expand All @@ -10,6 +44,7 @@ export const page_params: {
allowed: boolean;
}[];
corporate_enabled: boolean;
contributors: Contributor[] | undefined;
development_environment: boolean;
language_list: {
code: string;
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
50 changes: 10 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,8 @@
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 type {Contributor} from "../page_params";
import {all_repository_names, page_params, repo_name_to_tab_name} from "../page_params";

// 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 +53,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 +137,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 dfaa6b9

Please sign in to comment.