Now create multiple CRC cards

This commit is contained in:
Julien Calixte
2022-12-15 18:55:22 +01:00
parent bddbdc1885
commit ec551cd0fc
5 changed files with 111 additions and 22 deletions

2
components.d.ts vendored
View File

@@ -11,7 +11,9 @@ declare module '@vue/runtime-core' {
AppHeader: typeof import('./src/components/app-header.vue')['default'] AppHeader: typeof import('./src/components/app-header.vue')['default']
BlogPosts: typeof import('./src/components/posts/blog-posts.vue')['default'] BlogPosts: typeof import('./src/components/posts/blog-posts.vue')['default']
CrcCard: typeof import('./src/components/architecture/crc-card.vue')['default'] CrcCard: typeof import('./src/components/architecture/crc-card.vue')['default']
CrcProject: typeof import('./src/components/architecture/crc-project.vue')['default']
ForgettingCurve: typeof import('./src/components/smart-notes/forgetting-curve.vue')['default'] ForgettingCurve: typeof import('./src/components/smart-notes/forgetting-curve.vue')['default']
Island: typeof import('./node_modules/.pnpm/iles@0.8.7_sass@1.56.2/node_modules/iles/dist/client/app/components/Island.vue')['default']
JulienCalixte: typeof import('./src/components/core/julien-calixte.vue')['default'] JulienCalixte: typeof import('./src/components/core/julien-calixte.vue')['default']
MyProjects: typeof import('./src/components/presentation/my-projects.vue')['default'] MyProjects: typeof import('./src/components/presentation/my-projects.vue')['default']
OrderTag: typeof import('./src/components/core/order-tag.vue')['default'] OrderTag: typeof import('./src/components/core/order-tag.vue')['default']

View File

@@ -1,65 +1,111 @@
<script setup lang="ts">import { ref } from 'vue'; <script setup lang="ts">
import { CrcCardEntity } from "@/modules/crc/entities/CrcCard"
import { ref } from "vue"
interface Props { interface Props {
name: string, name?: string
responsabilities?: string[] responsabilities?: string[]
collaborators?: string[] collaborators?: string[]
editable?: boolean editable?: boolean
} }
const emits = defineEmits<{
(e: "submit", crc: CrcCardEntity): void
}>()
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
name: "",
responsabilities: () => [], responsabilities: () => [],
collaborators: () => [], collaborators: () => [],
editable: false editable: false,
}) })
const componentName = ref(props.name)
const allReponsabilities = ref(props.responsabilities) const allReponsabilities = ref(props.responsabilities)
const newResponsability = ref('') const newResponsability = ref("")
const addResponsability = () => { const addResponsability = () => {
if (!newResponsability || allReponsabilities.value.find(resp => newResponsability.value === resp)) { if (
!newResponsability ||
allReponsabilities.value.find((resp) => newResponsability.value === resp)
) {
return return
} }
allReponsabilities.value = [...allReponsabilities.value, newResponsability.value] allReponsabilities.value = [
...allReponsabilities.value,
newResponsability.value,
]
newResponsability.value = '' newResponsability.value = ""
} }
const allCollaborators = ref(props.collaborators) const allCollaborators = ref(props.collaborators)
const newCollaborator = ref('') const newCollaborator = ref("")
const addCollaborator = () => { const addCollaborator = () => {
if (!newCollaborator || allCollaborators.value.find(coll => newCollaborator.value === coll)) { if (
!newCollaborator ||
allCollaborators.value.find((coll) => newCollaborator.value === coll)
) {
return return
} }
allCollaborators.value = [...allCollaborators.value, newCollaborator.value] allCollaborators.value = [...allCollaborators.value, newCollaborator.value]
newCollaborator.value = '' newCollaborator.value = ""
}
const clearCard = () => {
componentName.value = ""
allReponsabilities.value = []
allCollaborators.value = []
}
const submitCard = () => {
emits("submit", {
name: componentName.value,
responsabilities: allReponsabilities.value,
collaborators: allCollaborators.value,
})
clearCard()
} }
</script> </script>
<template> <template>
<div class="crc-card"> <div class="crc-card">
<h3 :contenteditable="editable">{{ name }}</h3> <section>
<input
type="text"
class="component-name"
v-if="editable"
v-model="componentName"
/>
<h3 v-else>
{{ componentName }}
</h3>
<button v-if="editable" @click="submitCard">create</button>
</section>
<section> <section>
<div class="responsabilities"> <div class="responsabilities">
<hr> <hr />
<ol> <ol>
<li v-for="responsability in allReponsabilities" :key="responsability"> <li
v-for="responsability in allReponsabilities"
:key="responsability"
>
{{ responsability }} {{ responsability }}
</li> </li>
</ol> </ol>
<form @submit.prevent="addResponsability" v-if="editable"> <form @submit.prevent="addResponsability" v-if="editable">
<input type="text" v-model="newResponsability"> <input type="text" v-model="newResponsability" />
<button type="submit">+</button> <button type="submit">+</button>
</form> </form>
</div> </div>
<div class="collaborators" v-if="collaborators.length || editable"> <div class="collaborators" v-if="collaborators.length || editable">
<hr> <hr />
<ol> <ol>
<li v-for="collaborator in allCollaborators" :key="collaborator"> <li v-for="collaborator in allCollaborators" :key="collaborator">
{{ collaborator }} {{ collaborator }}
@@ -67,7 +113,7 @@ const addCollaborator = () => {
</ol> </ol>
<form @submit.prevent="addCollaborator" v-if="editable"> <form @submit.prevent="addCollaborator" v-if="editable">
<input type="text" v-model.trim="newCollaborator"> <input type="text" v-model.trim="newCollaborator" />
<button type="submit">+</button> <button type="submit">+</button>
</form> </form>
</div> </div>
@@ -112,11 +158,12 @@ const addCollaborator = () => {
visibility: hidden; visibility: hidden;
} }
} }
}
& [contenteditable] { input.component-name {
background-color: rgb(76, 71, 71); background-color: rgb(76, 71, 71);
padding: 0 0.5rem; padding: 0 0.5rem;
border-radius: 0.5rem; border-radius: 0.5rem;
} color: white;
} }
</style> </style>

View File

@@ -0,0 +1,35 @@
<script setup lang="ts">
import { CrcCardEntity } from "@/modules/crc/entities/CrcCard"
import { ref } from "vue"
const crcCards = ref<CrcCardEntity[]>([])
const addCrcCard = (card: CrcCardEntity) => {
crcCards.value = [...crcCards.value, card]
}
</script>
<template>
<div class="crc-project">
<CrcCard editable @submit="addCrcCard" />
<section>
<CrcCard
v-for="card in crcCards"
:key="card.name"
:name="card.name"
:responsabilities="card.responsabilities"
:collaborators="card.collaborators"
/>
</section>
</div>
</template>
<style scoped lang="scss">
.crc-project {
section {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
grid-gap: 1rem;
}
}
</style>

View File

@@ -0,0 +1,5 @@
export interface CrcCardEntity {
name: string
responsabilities: string[]
collaborators: string[]
}

View File

@@ -5,4 +5,4 @@ layout: post
# CRC Card playground # CRC Card playground
<CrcCard editable /> <CrcProject />