diff --git a/.env.example b/.env.example index f06e468..72109fb 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,16 @@ -MM_RUDDER_CALLS_PROD= -MM_RUDDER_DATAPLANE_URL= +# Скопируйте в .env и заполните. Файл .env не попадает в git. +# Адрес сервера Loop и токен системного администратора для make deploy MM_SERVICESETTINGS_SITEURL=http://localhost:8065 MM_ADMIN_TOKEN= + +# true — собирать серверную часть только под ваш компьютер и linux-amd64 (быстрее). +# Такая сборка НЕ запустится на сервере с ARM (linux-arm64). Для релиза закомментируйте. MM_SERVICESETTINGS_ENABLEDEVELOPER=true -#MM_DEBUG=true \ No newline at end of file + +# true — сборка без оптимизаций для отладчика Delve и с исходниками для браузера +#MM_DEBUG=true + +# Ключи RudderStack для серверной телеметрии. Пустые — телеметрия выключена. +MM_RUDDER_CALLS_PROD= +MM_RUDDER_DATAPLANE_URL= diff --git a/.gitea/workflows/build-and-push-plugin.yml b/.gitea/workflows/build-and-push-plugin.yml index 286b7bb..7035244 100644 --- a/.gitea/workflows/build-and-push-plugin.yml +++ b/.gitea/workflows/build-and-push-plugin.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-22.04 uses: wilix-infra/actions/.gitea/workflows/loop-plugin-with-marketplace-template.yml@master with: - go_version: "1.21" + go_version: "1.24" node_version: "22.14.0" vault_secrets_base_path: dev/wilix/loop/data/ci/plugin artifacts_url: https://artifacts.wilix.dev diff --git a/Makefile b/Makefile index ee58a6b..014cd5c 100644 --- a/Makefile +++ b/Makefile @@ -10,11 +10,10 @@ MM_UTILITIES_DIR ?= ../mattermost-utilities DLV_DEBUG_PORT := 2346 DEFAULT_GOOS := $(shell go env GOOS) DEFAULT_GOARCH := $(shell go env GOARCH) -SANS_RESTAPITEST = $(shell go list ./... | grep -v 'git.wilix.dev/loop/loop-plugin-apps/test/restapitest' | sed -e 's/git.wilix.dev\/loop\/loop-plugin-apps\//.\//g') ifneq (,$(wildcard ./.env)) include .env - export $(shell sed 's/=.*//' .env) + export $(shell sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p' .env) endif export GO111MODULE=on @@ -39,8 +38,8 @@ endif # ==================================================================================== # Used for semver bumping PROTECTED_BRANCH := master -APP_NAME := $(shell basename -s .git `git config --get remote.origin.url`) -CURRENT_VERSION := $(shell git describe --abbrev=0 --tags) +APP_NAME := $(shell basename -s .git `git config --get remote.origin.url` 2>/dev/null) +CURRENT_VERSION := $(shell git describe --abbrev=0 --tags 2>/dev/null) VERSION_PARTS := $(subst ., ,$(subst v,,$(subst -rc, ,$(CURRENT_VERSION)))) MAJOR := $(word 1,$(VERSION_PARTS)) MINOR := $(word 2,$(VERSION_PARTS)) @@ -159,7 +158,7 @@ apply: .PHONY: deps deps: - @$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 + @$(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.2 @$(GO) install github.com/nicksnyder/go-i18n/v2/goi18n@v2.2.0 ## Runs eslint and golangci-lint @@ -318,7 +317,7 @@ detach: setup-attach .PHONY: test test: webapp/node_modules ifneq ($(HAS_SERVER),) - $(GO) test -v $(GO_TEST_FLAGS) $(SANS_RESTAPITEST) + $(GO) test -v $(GO_TEST_FLAGS) ./... endif ifneq ($(HAS_WEBAPP),) cd webapp && $(NPM) run test; @@ -328,7 +327,7 @@ endif .PHONY: coverage coverage: webapp/node_modules ifneq ($(HAS_SERVER),) - $(GO) test $(GO_TEST_FLAGS) -coverprofile=server/coverage.txt $(SANS_RESTAPITEST) + $(GO) test $(GO_TEST_FLAGS) -coverprofile=server/coverage.txt ./... $(GO) tool cover -html=server/coverage.txt endif @@ -382,9 +381,6 @@ ifneq ($(HAS_WEBAPP),) rm -fr webapp/node_modules endif rm -fr build/bin/ - rm -fr test/restapitest/mattermost.log - rm -fr test/restapitest/notifications.log - rm -fr test/restapitest/data/ # Help documentation à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html help: diff --git a/README.md b/README.md index 5e2726d..c21e654 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,26 @@ Шаблон включает серверную часть на Go и клиентскую часть на React/TypeScript, настроенный билд через Makefile, пример REST API и базовую структуру Redux store. +Подробное руководство по разработке плагинов: [developers.loop.ru/integrate/plugin-development](https://developers.loop.ru/integrate/plugin-development). + +> **Совместимость.** Возможности плагинов в Loop соответствуют Mattermost 9.11.7. Поэтому серверная часть зафиксирована на `github.com/mattermost/mattermost/server/public v0.1.6` — в этой версии ровно те методы API и хуки, что есть в Loop, и компилятор не даст вызвать недоступный метод. Не обновляйте этот пакет. + ## Требования | Инструмент | Версия | |-----------|--------| -| Go | 1.21+ | +| Go | 1.24+ | | Node.js | 22+ | -| Yarn | 4.x | +| Yarn | 4.x (`corepack enable`) | ## Быстрый старт ### 1. Клонировать шаблон ```bash -git clone my-plugin +git clone https://git.wilix.dev/loop/loop-plugin-starter-template.git my-plugin cd my-plugin +rm -rf .git && git init ``` ### 2. Переименовать плагин @@ -45,7 +50,13 @@ module git.example.com/your-org/my-plugin Затем обновите все импорты в `server/`: ```bash -find server/ -type f -name "*.go" | xargs sed -i 's|git.wilix.dev/loop/loop-plugin-starter-template|git.example.com/your-org/my-plugin|g' +# macOS +grep -rl 'git.wilix.dev/loop/loop-plugin-starter-template' server build | \ + xargs sed -i '' 's|git.wilix.dev/loop/loop-plugin-starter-template|git.example.com/your-org/my-plugin|g' + +# Linux / WSL +grep -rl 'git.wilix.dev/loop/loop-plugin-starter-template' server build | \ + xargs sed -i 's|git.wilix.dev/loop/loop-plugin-starter-template|git.example.com/your-org/my-plugin|g' ``` ### 4. Установить зависимости и собрать @@ -68,6 +79,7 @@ make dist ├── plugin.json # Манифест плагина (ID, имя, версия) ├── Makefile # Команды сборки ├── .env.example # Пример переменных окружения +├── assets/ # Файлы, которые попадут в архив (иконка и т. п.) │ ├── server/ │ ├── main.go # Точка входа серверной части @@ -76,7 +88,7 @@ make dist │ ├── api.go # HTTP маршруты и обработчики │ ├── configuration.go # Конфигурация плагина │ ├── store.go # Работа с key-value хранилищем -│ └── telemetry.go # Телеметрия +│ └── telemetry.go # Телеметрия (включается ключами RudderStack при сборке) │ └── webapp/ └── src/ @@ -124,14 +136,16 @@ make dist ## Makefile: команды сборки ```bash +make # Линтинг, тесты и полная сборка make dist # Полная сборка (server + webapp + tar.gz) make server # Только серверная часть make webapp # Только клиентская часть -make check-style # Линтинг (golangci-lint + eslint) +make check-style # Линтинг (golangci-lint v2 + eslint) make test # Запуск тестов make clean # Очистить артефакты сборки make deploy # Сборка и деплой на сервер (требует .env) -make watch # Сборка + hot reload webapp +make watch # Пересборка webapp при изменениях (загрузка — make deploy-from-watch) +make deps # Установить golangci-lint и goi18n ``` Полный список команд: `make help` @@ -148,8 +162,9 @@ cp .env.example .env |-----------|----------| | `MM_SERVICESETTINGS_SITEURL` | URL вашего Loop-сервера (для деплоя) | | `MM_ADMIN_TOKEN` | Токен администратора (для деплоя через `make deploy`) | -| `MM_SERVICESETTINGS_ENABLEDEVELOPER` | `true` — билд только под текущую ОС (ускоряет разработку) | -| `MM_DEBUG` | `true` — билд без оптимизаций (для отладчика dlv) | +| `MM_SERVICESETTINGS_ENABLEDEVELOPER` | `true` — билд только под текущую ОС и linux-amd64 (ускоряет разработку, но не запустится на ARM-сервере) | +| `MM_DEBUG` | `true` — билд без оптимизаций (для отладчика dlv) и webapp с source maps | +| `MM_RUDDER_CALLS_PROD`, `MM_RUDDER_DATAPLANE_URL` | Ключи RudderStack для серверной телеметрии. Пустые — телеметрия выключена | ## Деплой @@ -157,7 +172,8 @@ cp .env.example .env 1. Соберите плагин: `make dist` 2. Загрузите `dist/-.tar.gz` в Loop: - **Администрирование → Управление плагинами → Загрузить плагин** + **Системная консоль → Плагины → Управление плагинами → Загрузить плагин**. + Загрузка должна быть разрешена на сервере: `PluginSettings.EnableUploads = true` (или `MM_PLUGINSETTINGS_ENABLEUPLOADS=true`) ### Деплой через `make deploy` diff --git a/assets/icon.svg b/assets/icon.svg new file mode 100644 index 0000000..e7145d7 --- /dev/null +++ b/assets/icon.svg @@ -0,0 +1 @@ + diff --git a/build/custom.mk b/build/custom.mk index 47a9b02..07c5203 100644 --- a/build/custom.mk +++ b/build/custom.mk @@ -1,58 +1,18 @@ -# Include custome targets and environment variables here +# Include custom targets and environment variables here default: all -# If there's no MM_RUDDER_PLUGINS_PROD, add DEV data -RUDDER_WRITE_KEY = "" -ifdef MM_RUDDER_PLUGINS_PROD - RUDDER_WRITE_KEY = $(MM_RUDDER_PLUGINS_PROD) -endif - -BUILD_DATE = $(shell date -u) -BUILD_HASH = $(shell git rev-parse HEAD) -BUILD_HASH_SHORT = $(shell git rev-parse --short HEAD) -LDFLAGS += -X "plugin.buildHash=$(BUILD_HASH)" -LDFLAGS+= -X "plugin.isDebug=$(MM_DEBUG)" -LDFLAGS += -X "plugin.rudderWriteKey=$(MM_RUDDER_CALLS_PROD)" -LDFLAGS += -X "plugin.rudderDataplaneURL=$(MM_RUDDER_DATAPLANE_URL)" +GO_MODULE := $(shell $(GO) list -m) +BUILD_HASH = $(shell git rev-parse HEAD 2>/dev/null) +LDFLAGS += -X "$(GO_MODULE)/server/plugin.buildHash=$(BUILD_HASH)" +LDFLAGS += -X "$(GO_MODULE)/server/plugin.rudderWriteKey=$(MM_RUDDER_CALLS_PROD)" +LDFLAGS += -X "$(GO_MODULE)/server/plugin.rudderDataplaneURL=$(MM_RUDDER_DATAPLANE_URL)" GO_BUILD_FLAGS += -ldflags '$(LDFLAGS)' GO_TEST_FLAGS += -ldflags '$(LDFLAGS)' -MM_SERVER_PATH ?= ${PWD}/../mattermost-server -export MM_SERVER_PATH - -## Generates mock golang interfaces for testing -.PHONY: mock -mock: -ifneq ($(HAS_SERVER),) - go install github.com/golang/mock/mockgen@v1.6.0 - mockgen -destination server/mocks/mock_proxy/mock_expand_getter.go git.wilix.dev/loop/loop-plugin-starter-template/server/proxy ExpandGetter - mockgen -destination server/mocks/mock_upstream/mock_upstream.go git.wilix.dev/loop/loop-plugin-starter-template/upstream Upstream - mockgen -destination server/mocks/mock_store/mock_appstore.go git.wilix.dev/loop/loop-plugin-starter-template/server/store AppStore - mockgen -destination server/mocks/mock_store/mock_session.go git.wilix.dev/loop/loop-plugin-starter-template/server/store SessionStore -endif - -## Generates mock golang interfaces for testing -.PHONY: clean_mock -clean_mock: -ifneq ($(HAS_SERVER),) - rm -rf ./server/mocks -endif - -## Run Go REST API system tests -.PHONY: test-rest-api -test-rest-api: dist - @echo Running REST API tests -ifneq ($(RUN),) - PLUGIN_BUNDLE=$(shell pwd)/dist/$(BUNDLE_NAME) $(GO) test -v $(GO_TEST_FLAGS) ./test/restapitest --run $(RUN) -else - PLUGIN_BUNDLE=$(shell pwd)/dist/$(BUNDLE_NAME) $(GO) test -v $(GO_TEST_FLAGS) ./test/restapitest -endif - - ## Extract new translation messages .PHONY: i18n-extract-server i18n-extract-server: - @goi18n extract -format json -outdir assets/i18n/ server/ utils/ apps/ cmd/ upstream/ + @goi18n extract -format json -outdir assets/i18n/ server/ @for x in assets/i18n/active.*.json; do echo $$x | sed 's/active/translate/' | sed 's/^/touch /' | bash; done @goi18n merge -format json -outdir assets/i18n/ assets/i18n/active.*.json @echo "Please update your assets/i18n/translate.*.json files and execute \"make i18n-merge-server\"" @@ -65,18 +25,3 @@ i18n-merge-server: @goi18n merge -format json -outdir assets/i18n/ assets/i18n/active.*.json assets/i18n/translate.*.json @rm -f assets/i18n/translate.*.json @echo "Translations merged, please verify your "git diff" before you submit the changes" - -## Run a simple Mattermost Server -.PHONY: dev_server -dev_server: - cd dev && docker-compose up mattermost db - -## Run the hello-world app -.PHONY: run-example-hello-4000 -run-example-hello-4000: - cd test/hello-world && go run . - -## Run the test app -.PHONY: run-test-app-8081 -run-test-app-8081: - cd test/app && go run . diff --git a/build/manifest/main.go b/build/manifest/main.go index 39d78a9..9ee9cfa 100644 --- a/build/manifest/main.go +++ b/build/manifest/main.go @@ -108,7 +108,7 @@ func findManifest() (*model.Manifest, error) { if err != nil { return nil, errors.Wrapf(err, "failed to open %s", manifestFilePath) } - defer manifestFile.Close() + defer func() { _ = manifestFile.Close() }() // Re-decode the manifest, disallowing unknown fields. When we write the manifest back out, // we don't want to accidentally clobber anything we won't preserve. diff --git a/build/pluginctl/main.go b/build/pluginctl/main.go index 54572fc..3587346 100644 --- a/build/pluginctl/main.go +++ b/build/pluginctl/main.go @@ -125,7 +125,7 @@ func deploy(ctx context.Context, client *model.Client4, pluginID, bundlePath str if err != nil { return fmt.Errorf("failed to open %s: %w", bundlePath, err) } - defer pluginBundle.Close() + defer func() { _ = pluginBundle.Close() }() log.Print("Uploading plugin via API.") _, _, err = client.UploadPluginForced(ctx, pluginBundle) diff --git a/go.mod b/go.mod index 28dfcb0..3584431 100644 --- a/go.mod +++ b/go.mod @@ -6,18 +6,19 @@ toolchain go1.24.10 require ( github.com/gorilla/mux v1.8.1 - github.com/mattermost/mattermost/server/public v0.1.16 + github.com/mattermost/mattermost/server/public v0.1.6 github.com/pkg/errors v0.9.1 github.com/rudderlabs/analytics-go v3.3.3+incompatible ) require ( - github.com/beevik/etree v1.5.1 // indirect + filippo.io/edwards25519 v1.1.0 // indirect github.com/blang/semver/v4 v4.0.0 // indirect github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a // indirect github.com/fatih/color v1.18.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect github.com/go-asn1-ber/asn1-ber v1.5.7 // indirect + github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect @@ -26,20 +27,17 @@ require ( github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-plugin v1.6.3 // indirect github.com/hashicorp/yamux v0.1.2 // indirect - github.com/jonboulle/clockwork v0.5.0 // indirect + github.com/kr/text v0.2.0 // indirect github.com/lib/pq v1.10.9 // indirect github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect - github.com/mattermost/gosaml2 v0.9.0 // indirect github.com/mattermost/ldap v0.0.0-20231116144001-0f480c025956 // indirect github.com/mattermost/logr/v2 v2.0.22 // indirect - github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/oklog/run v1.1.0 // indirect github.com/pborman/uuid v1.2.1 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect - github.com/russellhaering/goxmldsig v1.5.0 // indirect github.com/segmentio/backo-go v1.1.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/tidwall/gjson v1.18.0 // indirect @@ -52,7 +50,6 @@ require ( github.com/wiggin77/srslog v1.0.1 // indirect github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect golang.org/x/crypto v0.38.0 // indirect - golang.org/x/mod v0.24.0 // indirect golang.org/x/net v0.40.0 // indirect golang.org/x/sys v0.33.0 // indirect golang.org/x/text v0.25.0 // indirect @@ -61,5 +58,4 @@ require ( google.golang.org/protobuf v1.36.6 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 7b61589..2f8da9a 100644 --- a/go.sum +++ b/go.sum @@ -6,12 +6,11 @@ dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3/go.mod h1:Yl dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU= dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4= dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU= +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= -github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A= -github.com/beevik/etree v1.5.1 h1:TC3zyxYp+81wAmbsi8SWUpZCurbxa6S8RITYRSkNRwo= -github.com/beevik/etree v1.5.1/go.mod h1:gPNJNaBGVZ9AwsidazFZyygnd+0pAU38N4D+WemwKNs= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= @@ -45,6 +44,8 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= +github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= @@ -88,15 +89,10 @@ github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6 github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= -github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= -github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I= -github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -110,16 +106,12 @@ github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 h1:Khvh6waxG1cHc4Cz5ef9n3XVCxRWpAKUtqg9PJl5+y8= github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404/go.mod h1:RyS7FDNQlzF1PsjbJWHRI35exqaKGSO9qD4iv8QjE34= -github.com/mattermost/gosaml2 v0.9.0 h1:4GxvyRdT2X8KtrhuKjsByDqjA8o6P4q8Kvzo0RbO3CQ= -github.com/mattermost/gosaml2 v0.9.0/go.mod h1:1nMAdE2Psxaz+pj79Oytayi+hC3aZUi3SmJQlIe+sLM= github.com/mattermost/ldap v0.0.0-20231116144001-0f480c025956 h1:Y1Tu/swM31pVwwb2BTCsOdamENjjWCI6qmfHLbk6OZI= github.com/mattermost/ldap v0.0.0-20231116144001-0f480c025956/go.mod h1:SRl30Lb7/QoYyohYeVBuqYvvmXSZJxZgiV3Zf6VbxjI= github.com/mattermost/logr/v2 v2.0.22 h1:npFkXlkAWR9J8payh8ftPcCZvLbHSI125mAM5/r/lP4= github.com/mattermost/logr/v2 v2.0.22/go.mod h1:0sUKpO+XNMZApeumaid7PYaUZPBIydfuWZ0dqixXo+s= -github.com/mattermost/mattermost/server/public v0.1.16 h1:CtTzNnuFCNndUaNfQse5NnvzfBZt+8P+wOU7OMn07zg= -github.com/mattermost/mattermost/server/public v0.1.16/go.mod h1:hvxMXqfao9JDHM3auk8MLl7DD6jAuG0q27Kf9y6z1r0= -github.com/mattermost/xml-roundtrip-validator v0.1.0 h1:RXbVD2UAl7A7nOTR4u7E3ILa4IbtvKBHw64LDsmu9hU= -github.com/mattermost/xml-roundtrip-validator v0.1.0/go.mod h1:qccnGMcpgwcNaBnxqpJpWWUiPNr5H3O8eDgGV9gT5To= +github.com/mattermost/mattermost/server/public v0.1.6 h1:k3upRnYfDY9CtVifQ+hQS6ZP4dGsU6I3oG1DCcBYy0c= +github.com/mattermost/mattermost/server/public v0.1.6/go.mod h1:Dm5uf3z8ckDOKYD1cbnb1Uqm/G9WYIaouSP/HnH+Rbs= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= @@ -144,7 +136,6 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c h1:dAMKvw0MlJT1GshSTtih8C2gDs04w8dReiOGXrGLNoY= github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -155,15 +146,10 @@ github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/rudderlabs/analytics-go v3.3.3+incompatible h1:OG0XlKoXfr539e2t1dXtTB+Gr89uFW+OUNQBVhHIIBY= github.com/rudderlabs/analytics-go v3.3.3+incompatible/go.mod h1:LF8/ty9kUX4PTY3l5c97K3nZZaX5Hwsvt+NBaRL/f30= -github.com/russellhaering/goxmldsig v1.2.0/go.mod h1:gM4MDENBQf7M+V824SGfyIUVFWydB7n0KkEubVJl+Tw= -github.com/russellhaering/goxmldsig v1.5.0 h1:AU2UkkYIUOTyZRbe08XMThaOCelArgvNfYapcmSjBNw= -github.com/russellhaering/goxmldsig v1.5.0/go.mod h1:x98CjQNFJcWfMxeOrMnMKg70lvDP6tE0nTaeUnjXDmk= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/segmentio/backo-go v1.1.0 h1:cJIfHQUdmLsd8t9IXqf5J8SdrOMn9vMa7cIvOavHAhc= github.com/segmentio/backo-go v1.1.0/go.mod h1:ckenwdf+v/qbyhVdNPWHnqh2YdJBED1O9cidYyM5J18= @@ -201,8 +187,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= @@ -249,8 +235,6 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= -golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -323,10 +307,8 @@ google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3i google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= @@ -335,7 +317,6 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= diff --git a/server/plugin/api.go b/server/plugin/api.go index b766ffe..67b3903 100644 --- a/server/plugin/api.go +++ b/server/plugin/api.go @@ -40,7 +40,8 @@ func (p *Plugin) InitApi() { next.ServeHTTP(w, r) return } - http.Error(w, "Not authorized", http.StatusUnauthorized) + w.WriteHeader(http.StatusUnauthorized) + p.sendError(w, "Not authorized") }) }) diff --git a/server/plugin/configuration.go b/server/plugin/configuration.go index 7b87d32..0319f32 100644 --- a/server/plugin/configuration.go +++ b/server/plugin/configuration.go @@ -65,11 +65,13 @@ func (p *Plugin) OnConfigurationChange() error { p.API.LogInfo("OnConfigurationChange") var configuration = new(Configuration) // Load the public Configuration fields from the Mattermost server Configuration. - err := p.API.LoadPluginConfiguration(configuration) - if err == nil { - p.SetConfiguration(configuration) - return nil - } else { + if err := p.API.LoadPluginConfiguration(configuration); err != nil { return errors.Wrap(err, "failed to load plugin Configuration") } + p.SetConfiguration(configuration) + + if err := p.initTelemetry(p.API.GetConfig().LogSettings.EnableDiagnostics); err != nil { + p.API.LogWarn("failed to init telemetry", "error", err.Error()) + } + return nil } diff --git a/server/plugin/plugin.go b/server/plugin/plugin.go index 8c32f0f..b380e87 100644 --- a/server/plugin/plugin.go +++ b/server/plugin/plugin.go @@ -34,9 +34,6 @@ func (p *Plugin) OnActivate() error { p.InitApi() } - configuration := p.GetConfiguration() - p.configuration = configuration - bundlePath, err := p.API.GetBundlePath() if err != nil { return err diff --git a/server/plugin/telemetry.go b/server/plugin/telemetry.go index 42c5ab1..4763c52 100644 --- a/server/plugin/telemetry.go +++ b/server/plugin/telemetry.go @@ -17,6 +17,12 @@ func (p *Plugin) uninitTelemetry() error { } func (p *Plugin) initTelemetry(enableDiagnostics *bool) error { + // Ключи RudderStack задаются при сборке (MM_RUDDER_CALLS_PROD, MM_RUDDER_DATAPLANE_URL). + // Без них телеметрия просто выключена. + if rudderWriteKey == "" || rudderDataplaneURL == "" { + return nil + } + p.mut.Lock() defer p.mut.Unlock() if p.telemetry == nil && enableDiagnostics != nil && *enableDiagnostics { diff --git a/webapp/.eslintrc.json b/webapp/.eslintrc.json deleted file mode 100644 index 3da6789..0000000 --- a/webapp/.eslintrc.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "settings": { - "import/resolver": { - "typescript": { - "project": "./tsconfig.json" - } - }, - "react": { - "version": "17.0.2" - } - }, - "extends": [ - "eslint:recommended", - "plugin:react-hooks/recommended", - "plugin:import/recommended", - "plugin:import/typescript" - ], - "parser": "@typescript-eslint/parser", - "plugins": [ - "react", - "import", - "@typescript-eslint", - "unused-imports" - ], - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module", - "ecmaFeatures": { - "jsx": true, - "impliedStrict": true, - "modules": true, - "experimentalObjectRestSpread": true - } - }, - "env": { - "browser": true, - "node": true, - "jquery": false, - "es6": true - }, - "rules": { - "no-unused-vars": "warn", - "no-unused-expressions": "warn", - "unused-imports/no-unused-imports": "warn", - "import/no-named-as-default": "off" - } -} diff --git a/webapp/eslint.config.mjs b/webapp/eslint.config.mjs new file mode 100644 index 0000000..a9503ab --- /dev/null +++ b/webapp/eslint.config.mjs @@ -0,0 +1,24 @@ +import js from '@eslint/js'; +import tseslint from 'typescript-eslint'; +import reactHooks from 'eslint-plugin-react-hooks'; +import unusedImports from 'eslint-plugin-unused-imports'; + +export default tseslint.config( + { ignores: ['dist/', 'node_modules/', 'src/manifest.ts'] }, + js.configs.recommended, + ...tseslint.configs.recommended, + { + plugins: { + 'react-hooks': reactHooks, + 'unused-imports': unusedImports, + }, + rules: { + ...reactHooks.configs.recommended.rules, + 'unused-imports/no-unused-imports': 'warn', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/ban-ts-comment': 'off', + // В шаблоне пустые типы — заготовки, которые вы заполните + '@typescript-eslint/no-empty-object-type': 'off', + }, + }, +); diff --git a/webapp/package.json b/webapp/package.json index 4f2c778..f713fb4 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -6,10 +6,14 @@ }, "scripts": { "build": "vite build", + "build:watch": "vite build --watch", + "debug": "vite build --minify false --sourcemap inline", + "debug:watch": "vite build --minify false --sourcemap inline --watch", "dev": "vite", - "lint": "eslint --ignore-pattern node_modules --ignore-pattern dist --ext .js --ext .jsx --ext tsx --ext ts . --quiet --cache", - "fix": "eslint --ignore-pattern node_modules --ignore-pattern dist --ext .js --ext .jsx --ext tsx --ext ts . --quiet --fix --cache", - "check-types": "tsc" + "lint": "eslint . --quiet --cache", + "fix": "eslint . --quiet --fix --cache", + "check-types": "tsc", + "test": "echo \"no webapp tests\"" }, "devDependencies": { "@babel/plugin-transform-modules-umd": "^7.27.1", @@ -33,7 +37,7 @@ "eslint": "^9.26.0", "eslint-plugin-import": "2.22.0", "eslint-plugin-react": "7.20.3", - "eslint-plugin-react-hooks": "4.0.6", + "eslint-plugin-react-hooks": "5.2.0", "eslint-plugin-unused-imports": "^4.1.4", "file-loader": "6.0.0", "identity-obj-proxy": "3.0.0", diff --git a/webapp/src/components/RootComponent.tsx b/webapp/src/components/RootComponent.tsx index 6efd3cd..1e017c6 100644 --- a/webapp/src/components/RootComponent.tsx +++ b/webapp/src/components/RootComponent.tsx @@ -1,19 +1,10 @@ -import React from "react"; -import { useDispatch } from 'react-redux'; -import { Provider } from 'react-redux'; -import manifest from '../manifest'; -import usePlugin from '../utils/usePlugin'; +import React from 'react'; +// Корневой компонент всегда присутствует на странице, но ничего не показывает сам по себе. +// Держите здесь то, что должно работать постоянно: модальные окна, фоновую логику. +// Доступ к объекту плагина — хук usePlugin() из ../utils/usePlugin. const RootComponent: React.FC = () => { - const dispatch = useDispatch(); - const plugin = usePlugin(); + return null; +}; - return ( -
- {/* Add your root component content here */} -

Template Plugin Root Component

-
- ) -} - -export default RootComponent +export default RootComponent; diff --git a/webapp/src/constants/assets.ts b/webapp/src/constants/assets.ts deleted file mode 100644 index f206235..0000000 --- a/webapp/src/constants/assets.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { getPluginAssetsPath } from '../utils/utils'; - -export const basePath = getPluginAssetsPath(); - -// Add your assets configuration here -export type AssetsType = { - // Define your asset types -} - -const assets: AssetsType = { - // Add your assets here -} as const - -export default assets diff --git a/webapp/src/constants/index.js b/webapp/src/constants/index.js deleted file mode 100644 index aa33f9a..0000000 --- a/webapp/src/constants/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import Svgs from './svgs.js'; - -export { - Svgs, -}; diff --git a/webapp/src/store/reducers.ts b/webapp/src/store/reducers.ts index 8d9db3e..7977c6c 100644 --- a/webapp/src/store/reducers.ts +++ b/webapp/src/store/reducers.ts @@ -25,7 +25,7 @@ function pluginState(state: PluginStore = EmptyState, { type, data }: ActionType case ACTIONS.EXAMPLE_ACTION: return { ...state, - // Handle action + ...data, } default: return state; diff --git a/webapp/src/types/telemetry.ts b/webapp/src/types/telemetry.ts deleted file mode 100644 index 8d15e18..0000000 --- a/webapp/src/types/telemetry.ts +++ /dev/null @@ -1 +0,0 @@ -// trackEvent: (event: Telemetry.Event, source: Telemetry.Source, props?: Record) => void, \ No newline at end of file diff --git a/webapp/src/utils/useIsDarkTheme.ts b/webapp/src/utils/useIsDarkTheme.ts deleted file mode 100644 index bc0ee85..0000000 --- a/webapp/src/utils/useIsDarkTheme.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { getTheme } from 'loop-plugin-sdk/loop/redux/selectors/entities/preferences'; -import { GlobalState } from 'loop-plugin-sdk/loop/types/store'; -import React, { useEffect } from "react"; -import { useSelector } from 'react-redux'; -import { isDarkTheme } from './colorUtils'; - -const useIsDarkTheme = () => { - const [isDark, setIsDark] = React.useState(false); - const theme = useSelector((state: GlobalState) => getTheme(state)) - - useEffect(() => { - setIsDark(isDarkTheme()); - }, [theme]) - - return isDark -} - -export default useIsDarkTheme \ No newline at end of file diff --git a/webapp/yarn.lock b/webapp/yarn.lock index 01d3864..393456b 100644 --- a/webapp/yarn.lock +++ b/webapp/yarn.lock @@ -3117,12 +3117,12 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-react-hooks@npm:4.0.6": - version: 4.0.6 - resolution: "eslint-plugin-react-hooks@npm:4.0.6" +"eslint-plugin-react-hooks@npm:5.2.0": + version: 5.2.0 + resolution: "eslint-plugin-react-hooks@npm:5.2.0" peerDependencies: - eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 - checksum: 10c0/bc261eb7b2ac177c86f397e65f556c0f1273fcb96ee07155e2611716fa0b6c9e687c99fa91925421c11ebb4b769c8b78624bb9c86ecf68a353297f17212f5697 + eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0 + checksum: 10c0/1c8d50fa5984c6dea32470651807d2922cc3934cf3425e78f84a24c2dfd972e7f019bee84aefb27e0cf2c13fea0ac1d4473267727408feeb1c56333ca1489385 languageName: node linkType: hard @@ -5824,7 +5824,7 @@ __metadata: eslint: "npm:^9.26.0" eslint-plugin-import: "npm:2.22.0" eslint-plugin-react: "npm:7.20.3" - eslint-plugin-react-hooks: "npm:4.0.6" + eslint-plugin-react-hooks: "npm:5.2.0" eslint-plugin-unused-imports: "npm:^4.1.4" file-loader: "npm:6.0.0" identity-obj-proxy: "npm:3.0.0"