mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2025-12-13 05:26:47 +00:00
🎨 refactor(proposal): streamline vote handling and improve Nostr login/logout functions in project proposal view.
This commit is contained in:
@@ -23,50 +23,66 @@ state([
|
|||||||
'isAllowed' => false,
|
'isAllowed' => false,
|
||||||
'currentPubkey' => null,
|
'currentPubkey' => null,
|
||||||
'currentPleb' => null,
|
'currentPleb' => null,
|
||||||
'reasons' => fn()
|
'reasons' => fn() => $this->getReasons(),
|
||||||
=> Vote::query()
|
|
||||||
->where('project_proposal_id', $this->projectProposal->id)
|
|
||||||
->where('value', false)
|
|
||||||
->get(),
|
|
||||||
'ownVoteExists' => false,
|
'ownVoteExists' => false,
|
||||||
'boardVotes' => fn()
|
'boardVotes' => fn() => $this->getBoardVotes(),
|
||||||
=> Vote::query()
|
'otherVotes' => fn() => $this->getOtherVotes(),
|
||||||
->where('project_proposal_id', $this->projectProposal->id)
|
|
||||||
->whereHas('einundzwanzigPleb', fn($q) => $q->whereIn('npub', config('einundzwanzig.config.current_board')))
|
|
||||||
->where('value', true)
|
|
||||||
->get(),
|
|
||||||
'otherVotes' => fn()
|
|
||||||
=> Vote::query()
|
|
||||||
->where('project_proposal_id', $this->projectProposal->id)
|
|
||||||
->whereDoesntHave(
|
|
||||||
'einundzwanzigPleb',
|
|
||||||
fn($q) => $q->whereIn('npub', config('einundzwanzig.config.current_board')),
|
|
||||||
)
|
|
||||||
->where('value', true)
|
|
||||||
->get(),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
on([
|
on([
|
||||||
'nostrLoggedIn' => function ($pubkey) {
|
'nostrLoggedIn' => fn($pubkey) => $this->handleNostrLoggedIn($pubkey),
|
||||||
$this->currentPubkey = $pubkey;
|
'nostrLoggedOut' => fn() => $this->handleNostrLoggedOut(),
|
||||||
$this->currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', $pubkey)->first();
|
|
||||||
if ($this->currentPleb->association_status->value < 2) {
|
|
||||||
return $this->js('alert("Du bist hierzu nicht berechtigt.")');
|
|
||||||
}
|
|
||||||
$this->isAllowed = true;
|
|
||||||
$this->ownVoteExists = Vote::query()
|
|
||||||
->where('project_proposal_id', $this->projectProposal->id)
|
|
||||||
->where('einundzwanzig_pleb_id', $this->currentPleb->id)
|
|
||||||
->exists();
|
|
||||||
},
|
|
||||||
'nostrLoggedOut' => function () {
|
|
||||||
$this->isAllowed = false;
|
|
||||||
$this->currentPubkey = null;
|
|
||||||
$this->currentPleb = null;
|
|
||||||
},
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$approve = function () {
|
$approve = fn() => $this->handleApprove();
|
||||||
|
$notApprove = fn() => $this->handleNotApprove();
|
||||||
|
|
||||||
|
$getReasons = function () {
|
||||||
|
return Vote::query()
|
||||||
|
->where('project_proposal_id', $this->projectProposal->id)
|
||||||
|
->where('value', false)
|
||||||
|
->get();
|
||||||
|
};
|
||||||
|
|
||||||
|
$getBoardVotes = function () {
|
||||||
|
return Vote::query()
|
||||||
|
->where('project_proposal_id', $this->projectProposal->id)
|
||||||
|
->whereHas('einundzwanzigPleb', fn($q) => $q->whereIn('npub', config('einundzwanzig.config.current_board')))
|
||||||
|
->where('value', true)
|
||||||
|
->get();
|
||||||
|
};
|
||||||
|
|
||||||
|
$getOtherVotes = function () {
|
||||||
|
return Vote::query()
|
||||||
|
->where('project_proposal_id', $this->projectProposal->id)
|
||||||
|
->whereDoesntHave(
|
||||||
|
'einundzwanzigPleb',
|
||||||
|
fn($q) => $q->whereIn('npub', config('einundzwanzig.config.current_board'))
|
||||||
|
)
|
||||||
|
->where('value', true)
|
||||||
|
->get();
|
||||||
|
};
|
||||||
|
|
||||||
|
$handleNostrLoggedIn = function ($pubkey) {
|
||||||
|
$this->currentPubkey = $pubkey;
|
||||||
|
$this->currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', $pubkey)->first();
|
||||||
|
if ($this->currentPleb->association_status->value < 2) {
|
||||||
|
return $this->js('alert("Du bist hierzu nicht berechtigt.")');
|
||||||
|
}
|
||||||
|
$this->isAllowed = true;
|
||||||
|
$this->ownVoteExists = Vote::query()
|
||||||
|
->where('project_proposal_id', $this->projectProposal->id)
|
||||||
|
->where('einundzwanzig_pleb_id', $this->currentPleb->id)
|
||||||
|
->exists();
|
||||||
|
};
|
||||||
|
|
||||||
|
$handleNostrLoggedOut = function () {
|
||||||
|
$this->isAllowed = false;
|
||||||
|
$this->currentPubkey = null;
|
||||||
|
$this->currentPleb = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
$handleApprove = function () {
|
||||||
Vote::query()->updateOrCreate([
|
Vote::query()->updateOrCreate([
|
||||||
'project_proposal_id' => $this->projectProposal->id,
|
'project_proposal_id' => $this->projectProposal->id,
|
||||||
'einundzwanzig_pleb_id' => $this->currentPleb->id,
|
'einundzwanzig_pleb_id' => $this->currentPleb->id,
|
||||||
@@ -75,17 +91,11 @@ $approve = function () {
|
|||||||
]);
|
]);
|
||||||
$this->form->reset();
|
$this->form->reset();
|
||||||
$this->ownVoteExists = true;
|
$this->ownVoteExists = true;
|
||||||
$this->boardVotes = Vote::query()
|
$this->boardVotes = $this->getBoardVotes();
|
||||||
->where('project_proposal_id', $this->projectProposal->id)
|
$this->otherVotes = $this->getOtherVotes();
|
||||||
->where('value', false)
|
|
||||||
->get();
|
|
||||||
$this->otherVotes = Vote::query()
|
|
||||||
->where('project_proposal_id', $this->projectProposal->id)
|
|
||||||
->where('value', false)
|
|
||||||
->get();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$notApprove = function () {
|
$handleNotApprove = function () {
|
||||||
$this->form->validate();
|
$this->form->validate();
|
||||||
|
|
||||||
Vote::query()->updateOrCreate([
|
Vote::query()->updateOrCreate([
|
||||||
@@ -97,17 +107,13 @@ $notApprove = function () {
|
|||||||
]);
|
]);
|
||||||
$this->form->reset();
|
$this->form->reset();
|
||||||
$this->ownVoteExists = true;
|
$this->ownVoteExists = true;
|
||||||
$this->reasons = Vote::query()
|
$this->reasons = $this->getReasons();
|
||||||
->where('project_proposal_id', $this->projectProposal->id)
|
|
||||||
->where('value', false)
|
|
||||||
->get();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<x-layouts.app title="{{ $projectProposal->name }}"
|
<x-layouts.app title="{{ $projectProposal->name }}"
|
||||||
:seo="new SEOData(image: $projectProposal->getFirstMediaUrl('main'), description: str($projectProposal->description)->limit(100, '...', true))">
|
:seo="new SEOData(image: $projectProposal->getFirstMediaUrl('main'), description: str($projectProposal->description)->limit(100, '...', true))">
|
||||||
>
|
|
||||||
@volt
|
@volt
|
||||||
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full" x-data="nostrDefault(@this)" x-cloak
|
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full" x-data="nostrDefault(@this)" x-cloak
|
||||||
x-show="isAllowed">
|
x-show="isAllowed">
|
||||||
|
|||||||
Reference in New Issue
Block a user