rename method

Signed-off-by: Alex Rybchenko <arybchenko@box.com>
This commit is contained in:
Alex Rybchenko
2022-07-19 16:10:43 +02:00
parent 5416c9af06
commit a6407c0f82
5 changed files with 11 additions and 14 deletions
+3 -3
View File
@@ -20,14 +20,14 @@ export class LocalStoredShortcuts implements ShortcutApi {
// (undocumented)
add(shortcut: Omit<Shortcut, 'id'>): Promise<void>;
// (undocumented)
get(): Shortcut[];
// (undocumented)
getColor(url: string): string;
// (undocumented)
remove(id: string): Promise<void>;
// (undocumented)
shortcut$(): Observable_2<Shortcut[]>;
// (undocumented)
snapshot(): Shortcut[];
// (undocumented)
update(shortcut: Shortcut): Promise<void>;
}
@@ -45,10 +45,10 @@ export type Shortcut = {
// @public (undocumented)
export interface ShortcutApi {
add(shortcut: Omit<Shortcut, 'id'>): Promise<void>;
get(): Shortcut[];
getColor(url: string): string;
remove(id: string): Promise<void>;
shortcut$(): Observable<Shortcut[]>;
snapshot(): Shortcut[];
update(shortcut: Shortcut): Promise<void>;
}
+1 -4
View File
@@ -39,10 +39,7 @@ export interface ShortcutsProps {
export const Shortcuts = (props: ShortcutsProps) => {
const shortcutApi = useApi(shortcutsApiRef);
const shortcuts = useObservable(
shortcutApi.shortcut$(),
shortcutApi.snapshot(),
);
const shortcuts = useObservable(shortcutApi.shortcut$(), shortcutApi.get());
const [anchorEl, setAnchorEl] = React.useState<Element | undefined>();
const loading = Boolean(!shortcuts);
@@ -33,27 +33,27 @@ export class LocalStoredShortcuts implements ShortcutApi {
);
}
snapshot() {
get() {
return Array.from(
this.storageApi.snapshot<Shortcut[]>('items').value ?? [],
).sort((a, b) => (a.title >= b.title ? 1 : -1));
}
async add(shortcut: Omit<Shortcut, 'id'>) {
const shortcuts = this.snapshot();
const shortcuts = this.get();
shortcuts.push({ ...shortcut, id: uuid() });
await this.storageApi.set('items', shortcuts);
}
async remove(id: string) {
const shortcuts = this.snapshot().filter(s => s.id !== id);
const shortcuts = this.get().filter(s => s.id !== id);
await this.storageApi.set('items', shortcuts);
}
async update(shortcut: Shortcut) {
const shortcuts = this.snapshot().filter(s => s.id !== shortcut.id);
const shortcuts = this.get().filter(s => s.id !== shortcut.id);
shortcuts.push(shortcut);
await this.storageApi.set('items', shortcuts);
+1 -1
View File
@@ -31,7 +31,7 @@ export interface ShortcutApi {
/**
* Returns an immediate snapshot of shortcuts, sorted by title
*/
snapshot(): Shortcut[];
get(): Shortcut[];
/**
* Generates a unique id for the shortcut and then saves it.