Skip to content

Commit

Permalink
Update: Write websites
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Nov 9, 2023
1 parent 20c73f5 commit 436870d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/class/StorageTool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import Browser from "webextension-polyfill";

import { WebSiteClasses, WebsiteIds } from "@/data/websites";
import { WebsiteIds, Websites } from "@/data/websites";

import IsTrue from "../../utils/isTrue";

Expand All @@ -30,7 +30,7 @@ export default class StorageTool {

static getStorage(id: StorageIds) {
if (id == "other") return new StorageTool(id);
return WebSiteClasses.get(id)?.storage;
return Websites.get(id)?.class.storage;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion src/components/SwitchItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export function SwitchItem({
color?: ComponentColor;
readonly?: boolean;
}) {
return <ToggleWithStorage dataId={config.id} dataKey={category} color={color} readonly={readonly} />;
return <ToggleWithStorage dataId={config.class.id} dataKey={category} color={color} readonly={readonly} />;
}
103 changes: 56 additions & 47 deletions src/data/websites.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { UnivWebsite } from "@/class";
import { Kyomu, Media, Moodle, MyLibrary, SSO, UnivWebsite } from "@/class";

export interface WebsiteConfig {
name: string;
id: WebsiteIds;
class: UnivWebsite<unknown>;
configable: {
rainbow: boolean;
dark: boolean;
Expand All @@ -11,53 +11,62 @@ export interface WebsiteConfig {

export type WebsiteIds = "kyomu" | "media" | "moodle" | "mylibrary" | "sso";

export const WebSiteClasses: Map<WebsiteIds, UnivWebsite<unknown>> = new Map([
["kyomu", new UnivWebsite<unknown>("kyomu")],
["media", new UnivWebsite<unknown>("media")],
["moodle", new UnivWebsite<unknown>("moodle")],
["mylibrary", new UnivWebsite<unknown>("mylibrary")],
["sso", new UnivWebsite<unknown>("sso")],
]);

export const Websites: WebsiteConfig[] = [
{
name: "Moodle",
id: "moodle",
configable: {
rainbow: true,
dark: true,
export const Websites: Map<WebsiteIds, WebsiteConfig> = new Map([
[
"moodle",
{
name: "Moodle",
class: Moodle,
configable: {
rainbow: true,
dark: true,
},
},
},
{
name: "教務システム",
id: "kyomu",
configable: {
rainbow: true,
dark: true,
],
[
"media",
{
name: "メディアセンター",
class: Media,
configable: {
rainbow: true,
dark: false,
},
},
},
{
name: "メディアセンター",
id: "media",
configable: {
rainbow: true,
dark: false,
],
[
"kyomu",
{
name: "教務システム",
class: Kyomu,
configable: {
rainbow: true,
dark: true,
},
},
},
{
name: "MyLibrary",
id: "mylibrary",
configable: {
rainbow: true,
dark: false,
],
[
"mylibrary",
{
name: "MyLibrary",
class: MyLibrary,
configable: {
rainbow: true,
dark: false,
},
},
},
{
name: "SSO",
id: "sso",
configable: {
rainbow: true,
dark: false,
],
[
"sso",
{
name: "SSO",
class: SSO,
configable: {
rainbow: true,
dark: false,
},
},
},
];
],
]);

export const WebsitesList = Array.from(Websites.values());
4 changes: 2 additions & 2 deletions src/options/pages/Top.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default function Top() {
<>
<ConfigSection name="Websites" desc="それぞれのウェブサイトで有効化する機能を設定できます">
<div className="flex flex-wrap items-center">
{Websites.map((site) => {
{Array.from(Websites.values()).map((site) => {
return (
<div className="chiid:p-1 mx-4 my-2 flex w-60 justify-center child:grow" key={site.id}>
<div className="chiid:p-1 mx-4 my-2 flex w-60 justify-center child:grow" key={site.class.id}>
<p className="my-0 flex w-1/2 items-center justify-center rounded-l-lg bg-base-300 text-center">
{site.name}
</p>
Expand Down
6 changes: 3 additions & 3 deletions src/popup/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FaGamepad, FaMoon } from "react-icons/fa";
import browser from "webextension-polyfill";

import { SwitchItem } from "../../components/SwitchItem";
import { WebsiteConfig, Websites } from "../../data/websites";
import { WebsiteConfig, WebsitesList } from "../../data/websites";

type MainProps = DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;

Expand All @@ -28,9 +28,9 @@ export default function Main(props: MainProps) {

const switches = (
<div className="flex flex-wrap">
{Websites.map((config) => {
{WebsitesList.map((config) => {
return (
<div className="m-2 flex w-36 min-w-fit flex-col rounded-lg bg-base-300 p-2" key={config.id}>
<div className="m-2 flex w-36 min-w-fit flex-col rounded-lg bg-base-300 p-2" key={config.class.id}>
<p className="flex items-center justify-center">{config.name}</p>
<Switches config={config} />
</div>
Expand Down

0 comments on commit 436870d

Please sign in to comment.