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 Latte\Engine as TemplatingEngine;
use openvk\Web\Models\Entities\IP;
use openvk\Web\Themes\Themepacks;
use openvk\Web\Models\Repositories\{IPs, Users, APITokens};
abstract class OpenVKPresenter extends SimplePresenter
@ -33,6 +34,11 @@ abstract class OpenVKPresenter extends SimplePresenter
]));
}
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
{
$this->flash($type, $title, $message, $code);
@ -223,5 +229,14 @@ abstract class OpenVKPresenter extends SimplePresenter
$this->template->flashMessage = json_decode(Session::i()->get("_error"));
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"));
} else if($_GET['act'] === "interface") {
if (isset(Themepacks::i()[$this->postParam("style")]) || $this->postParam("style") === Themepacks::DEFAULT_THEME_ID)
{
$user->setStyle($this->postParam("style"));
$this->setTempTheme($this->postParam("style"));
}
if ($this->postParam("style_avatar") <= 2 && $this->postParam("style_avatar") >= 0)
$user->setStyle_Avatar((int)$this->postParam("style_avatar"));
@ -311,7 +314,7 @@ final class UserPresenter extends OpenVKPresenter
$this->flash(
"succ",
"Изменения сохранены",
"Новые данные появятся на вашей странице.<br/>Если вы изменили стиль, перезагрузите страницу."
"Новые данные появятся на вашей странице."
);
}
$this->template->mode = in_array($this->queryParam("act"), [

View file

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

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