mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-29 20:43:37 +03:00
ok, now git statuses is a store
This commit is contained in:
parent
2d9e738038
commit
0208068a0f
38
src/lib/statuses.ts
Normal file
38
src/lib/statuses.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { appWindow } from '@tauri-apps/api/window';
|
||||
import { writable, type Readable } from 'svelte/store';
|
||||
import { log } from '$lib';
|
||||
import type { Session } from '$lib/sessions';
|
||||
|
||||
export type Status = {
|
||||
path: string;
|
||||
status: string;
|
||||
};
|
||||
|
||||
const listFiles = (params: { projectId: string; }) =>
|
||||
invoke<Record<string, string>>('git_status', params);
|
||||
|
||||
function convertToStatuses(statusesGit: Record<string, string>): Status[] {
|
||||
return Object.entries(statusesGit).map((status) => {
|
||||
return {
|
||||
path: status[0],
|
||||
status: status[1]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default async (params: { projectId: string }) => {
|
||||
const statusesGit = await listFiles(params);
|
||||
const statuses = convertToStatuses(statusesGit)
|
||||
|
||||
const store = writable(statuses);
|
||||
|
||||
appWindow.listen<Session>(`project://${params.projectId}/sessions`, async (event) => {
|
||||
log.info(`Received sessions event, projectId: ${params.projectId}`);
|
||||
const statusesGit = await listFiles(params);
|
||||
const statuses = convertToStatuses(statusesGit)
|
||||
store.set(statuses)
|
||||
});
|
||||
|
||||
return store as Readable<Status[]>;
|
||||
};
|
@ -3,18 +3,18 @@ import { building } from '$app/environment';
|
||||
import { readable, derived } from 'svelte/store';
|
||||
import type { Session } from '$lib/sessions';
|
||||
import type { UISession } from '$lib/uisessions';
|
||||
import type { Status } from '$lib/statuses';
|
||||
import { asyncDerived } from '@square/svelte-store';
|
||||
import type { Delta } from '$lib/deltas';
|
||||
import { startOfDay } from 'date-fns';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
|
||||
export const prerender = false;
|
||||
export const load: LayoutLoad = async ({ parent, params }) => {
|
||||
const { projects } = await parent();
|
||||
|
||||
const filesStatus = building
|
||||
? readable<Record<string, string>>({})
|
||||
: await invoke<Record<string, string>>('git_status', { projectId: params.projectId });
|
||||
let filesStatus = building
|
||||
? readable<Status[]>([])
|
||||
: await (await import('$lib/statuses')).default({ projectId: params.projectId });
|
||||
|
||||
const sessions = building
|
||||
? readable<Session[]>([])
|
||||
|
@ -98,7 +98,6 @@
|
||||
let recentActivity = [];
|
||||
if (dateSessions) {
|
||||
Object.entries(dateSessions).forEach(([date, sessions]) => {
|
||||
console.log(date, sessions);
|
||||
sessions.forEach((session) => {
|
||||
if (session.session) {
|
||||
session.session.activity.forEach((activity) => {
|
||||
@ -111,7 +110,6 @@
|
||||
let activitySorted = recentActivity.sort((a, b) => {
|
||||
return b.timestampMs - a.timestampMs;
|
||||
});
|
||||
console.log(activitySorted);
|
||||
return activitySorted.slice(0, 20);
|
||||
}
|
||||
</script>
|
||||
@ -158,10 +156,10 @@
|
||||
{:else}
|
||||
<div class="bg-blue-900 p-4 rounded">
|
||||
<ul class="">
|
||||
{#each Object.entries(filesStatus) as activity}
|
||||
{#each $filesStatus as activity}
|
||||
<li>
|
||||
{activity[1].slice(0, 1)}
|
||||
{shortPath(activity[0])}
|
||||
{activity.status.slice(0, 1)}
|
||||
{shortPath(activity.path)}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
@ -14,7 +14,6 @@
|
||||
const { project } = data;
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
console.log(urlParams.get('search'));
|
||||
|
||||
let query: string;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user