|
1 | | -import { FigmaFilesStore } from "store/fimga-file-store/figma-file-store"; |
| 1 | +import { |
| 2 | + FigmaFilesStore, |
| 3 | + FileResponseRecord, |
| 4 | +} from "store/fimga-file-store/figma-file-store"; |
| 5 | + |
| 6 | +export type LastUsedFileDisplay = FileResponseRecord & { type: "file" } & { |
| 7 | + lastUsed: Date; |
| 8 | +}; |
| 9 | +export type LastusedDisplayType = LastUsedFileDisplay; |
2 | 10 |
|
3 | 11 | export class WorkspaceRepository { |
4 | 12 | constructor() {} |
5 | 13 |
|
6 | 14 | async getRecents({ count = 4 }: { count?: number }) { |
7 | | - const fetches = []; |
8 | | - fetches.push(this.getRecentFiles()); |
9 | | - fetches.push(this.getRecentScenes()); |
10 | | - fetches.push(this.getRecentComponents()); |
| 15 | + const fetches: LastusedDisplayType[] = []; |
| 16 | + const files = (await this.getFiles()).map( |
| 17 | + (f) => |
| 18 | + <LastusedDisplayType>{ |
| 19 | + ...f, |
| 20 | + type: "file", |
| 21 | + } |
| 22 | + ); |
| 23 | + fetches.push(...files); |
| 24 | + // fetches.push(this.getRecentScenes()); |
| 25 | + // fetches.push(this.getRecentComponents()); |
11 | 26 |
|
12 | 27 | const allRecents = await Promise.all(fetches); |
13 | | - const recents = allRecents.sort((r) => r.lastUsed).slice(0, count); |
| 28 | + const recents = allRecents |
| 29 | + .sort((r, r2) => (r2.lastUsed > r.lastUsed ? 1 : -1)) |
| 30 | + .slice(0, count); |
| 31 | + |
14 | 32 | return recents; |
15 | 33 | } |
16 | 34 |
|
17 | | - async getFiles(): Promise<any[]> { |
| 35 | + async getFiles() { |
18 | 36 | return FigmaFilesStore.all(); |
19 | | - return [ |
20 | | - "JRD2EdsbBlWgib8NzTXIGo", |
21 | | - "HSozKEVWhh8saZa2vr1Nxd", |
22 | | - "Gaznaw1QHppxvs9UkqNOb0", |
23 | | - "Y0Gh77AqBoHH7dG1GtK3xF", |
24 | | - "iypAHagtcSp3Osfo2a7EDz", |
25 | | - "x7RRK6RwWtZuNakmbMLTVH", |
26 | | - ].map((id) => { |
27 | | - return { |
28 | | - id: id, |
29 | | - file: id, |
30 | | - name: id, |
31 | | - lastUsed: new Date("2021-01-01"), |
32 | | - }; |
33 | | - }); |
34 | | - } |
35 | | - |
36 | | - async getRecentFiles() { |
37 | | - return this.getFiles(); |
38 | 37 | } |
39 | 38 |
|
40 | 39 | async getRecentScenes() { |
|
0 commit comments