ok, now git statuses is a store

This commit is contained in:
Scott Chacon 2023-03-09 12:16:29 -08:00
parent 2d9e738038
commit 0208068a0f
4 changed files with 45 additions and 10 deletions

38
src/lib/statuses.ts Normal file
View 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[]>;
};

View File

@ -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[]>([])

View File

@ -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>

View File

@ -14,7 +14,6 @@
const { project } = data;
const urlParams = new URLSearchParams(window.location.search);
console.log(urlParams.get('search'));
let query: string;