-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event Emission from viewmodel to Event Manager and Rename Project Flow Update #645
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ dismiss the modal correctly. | |
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
|
||
export let onSubmit: () => void = () => {}; | ||
export let onDismiss: () => void; | ||
export let left: number = 0; | ||
export let top: number = 0; | ||
|
@@ -27,6 +28,8 @@ onMount(() => { | |
function onKeyDown(event: KeyboardEvent) { | ||
if (event.key === 'Escape') { | ||
dismiss(); | ||
} else if (event.key === 'Enter') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should handle this key inside the modal component container. This key should be captured explicitly by the content of the modal. |
||
submit(); | ||
} | ||
} | ||
|
||
|
@@ -62,6 +65,12 @@ function dismiss() { | |
onDismiss(); | ||
} | ||
|
||
function submit() { | ||
checkbox = null; | ||
onSubmit(); | ||
onDismiss(); | ||
} | ||
|
||
function createStyle() { | ||
let adjustedLeft = left + width > window.innerWidth ? window.innerWidth - width : left; | ||
return [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { Flow } from '../../../libs/flow'; | ||
import { type ProjectItem, sampleProjectItems } from './model'; | ||
import { UUID } from '../../../mono/uuid'; | ||
import type { ActionManager } from '$mono/action-manager/action-manager'; | ||
import { OneTimeAction } from '$mono/action-manager/one-time-actions'; | ||
import { AppContext } from '$app/app-context'; | ||
|
||
class ProjectDataViewModel { | ||
private _projectFlow: Flow<ProjectItem[]> = new Flow(); | ||
|
@@ -10,6 +13,8 @@ class ProjectDataViewModel { | |
deletingProjectIdFlow: Flow<string> = new Flow(''); | ||
renamingProjectIdFlow: Flow<string> = new Flow(''); | ||
|
||
constructor(private actionManager: ActionManager) {} | ||
|
||
setProjectList(projectList: ProjectItem[]) { | ||
this._projectFlow.value = projectList; | ||
this.openingProjectIdFlow.value = projectList[0].id; | ||
|
@@ -22,11 +27,18 @@ class ProjectDataViewModel { | |
}; | ||
this.setProjectList([newProject, ...this._projectFlow.value!]); | ||
this.openProject(newProject.id); | ||
this.setRenamingProject(newProject.id); | ||
this.setRenamingProject(newProject.id, newProject.name); | ||
this.actionManager.setOneTimeAction(OneTimeAction.ProjectAction.NewProject); | ||
} | ||
|
||
openProject(id: string) { | ||
this.openingProjectIdFlow.value = id; | ||
// Reorder the project list, move the opened project to the top | ||
const currentProject = this._projectFlow.value!.find((item) => item.id === id); | ||
if (currentProject) { | ||
this._projectFlow.value = [currentProject, ...this._projectFlow.value!.filter((item) => item.id !== id)]; | ||
} | ||
this.actionManager.setOneTimeAction(OneTimeAction.ProjectAction.SwitchProject(id)); | ||
} | ||
|
||
confirmDeletingProject(id: string) { | ||
|
@@ -35,14 +47,17 @@ class ProjectDataViewModel { | |
|
||
deleteProject(id: string) { | ||
this._projectFlow.value = this._projectFlow.value!.filter((item) => item.id !== id); | ||
this.actionManager.setOneTimeAction(OneTimeAction.ProjectAction.RemoveProject(id)); | ||
} | ||
|
||
cancelDeletingProject() { | ||
this.deletingProjectIdFlow.value = ''; | ||
} | ||
|
||
setRenamingProject(id: string) { | ||
setRenamingProject(id: string, newName: string) { | ||
console.log("Project id: " + id); | ||
this.renamingProjectIdFlow.value = id; | ||
this.actionManager.setOneTimeAction(OneTimeAction.ProjectAction.RenameCurrentProject(newName)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not correct. |
||
} | ||
|
||
setProjectName(id: string, name: string) { | ||
|
@@ -55,12 +70,15 @@ class ProjectDataViewModel { | |
} | ||
return item; | ||
}); | ||
this.actionManager.setOneTimeAction(OneTimeAction.ProjectAction.RenameCurrentProject(name)); | ||
} | ||
|
||
getProject(id: string): ProjectItem | undefined { | ||
console.log(this._projectFlow.value); | ||
return this._projectFlow.value!.find((item) => item.id === id); | ||
} | ||
} | ||
|
||
export const projectDataViewModel = new ProjectDataViewModel(); | ||
const appContext = new AppContext(); | ||
export const projectDataViewModel = new ProjectDataViewModel(appContext.actionManager); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not correct. |
||
projectDataViewModel.setProjectList(sampleProjectItems); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve initialized it as an empty function to ensure it's optional—other components using this one won’t need any changes, and everything will work as before if the function isn’t needed.