-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
You can now set custom notification settings for users, magazine, entries and posts: `Loud`, `Default` or `Muted`. Move the logic of "fetch an endpoint and get html. Replace html node with selector x with the result of the fetch" to another controller, so it can be used outside of subjects (`Entry`, `EntryComment`, `Post` and `PostComment`)
- Loading branch information
1 parent
c1aba40
commit a2e5b9b
Showing
48 changed files
with
907 additions
and
224 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
import { fetch, ok } from "../utils/http"; | ||
|
||
/* stimulusFetch: 'lazy' */ | ||
export default class extends Controller { | ||
/** | ||
* Calls the address attached to the nearest link node. Replaces the outer html of the nearest `cssclass` parameter | ||
* with the response from the link | ||
*/ | ||
async linkCallback(event) { | ||
event.preventDefault(); | ||
const { cssclass: cssClass, refreshlink: refreshLink, refreshselector: refreshSelector } = event.params | ||
|
||
const a = event.target.closest('a'); | ||
let subjectController = this.application.getControllerForElementAndIdentifier(this.element, 'subject') | ||
|
||
try { | ||
if (subjectController) { | ||
subjectController.loadingValue = true; | ||
} | ||
|
||
let response = await fetch(a.href); | ||
|
||
response = await ok(response); | ||
response = await response.json(); | ||
|
||
event.target.closest(`.${cssClass}`).outerHTML = response.html; | ||
|
||
const refreshElement = this.element.querySelector(refreshSelector) | ||
|
||
if (!!refreshLink && refreshLink !== "" && !!refreshElement) { | ||
let response = await fetch(refreshLink); | ||
|
||
response = await ok(response); | ||
response = await response.json(); | ||
refreshElement.outerHTML = response.html; | ||
} | ||
} catch (e) { | ||
console.error(e) | ||
} finally { | ||
if (subjectController) { | ||
subjectController.loadingValue = false; | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.notification-switch-container .notification-switch { | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.entry-info, | ||
.user-main { | ||
.notification-switch > * { | ||
opacity: .75; | ||
} | ||
} | ||
|
||
footer .notification-switch { | ||
padding: 0.25em 0; | ||
margin-top: 0; | ||
line-height: 1.25em; | ||
} | ||
|
||
.notification-switch { | ||
display: flex; | ||
flex-direction: row; | ||
margin-top: .25em; | ||
line-height: 1.5; | ||
|
||
>* { | ||
cursor: pointer; | ||
padding: .25em .375em; | ||
border: var(--kbin-button-secondary-border); | ||
background: var(--kbin-button-secondary-bg); | ||
color: var(--kbin-button-secondary-text-color); | ||
|
||
&:hover:not(.active) { | ||
background: var(--kbin-button-secondary-hover-bg); | ||
color: var(--kbin-button-secondary-text-hover-color); | ||
} | ||
|
||
&.active { | ||
cursor: unset; | ||
background: var(--kbin-button-primary-bg); | ||
color: var(--kbin-button-primary-text-color); | ||
|
||
&:hover { | ||
background: var(--kbin-button-primary-hover-bg); | ||
color: var(--kbin-button-primary-text-hover-color); | ||
} | ||
} | ||
|
||
&:last-child { | ||
border-radius: 0 1em 1em 0; | ||
padding-right: .75em; | ||
} | ||
|
||
&:first-child { | ||
border-radius: 1em 0 0 1em; | ||
padding-left: .75em; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
change_notification_setting: | ||
controller: App\Controller\NotificationSettingsController::changeSetting | ||
path: /cns/{subject_type}/{subject_id}/{status} | ||
requirements: | ||
subject_type: user|magazine|entry|post | ||
status: Default|Loud|Muted |
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,8 @@ | ||
api_notification_settings_update: | ||
controller: App\Controller\Api\Notification\NotificationSettingApi::update | ||
path: /api/notification/update/{targetType}/{targetId}/{setting} | ||
requirements: | ||
targetType: entry|post|magazine|user | ||
setting: Default|Loud|Muted | ||
methods: [ GET ] | ||
format: json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20241125210454 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Create the notification_settings table for customized notification settings'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE TYPE enumNotificationStatus AS ENUM(\'Default\', \'Muted\', \'Loud\')'); | ||
$this->addSql('CREATE SEQUENCE notification_settings_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); | ||
$this->addSql('CREATE TABLE notification_settings (id INT NOT NULL, user_id INT NOT NULL, entry_id INT DEFAULT NULL, post_id INT DEFAULT NULL, magazine_id INT DEFAULT NULL, target_user_id INT DEFAULT NULL, notification_status enumNotificationStatus DEFAULT \'Default\' NOT NULL, PRIMARY KEY(id))'); | ||
$this->addSql('CREATE INDEX IDX_B0559860A76ED395 ON notification_settings (user_id)'); | ||
$this->addSql('CREATE INDEX IDX_B0559860BA364942 ON notification_settings (entry_id)'); | ||
$this->addSql('CREATE INDEX IDX_B05598604B89032C ON notification_settings (post_id)'); | ||
$this->addSql('CREATE INDEX IDX_B05598603EB84A1D ON notification_settings (magazine_id)'); | ||
$this->addSql('CREATE INDEX IDX_B05598606C066AFE ON notification_settings (target_user_id)'); | ||
$this->addSql('CREATE UNIQUE INDEX notification_settings_user_target ON notification_settings (user_id, entry_id, post_id, magazine_id, target_user_id)'); | ||
$this->addSql('COMMENT ON COLUMN notification_settings.notification_status IS \'(DC2Type:EnumNotificationStatus)\''); | ||
$this->addSql('ALTER TABLE notification_settings ADD CONSTRAINT FK_B0559860A76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE notification_settings ADD CONSTRAINT FK_B0559860BA364942 FOREIGN KEY (entry_id) REFERENCES entry (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE notification_settings ADD CONSTRAINT FK_B05598604B89032C FOREIGN KEY (post_id) REFERENCES post (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE notification_settings ADD CONSTRAINT FK_B05598603EB84A1D FOREIGN KEY (magazine_id) REFERENCES magazine (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE notification_settings ADD CONSTRAINT FK_B05598606C066AFE FOREIGN KEY (target_user_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('DROP SEQUENCE notification_settings_id_seq CASCADE'); | ||
$this->addSql('ALTER TABLE notification_settings DROP CONSTRAINT FK_B0559860A76ED395'); | ||
$this->addSql('ALTER TABLE notification_settings DROP CONSTRAINT FK_B0559860BA364942'); | ||
$this->addSql('ALTER TABLE notification_settings DROP CONSTRAINT FK_B05598604B89032C'); | ||
$this->addSql('ALTER TABLE notification_settings DROP CONSTRAINT FK_B05598603EB84A1D'); | ||
$this->addSql('ALTER TABLE notification_settings DROP CONSTRAINT FK_B05598606C066AFE'); | ||
$this->addSql('DROP TABLE notification_settings'); | ||
$this->addSql('DROP TYPE enumNotificationStatus'); | ||
} | ||
} |
Oops, something went wrong.