Skip to content

Commit

Permalink
Board: fix card live updates (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
annano authored Apr 14, 2022
1 parent b6156fa commit 140132b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
21 changes: 7 additions & 14 deletions plugins/board-resources/src/components/EditCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@
export let _class: Ref<Class<Card>>
const dispatch = createEventDispatcher()
const client = getClient()
const query = createQuery()
const cardQuery = createQuery()
const stateQuery = createQuery()
let object: Card | undefined
let state: State | undefined
let handleMove: () => void
$: _id &&
_class &&
query.query(_class, { _id }, async (result) => {
$: cardQuery.query(_class, { _id }, async (result) => {
object = result[0]
})
$: object &&
query.query(task.class.State, { _id: object.state }, async (result) => {
$: object?.state && stateQuery.query(task.class.State, { _id: object.state }, async (result) => {
state = result[0]
})
Expand Down Expand Up @@ -103,7 +101,7 @@
<div class="flex-grow mr-4">
<div class="flex-row-streach">
<div class="w-9" />
<CardDetails value={object} />
<CardDetails bind:value={object} />
</div>
<div class="flex-row-streach mt-4 mb-2">
<div class="w-9">
Expand All @@ -127,22 +125,17 @@
</div>
<!-- TODO attachments-->
<!-- TODO checklists -->
<CardActivity value={object} />
<CardActivity bind:value={object} />
</div>

<CardActions value={object} />
<CardActions bind:value={object} />
</div>
</div>
</Scroller>
</Panel>
{/if}

<style lang="scss">
.close-button {
position: absolute;
top: 0.7rem;
right: 0.7rem;
}
.state-name {
text-decoration: underline;
Expand Down
22 changes: 15 additions & 7 deletions plugins/board-resources/src/components/editor/CardActions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
export let value: Card
const client = getClient()
const suggestedActions: CardAction[] = []
const addToCardActions: CardAction[] = []
const automationActions: CardAction[] = []
const actions: CardAction[] = []
let actionGroups: { label: IntlString; actions: CardAction[] }[] = []
getCardActions(client).then(async (result) => {
async function fetch() {
const suggestedActions: CardAction[] = []
const addToCardActions: CardAction[] = []
const automationActions: CardAction[] = []
const actions: CardAction[] = []
const result = await getCardActions(client)
for (const action of result) {
let supported = true
if (action.supported) {
Expand Down Expand Up @@ -74,7 +75,14 @@
actions: actions.sort(cardActionSorter)
}
]
})
}
fetch()
$: value.members && fetch()
$: value.isArchived && fetch()
$: !value.isArchived && fetch()
</script>

{#if value}
Expand Down
8 changes: 4 additions & 4 deletions plugins/board-resources/src/utils/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export function hasDate (card: Card): boolean {

export function addCurrentUser (card: Card, client: Client): void {
const employee = (getCurrentAccount() as EmployeeAccount).employee
card.members = card.members ?? []
const members = card.members ?? []

if (card.members.includes(employee)) {
if (members.includes(employee)) {
return
}

card.members.push(employee)
updateCard(client, card, 'members', card.members)
members.push(employee)
updateCard(client, card, 'members', members)
}

0 comments on commit 140132b

Please sign in to comment.