Themes: Now you should not reload page twice after changeing theme

Also added a setTempTheme global presenter function
This commit is contained in:
veselcraft 2021-11-06 23:43:48 +03:00
parent f555c781bf
commit 1dff89972e
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
4 changed files with 25 additions and 8 deletions

View file

@ -6,6 +6,7 @@ use Chandler\Session\Session;
use Chandler\Security\Authenticator; use Chandler\Security\Authenticator;
use Latte\Engine as TemplatingEngine; use Latte\Engine as TemplatingEngine;
use openvk\Web\Models\Entities\IP; use openvk\Web\Models\Entities\IP;
use openvk\Web\Themes\Themepacks;
use openvk\Web\Models\Repositories\{IPs, Users, APITokens}; use openvk\Web\Models\Repositories\{IPs, Users, APITokens};
abstract class OpenVKPresenter extends SimplePresenter abstract class OpenVKPresenter extends SimplePresenter
@ -32,6 +33,11 @@ abstract class OpenVKPresenter extends SimplePresenter
"code" => $code, "code" => $code,
])); ]));
} }
protected function setTempTheme(string $theme): void
{
Session::i()->set("_tempTheme", $theme);
}
protected function flashFail(string $type, string $title, ?string $message = NULL, ?int $code = NULL): void protected function flashFail(string $type, string $title, ?string $message = NULL, ?int $code = NULL): void
{ {
@ -216,12 +222,21 @@ abstract class OpenVKPresenter extends SimplePresenter
$theme = $this->user->identity->getTheme(); $theme = $this->user->identity->getTheme();
if(!is_null($theme) && $theme->overridesTemplates()) { if(!is_null($theme) && $theme->overridesTemplates()) {
$this->template->_templatePath = $theme->getBaseDir() . "/tpl"; $this->template->_templatePath = $theme->getBaseDir() . "/tpl";
} }
} }
if(!is_null(Session::i()->get("_error"))) { if(!is_null(Session::i()->get("_error"))) {
$this->template->flashMessage = json_decode(Session::i()->get("_error")); $this->template->flashMessage = json_decode(Session::i()->get("_error"));
Session::i()->set("_error", NULL); Session::i()->set("_error", NULL);
} }
if(Session::i()->get("_tempTheme"))
$this->template->theme = Themepacks::i()[Session::i()->get("_tempTheme", "ovk")];
else if($this->requestParam("themePreview"))
$this->template->theme = Themepacks::i()[$this->requestParam("themePreview")];
else if($this->user->identity->getTheme())
$this->template->theme = $this->user->identity->getTheme();
// Знаю, каша ебаная, целестора рефактор всё равно сделает :)))
} }
} }

View file

@ -273,7 +273,10 @@ final class UserPresenter extends OpenVKPresenter
$this->flashFail("succ", tr("voucher_good"), tr("voucher_redeemed")); $this->flashFail("succ", tr("voucher_good"), tr("voucher_redeemed"));
} else if($_GET['act'] === "interface") { } else if($_GET['act'] === "interface") {
if (isset(Themepacks::i()[$this->postParam("style")]) || $this->postParam("style") === Themepacks::DEFAULT_THEME_ID) if (isset(Themepacks::i()[$this->postParam("style")]) || $this->postParam("style") === Themepacks::DEFAULT_THEME_ID)
$user->setStyle($this->postParam("style")); {
$user->setStyle($this->postParam("style"));
$this->setTempTheme($this->postParam("style"));
}
if ($this->postParam("style_avatar") <= 2 && $this->postParam("style_avatar") >= 0) if ($this->postParam("style_avatar") <= 2 && $this->postParam("style_avatar") >= 0)
$user->setStyle_Avatar((int)$this->postParam("style_avatar")); $user->setStyle_Avatar((int)$this->postParam("style_avatar"));
@ -308,10 +311,10 @@ final class UserPresenter extends OpenVKPresenter
throw $ex; throw $ex;
} }
$this->flash( $this->flash(
"succ", "succ",
"Изменения сохранены", "Изменения сохранены",
"Новые данные появятся на вашей странице.<br/>Если вы изменили стиль, перезагрузите страницу." "Новые данные появятся на вашей странице."
); );
} }
$this->template->mode = in_array($this->queryParam("act"), [ $this->template->mode = in_array($this->queryParam("act"), [

View file

@ -16,9 +16,8 @@
{css "css/nsfw-posts.css"} {css "css/nsfw-posts.css"}
{/if} {/if}
{if !is_null($thisUser->getTheme())} {if $theme !== null}
{var theme = $thisUser->getTheme()} {if $theme->inheritDefault()}
{if $theme->inheritDefault()}
{css "css/style.css"} {css "css/style.css"}
{css "css/dialog.css"} {css "css/dialog.css"}
{css "css/notifications.css"} {css "css/notifications.css"}

@ -1 +1 @@
Subproject commit ef1b7ab803b56a02df670d91d7c22b3e509e6779 Subproject commit ce4ede6f8c6cb42f2421969fab23da933c81b52b