mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	ts: Convert color_data module to TypeScript.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							adf83c6eb7
						
					
				
				
					commit
					91573531bb
				
			@@ -1,6 +1,7 @@
 | 
				
			|||||||
import _ from "lodash";
 | 
					import _ from "lodash";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export let unused_colors;
 | 
					export let unused_colors: string[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// These colors are used now for streams.
 | 
					// These colors are used now for streams.
 | 
				
			||||||
const stream_colors = [
 | 
					const stream_colors = [
 | 
				
			||||||
    "#76ce90",
 | 
					    "#76ce90",
 | 
				
			||||||
@@ -33,13 +34,13 @@ const stream_colors = [
 | 
				
			|||||||
// bias toward "early" colors.
 | 
					// bias toward "early" colors.
 | 
				
			||||||
export const colors = _.shuffle(stream_colors);
 | 
					export const colors = _.shuffle(stream_colors);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function reset() {
 | 
					export function reset(): void {
 | 
				
			||||||
    unused_colors = colors.slice();
 | 
					    unused_colors = colors.slice();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
reset();
 | 
					reset();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function claim_color(color) {
 | 
					export function claim_color(color: string): void {
 | 
				
			||||||
    const i = unused_colors.indexOf(color);
 | 
					    const i = unused_colors.indexOf(color);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (i < 0) {
 | 
					    if (i < 0) {
 | 
				
			||||||
@@ -53,14 +54,14 @@ export function claim_color(color) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function claim_colors(subs) {
 | 
					export function claim_colors(subs: {color: string}[]): void {
 | 
				
			||||||
    const colors = new Set(subs.map((sub) => sub.color));
 | 
					    const colors = new Set(subs.map((sub) => sub.color));
 | 
				
			||||||
    for (const color of colors) {
 | 
					    for (const color of colors) {
 | 
				
			||||||
        claim_color(color);
 | 
					        claim_color(color);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function pick_color() {
 | 
					export function pick_color(): string {
 | 
				
			||||||
    const color = unused_colors[0];
 | 
					    const color = unused_colors[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    claim_color(color);
 | 
					    claim_color(color);
 | 
				
			||||||
		Reference in New Issue
	
	Block a user