Skip to content

Commit

Permalink
fix: remove occurrence after delete (#26)
Browse files Browse the repository at this point in the history
* fix: remove occurrence after delete
  • Loading branch information
Adjilino authored Oct 23, 2023
1 parent 767ab94 commit 2c424da
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tesla-eyes",
"version": "0.8.1",
"version": "0.8.2",
"description": "",
"scripts": {
"start": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "app"
version = "0.8.1"
version = "0.8.2"
description = "Tesla eyes app. Sentry Mode and Dashcam viewer"
authors = ["adjilino"]
license = ""
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"package": {
"productName": "Tesla eyes",
"version": "0.8.1"
"version": "0.8.2"
},
"tauri": {
"allowlist": {
Expand Down
16 changes: 15 additions & 1 deletion src/components/main-view/Timelime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { Show, createMemo, createSignal } from "solid-js";
import { Occurrence } from "../../models";
import {
currentTime,
fileByOccurrence,
isPlaying,
selectedOccurrence,
selectedOccurrenceFiles,
setChangeCurrentTime,
setFilesByOccurrences,
setIsPlaying,
setSelectedOccurrence,
} from "../../stores";
import { Button } from "../../ui";
import timelineStyles from "./Timelime.module.css";
import { tauri } from "../../utils";

function addVideoShortcutControls() {
window.addEventListener("keydown", (event) => {
Expand Down Expand Up @@ -150,7 +154,7 @@ export function Timeline() {
};

const removeOccurence = async (occurence: Occurrence | null) => {
if (!occurence || !occurence.directory || !window["__TAURI__"]?.tauri) {
if (!occurence || !occurence.directory || !tauri?.tauri) {
return;
}

Expand All @@ -169,6 +173,16 @@ export function Timeline() {
removeDir(occurence.directory, {
recursive: true,
});

const _fileByOccurence = fileByOccurrence();
const _selectedOccurrenceFile = selectedOccurrenceFiles();
if (_fileByOccurence && _selectedOccurrenceFile) {
setFilesByOccurrences(
_fileByOccurence.filter(
(file) => file.getId() !== _selectedOccurrenceFile.getId()
)
);
}
};

return (
Expand Down
54 changes: 30 additions & 24 deletions src/models/occurence-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@ import { FileEntry } from "@tauri-apps/api/fs";
import { OccurenceBuilder } from "../builders/occurence.builder";
import { Config } from "./config";
import { Occurrence } from "./occurence";
import { uuidv4 } from "../utils";

export class OccurrenceFiles {
files: Array<File | FileEntry> = [];
config?: Config = undefined;
thumbnail?: string | undefined = undefined;
protected id: string = uuidv4();
files: Array<File | FileEntry> = [];
config?: Config = undefined;
thumbnail?: string | undefined = undefined;

setConfig(config: Config | undefined): void {
this.config = config;
}
getConfig(): Config | undefined {
return this.config;
}
getId(): string {
return this.id;
}

setThumbnail(thumbnail: string | undefined): void {
this.thumbnail = thumbnail;
}
getThumbnail(): string | undefined {
return this.thumbnail;
}
setConfig(config: Config | undefined): void {
this.config = config;
}
getConfig(): Config | undefined {
return this.config;
}

setFiles(files: Array<File | FileEntry>): void {
this.files = files;
}
getFiles(): Array<File | FileEntry> {
return this.files;
}
setThumbnail(thumbnail: string | undefined): void {
this.thumbnail = thumbnail;
}
getThumbnail(): string | undefined {
return this.thumbnail;
}

toOccurrence(): Promise<Occurrence | undefined> {
return new OccurenceBuilder().addFiles(this.files).build();
}
setFiles(files: Array<File | FileEntry>): void {
this.files = files;
}
getFiles(): Array<File | FileEntry> {
return this.files;
}

toOccurrence(): Promise<Occurrence | undefined> {
return new OccurenceBuilder().addFiles(this.files).build();
}
}
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './to-base64';
export * from './tauri';

export * from './uuid';
8 changes: 8 additions & 0 deletions src/utils/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function uuidv4() {
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c: any) =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
);
}

0 comments on commit 2c424da

Please sign in to comment.