-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from codex-team/feat/add-tool-from-markeplace
feat(marketplace): added ability to install/uninstall tools
- Loading branch information
Showing
11 changed files
with
172 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,65 @@ | ||
import type EditorTool from '@/domain/entities/EditorTool'; | ||
import { type Ref, ref, onMounted } from 'vue'; | ||
import { type Ref, ref, watch, onMounted } from 'vue'; | ||
import { marketplaceService } from '@/domain'; | ||
import type { EditorToolWithUserBinding } from '@/domain/entities/EditorTool'; | ||
import { useAppState } from './useAppState'; | ||
import type EditorTool from '@/domain/entities/EditorTool'; | ||
|
||
/** | ||
* Composable for the application state | ||
*/ | ||
interface UseMarketplaceComposable { | ||
/** | ||
* All editor tools that are used in notes creation | ||
* List of tools with information, if they are installed by the user | ||
*/ | ||
tools: Ref<EditorTool[]>; | ||
tools: Ref<EditorToolWithUserBinding[]>; | ||
} | ||
|
||
/** | ||
* Application service for working with the Editor Tools | ||
*/ | ||
export default function (): UseMarketplaceComposable { | ||
const toolsWithUserBindings = ref<EditorToolWithUserBinding[]>([]); | ||
const availableTools = ref<EditorTool[]>([]); | ||
|
||
/** | ||
* All editor tools | ||
* Create a list of tools with information, if they are installed by the user | ||
* | ||
* @param tools - list of all tools | ||
* @param userTools - list of user tools | ||
*/ | ||
const tools = ref<EditorTool[]>([]); | ||
const getToolsWithUserBindings = (tools: EditorTool[], userTools: EditorTool[]): EditorToolWithUserBinding[] => { | ||
return tools.map((tool) => { | ||
return { | ||
...tool, | ||
isInstalled: userTools.some((userTool) => userTool.id === tool.id), | ||
}; | ||
}); | ||
}; | ||
|
||
/** | ||
* Get list of all tools | ||
* User tools | ||
*/ | ||
const { userEditorTools } = useAppState(); | ||
|
||
onMounted(async () => { | ||
tools.value = await marketplaceService.getAllTools(); | ||
availableTools.value = await marketplaceService.getAllTools(); | ||
toolsWithUserBindings.value = getToolsWithUserBindings(availableTools.value, userEditorTools.value); | ||
}); | ||
|
||
/** | ||
* Check if user tools are changed | ||
*/ | ||
watch( | ||
userEditorTools, | ||
async (newValue) => { | ||
toolsWithUserBindings.value = getToolsWithUserBindings(availableTools.value, newValue); | ||
}, | ||
{ | ||
immediate: true, | ||
} | ||
); | ||
|
||
return { | ||
tools: tools, | ||
tools: toolsWithUserBindings, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/presentation/components/marketplace/EditorToolElement.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<template> | ||
<li> | ||
<div class="marketplace__tool"> | ||
{{ tool.title }} | ||
<Button | ||
v-if="canBeUninstalled" | ||
:disabled="tool.isDefault" | ||
:text="t('marketplace.uninstallTool')" | ||
@click="removeTool(tool.id)" | ||
/> | ||
<Button | ||
v-if="canBeInstalled" | ||
:text="t('marketplace.installTool')" | ||
type="transparent" | ||
@click="addTool(tool.id)" | ||
/> | ||
</div> | ||
</li> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { EditorToolWithUserBinding } from '@/domain/entities/EditorTool'; | ||
import { useUserSettings } from '@/application/services/useUserSettings'; | ||
import { useI18n } from 'vue-i18n'; | ||
import { computed } from 'vue'; | ||
import Button from '../button/Button.vue'; | ||
const { addTool, removeTool } = useUserSettings(); | ||
const { t } = useI18n(); | ||
const props = defineProps<{ | ||
tool: EditorToolWithUserBinding; | ||
}>(); | ||
const canBeUninstalled = computed(() => !props.tool.isDefault && props.tool.isInstalled); | ||
const canBeInstalled = computed(() => !props.tool.isDefault && !props.tool.isInstalled); | ||
</script> | ||
|
||
<style scoped lang="postcss"> | ||
.marketplace__tool { | ||
display: flex; | ||
align-items: center; | ||
gap: var(--spacing-very-x); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters