Skip to content

Commit

Permalink
feat: project form getting form
Browse files Browse the repository at this point in the history
  • Loading branch information
davay42 committed Apr 29, 2023
1 parent e5728d6 commit b43d14e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/project/ProjectForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const props = defineProps({
title: { type: String, default: 'Project0' }
})
const emit = defineEmits(['added'])
const { newProject, addProject } = useNewProject()
watchEffect(() => {
Expand All @@ -23,5 +25,6 @@ watchEffect(() => {
h3 Title:
input(type="text" v-model="newProject.title")

button.button(@click="addProject(()=>$emit('added'))") ADD PROJECT
pre.text-xs {{ newProject }}
</template>
4 changes: 1 addition & 3 deletions src/project/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const props = defineProps({
const { candidates, search } = useProjects(props.pub)
defineEmits(['open'])
</script>
<template lang="pug">
Expand All @@ -32,5 +30,5 @@ defineEmits(['open'])
@click="$emit('open', proj.item.path)"
)
.p-2.flex.flex-col.gap-2
project-form(:title="search" v-if="search")
project-form(:title="search" v-if="search" @added="search=''")
</template>
15 changes: 7 additions & 8 deletions src/project/useProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@ export function useNewProject(title?: string) {
author: computed(() => user.pub),
})

async function addProject() {
async function addProject(cb?: Function) {
const gun = useGun()
const { user } = useUser()

const id = genUUID(6)
newProject.author = user.pub

const link = gun.user().get('projects').get(id).put(newProject, () => {
const link = gun.user().get('projects').get(newProject.id).put(newProject, () => {
if (!newProject.public) return

gun
.user(currentRoom.pub)
.get('projects')
.get(id + '@' + user.pub)
.get(newProject.id + '@' + user.pub)
.put(
link,
undefined,
() => {
console.log('added project')
if (cb) { cb?.() }
},
{
opt:
{ cert: currentRoom.features?.projects }
Expand Down
3 changes: 1 addition & 2 deletions src/room/useRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import config from "../../gun.config.json";
import { reactive, computed, ref, watchEffect } from "vue";
import { ISEAPair } from "gun";
import { useStorage } from '@vueuse/core'
import { CurrentRoom } from "./useRoom.d";

const rootRoom = config.room

import { CurrentRoom } from "./useRoom.d";

export const currentRoom: CurrentRoom = reactive({
pub: useStorage('current-room', rootRoom.pub),
isRoot: computed(() => currentRoom.pub == rootRoom.pub),
Expand Down

0 comments on commit b43d14e

Please sign in to comment.