|
1 | 1 | import _ from "lodash"; |
| 2 | +import theme from "../components/styles/themes"; |
2 | 3 |
|
3 | 4 | /** |
4 | 5 | * Generates html tabs |
@@ -68,3 +69,83 @@ export const checkThemeRedirect = ( |
68 | 69 | return false; |
69 | 70 | } |
70 | 71 | }; |
| 72 | + |
| 73 | +/** |
| 74 | + * Perform advanced tab actions |
| 75 | + * @param {string} inputVal - current input value |
| 76 | + * @param {(value: React.SetStateAction<string>) => void} setInputVal - setInputVal setState |
| 77 | + * @param {(value: React.SetStateAction<string[]>) => void} setHints - setHints setState |
| 78 | + * @param {hintsCmds} hintsCmds - hints command array |
| 79 | + * @returns {string[] | undefined} hints command or setState action(undefined) |
| 80 | + */ |
| 81 | +export const argTab = ( |
| 82 | + inputVal: string, |
| 83 | + setInputVal: (value: React.SetStateAction<string>) => void, |
| 84 | + setHints: (value: React.SetStateAction<string[]>) => void, |
| 85 | + hintsCmds: string[] |
| 86 | +): string[] | undefined => { |
| 87 | + // 1) if input is 'themes ' |
| 88 | + if (inputVal === "themes ") { |
| 89 | + setInputVal(`themes set`); |
| 90 | + return []; |
| 91 | + } |
| 92 | + |
| 93 | + // 2) if input is 'themes s' |
| 94 | + else if ( |
| 95 | + _.startsWith("themes", _.split(inputVal, " ")[0]) && |
| 96 | + _.split(inputVal, " ")[1] !== "set" && |
| 97 | + _.startsWith("set", _.split(inputVal, " ")[1]) |
| 98 | + ) { |
| 99 | + setInputVal(`themes set`); |
| 100 | + return []; |
| 101 | + } |
| 102 | + |
| 103 | + // 3) if input is 'themes set ' |
| 104 | + else if (inputVal === "themes set ") { |
| 105 | + setHints(_.keys(theme)); |
| 106 | + return []; |
| 107 | + } |
| 108 | + |
| 109 | + // 4) if input starts with 'themes set ' + theme |
| 110 | + else if (_.startsWith(inputVal, "themes set ")) { |
| 111 | + _.keys(theme).forEach((t) => { |
| 112 | + if (_.startsWith(t, _.split(inputVal, " ")[2])) { |
| 113 | + hintsCmds = [...hintsCmds, t]; |
| 114 | + } |
| 115 | + }); |
| 116 | + return hintsCmds; |
| 117 | + } |
| 118 | + |
| 119 | + // 5) if input is 'projects' or 'socials' |
| 120 | + else if (inputVal === "projects " || inputVal === "socials ") { |
| 121 | + setInputVal(`${inputVal}go`); |
| 122 | + return []; |
| 123 | + } |
| 124 | + |
| 125 | + // 6) if input is 'projects g' or 'socials g' |
| 126 | + else if (inputVal === "projects g" || inputVal === "socials g") { |
| 127 | + setInputVal(`${inputVal}o`); |
| 128 | + return []; |
| 129 | + } |
| 130 | + |
| 131 | + // 7) if input is 'socials go ' |
| 132 | + else if (_.startsWith(inputVal, "socials go ")) { |
| 133 | + ["1.Github", "2.Dev.to", "3.Facebook", "4.Instagram"].forEach((t) => { |
| 134 | + hintsCmds = [...hintsCmds, t]; |
| 135 | + }); |
| 136 | + return hintsCmds; |
| 137 | + } |
| 138 | + |
| 139 | + // 8) if input is 'projects go ' |
| 140 | + else if (_.startsWith(inputVal, "projects go ")) { |
| 141 | + [ |
| 142 | + "1.Sat Naing's Blog", |
| 143 | + "2.Haru Fashion", |
| 144 | + "3.Haru API", |
| 145 | + "4.Tip Calculator", |
| 146 | + ].forEach((t) => { |
| 147 | + hintsCmds = [...hintsCmds, t]; |
| 148 | + }); |
| 149 | + return hintsCmds; |
| 150 | + } |
| 151 | +}; |
0 commit comments