Skip to content

Commit

Permalink
Merge pull request #114 from yatt-ai/ok/abstracting-business-logic
Browse files Browse the repository at this point in the history
Ok/abstracting business logic
  • Loading branch information
dacoaster authored Jan 17, 2024
2 parents 92e99f1 + 4d3a00c commit 2619d7d
Show file tree
Hide file tree
Showing 56 changed files with 3,557 additions and 1,777 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
node_modules
/dist
db-rest-mock.json


# local env files
Expand Down
68 changes: 44 additions & 24 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
</template>

<script>
import { IPC_HANDLERS, IPC_FUNCTIONS } from "./modules/constants";
const default_layout = "default";
export default {
Expand All @@ -18,33 +16,55 @@ export default {
return (this.$route.meta.layout || default_layout) + "-layout";
},
},
beforeCreate() {
async beforeCreate() {
// Only restore state for the primary window that opens at HomeView
if (this.$router.history.current.path === "/") {
window.ipc
.invoke(IPC_HANDLERS.DATABASE, {
func: IPC_FUNCTIONS.GET_STATE,
})
.then((state) => {
if (Object.keys(state).length > 0) {
this.$store.commit("restoreState", state);
const currentPath = this.$router.history.current.path;
if (state.path && currentPath !== state.path) {
if (state.path.includes("result")) {
window.ipc.invoke(IPC_HANDLERS.WINDOW, {
func: IPC_FUNCTIONS.SET_WINDOW_SIZE,
data: {
width: 1440,
height: 900,
},
});
}
this.$router.push({ path: state.path });
}
const state = await this.$storageService.getState();
if (Object.keys(state).length) {
await this.$store.commit("restoreState", state);
const currentPath = this.$router.history.current.path;
if (state.path && currentPath !== state.path) {
if (state.path.includes("result") && this.$isElectron) {
this.$electronService.setWindowSize({ width: 1440, height: 900 });
}
});
await this.$router.push({ path: state.path });
}
}
}
},
async created() {
const config = await this.$storageService.getConfig();
this.$store.commit("config/setFullConfig", config);
const credentials = await this.$storageService.getCredentials();
this.$store.commit("auth/setCredentials", credentials);
if (this.$isElectron) {
// todo remove this check when $integrationHelpers will support REST API
await this.updateAuth();
}
},
methods: {
async updateAuth() {
if (
this.$store.getters["auth/credentials"] &&
Object.entries(this.$store.getters["auth/credentials"]).length > 0
) {
let authCheckResponse = await this.$integrationHelpers.checkAuth(
this.$store.getters["auth/credentials"]
);
this.$store.commit("auth/setIsAuthenticated", authCheckResponse.authed);
if (authCheckResponse.failedAuth?.length > 0) {
// TODO - Prompt the user if they'd like to remove the failing cred
let message = "";
for (const failedCred of authCheckResponse.failedAuth) {
message += `${failedCred.credentialType} `;
}
message += this.$tc("message.integrations_expired", 1);
this.setSnackBar(message);
}
}
},
},
};
</script>
<style scoped>
Expand Down
56 changes: 28 additions & 28 deletions src/components/AudioWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@

<script>
import WaveSurfer from "wavesurfer.js";
import { IPC_HANDLERS, IPC_FUNCTIONS, STATUSES } from "../modules/constants";
import { STATUSES } from "@/modules/constants";
export default {
name: "AudioWrapper",
props: {
Expand Down Expand Up @@ -198,8 +199,7 @@ export default {
// return this.wavesurfer.getCurrentTime();
const duration = parseFloat(this.wavesurfer.getDuration());
const current = parseFloat(this.wavesurfer.getCurrentTime());
const result = Math.round((current / duration) * 100);
this.currentProgress = result;
this.currentProgress = Math.round((current / duration) * 100);
},
syncSlideWithAudio() {
this.wavesurfer.seekTo(this.currentProgress / 100);
Expand All @@ -214,35 +214,35 @@ export default {
this.wavesurfer.setVolume(volume);
},
async handleAudio() {
const uri = this.wavesurfer.exportImage("image/png", 1, "dataURL");
if (this.$isElectron) {
// todo add web handler
const uri = this.wavesurfer.exportImage("image/png", 1, "dataURL");
let posterResult = await window.ipc.invoke(IPC_HANDLERS.CAPTURE, {
func: IPC_FUNCTIONS.CREATE_IMAGE,
data: { url: uri, isPoster: true },
});
if (posterResult.status === STATUSES.ERROR) {
this.$root.$emit("set-snackbar", posterResult.message);
console.log(
"Unable to generate waveform image: " + posterResult.message
);
}
let posterResult = await this.$electronService.createImage(uri, true);
let audioResult = await window.ipc.invoke(IPC_HANDLERS.CAPTURE, {
func: IPC_FUNCTIONS.UPDATE_AUDIO,
data: { item: this.sessionItem },
});
if (posterResult.status === STATUSES.ERROR) {
this.$root.$emit("set-snackbar", posterResult.message);
console.log(
"Unable to generate waveform image: " + posterResult.message
);
}
let audioResult = await this.$electronService.updateAudio(
this.sessionItem
);
if (audioResult.status === STATUSES.ERROR) {
this.$root.$emit("set-snackbar", audioResult.message);
console.log("Unable to update audio file: " + audioResult.message);
if (audioResult.status === STATUSES.ERROR) {
this.$root.$emit("set-snackbar", audioResult.message);
console.log("Unable to update audio file: " + audioResult.message);
}
this.sessionItem = {
...this.sessionItem,
poster: posterResult.item.filePath,
...audioResult.item,
};
this.$root.$emit("update-session", this.sessionItem);
this.$root.$emit("save-data", this.sessionItem);
}
this.sessionItem = {
...this.sessionItem,
poster: posterResult.item.filePath,
...audioResult.item,
};
this.$root.$emit("update-session", this.sessionItem);
this.$root.$emit("save-data", this.sessionItem);
},
},
};
Expand Down
29 changes: 12 additions & 17 deletions src/components/CheckTaskWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
@shortkey="$hotkeyHelpers.focusField($refs, 'form')"
>
<v-form ref="form" v-model="valid" lazy-validation>
<div class="" v-for="task in tasks" :key="task.id">
<div v-for="task in tasks" :key="task.id">
<v-checkbox
v-model="task.checked"
:value="task.checked"
@change="(val) => $emit('taskToggle', task.id, val)"
:rules="rules(task.required)"
:label="`${task.content}`"
dense
Expand All @@ -34,38 +35,37 @@
</div>
</template>
<script>
import { mapGetters } from "vuex";
export default {
name: "CheckTaskWrapper",
props: {
configItem: {
type: Object,
default: () => {},
},
tasks: {
type: Array,
default: () => [],
},
type: {
type: String,
defaut: () => "pressession",
},
},
data() {
return {
valid: true,
config: this.configItem,
};
},
mounted() {
this.$root.$on("start-new-session", () => {
this.handleValidate();
});
this.$root.$on("end-session", () => {
this.handleValidate();
});
},
computed: {
...mapGetters({
hotkeys: "config/hotkeys",
}),
checklistHotkey() {
return this.$hotkeyHelpers.findBinding(
"sessionPlanning.checklist",
this.config.hotkeys
this.hotkeys
);
},
currentTheme() {
Expand All @@ -76,11 +76,6 @@ export default {
}
},
},
watch: {
configItem: function (newValue) {
this.config = newValue;
},
},
methods: {
rules(required) {
if (required) {
Expand Down
Loading

0 comments on commit 2619d7d

Please sign in to comment.