Skip to content

Commit 307d014

Browse files
committed
Shuffle some functions around.
1 parent 7246ad8 commit 307d014

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

js/background/background.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ async function requestSpaceFromSessionId(sessionId) {
817817
async function requestAllSpaces() {
818818
// Get all sessions from spacesService (includes both saved and temporary open window sessions)
819819
const allSessions = await spacesService.getAllSessions();
820+
/** @type {Space[]} */
820821
const allSpaces = allSessions
821822
.map(session => {
822823
return { sessionId: session.id, ...session };

js/background/spacesService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class SpacesService {
363363

364364
/**
365365
* Get all sessions (includes both saved sessions and temporary open window sessions)
366-
* @returns {Promise<Array>} Promise that resolves to a shallow copy of all sessions
366+
* @returns {Promise<Array<Session>>} Promise that resolves to a shallow copy of all sessions
367367
*/
368368
async getAllSessions() {
369369
await this.ensureInitialized();

js/spacesRenderer.js

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
11
import { escapeHtml } from './utils.js';
22

3-
export function getDefaultSpaceTitle(space) {
4-
const count = space.tabs && space.tabs.length;
5-
if (!count) return '';
6-
const firstTitle = space.tabs[0].title;
7-
if (count === 1) {
8-
return `[${escapeHtml(firstTitle)}]`;
9-
}
10-
return firstTitle.length > 30
11-
? `[${escapeHtml(firstTitle.slice(0, 21))}&hellip;] +${count - 1} more`
12-
: `[${escapeHtml(firstTitle)}] +${count - 1} more`;
13-
}
14-
15-
export function getTabDetailsString(space) {
16-
const count = space.tabs && space.tabs.length;
17-
const open = space.windowId;
18-
19-
if (open) {
20-
return '';
21-
}
22-
return `(${count} tab${count !== 1 ? 's' : ''})`;
23-
}
3+
/** @typedef {import('./common.js').Space} Space */
244

255
// eslint-disable-next-line no-var
266
export const spacesRenderer = {
@@ -248,3 +228,40 @@ export const spacesRenderer = {
248228
}
249229
},
250230
};
231+
232+
// Module-level helper functions.
233+
234+
/**
235+
* Generates a default title for a space when it hasn't been named.
236+
* Based on the title of the first tab and the total number of tabs.
237+
* @param {Space} space - The space object
238+
* @returns {string} The generated title string
239+
*/
240+
export function getDefaultSpaceTitle(space) {
241+
const count = space.tabs && space.tabs.length;
242+
if (!count) return '';
243+
const firstTitle = space.tabs[0].title;
244+
if (count === 1) {
245+
return `[${escapeHtml(firstTitle)}]`;
246+
}
247+
return firstTitle.length > 30
248+
? `[${escapeHtml(firstTitle.slice(0, 21))}&hellip;] +${count - 1} more`
249+
: `[${escapeHtml(firstTitle)}] +${count - 1} more`;
250+
}
251+
252+
/**
253+
* Generates a string with the number of tabs in a space.
254+
* Returns an empty string if the space is currently open.
255+
* @param {Space} space - The space object
256+
* @returns {string} The generated string with the number of tabs
257+
*/
258+
export function getTabDetailsString(space) {
259+
const count = space.tabs && space.tabs.length;
260+
const open = space.windowId;
261+
262+
if (open) {
263+
return '';
264+
}
265+
return `(${count} tab${count !== 1 ? 's' : ''})`;
266+
}
267+

0 commit comments

Comments
 (0)